diff --git a/src/motherduck_destination_server.cpp b/src/motherduck_destination_server.cpp index 32fb7bd..f2eaf80 100644 --- a/src/motherduck_destination_server.cpp +++ b/src/motherduck_destination_server.cpp @@ -29,7 +29,7 @@ int find_optional_property( const std::string &property_name, int default_value, const std::function &parse) { auto token_it = config.find(property_name); - return token_it == config.end() ? default_value : parse(token_it->second); + return token_it == config.end() || token_it->second.empty() ? default_value : parse(token_it->second); } template std::string get_schema_name(const T *request) { diff --git a/test/integration/test_server.cpp b/test/integration/test_server.cpp index e762e71..a45dbc3 100644 --- a/test/integration/test_server.cpp +++ b/test/integration/test_server.cpp @@ -237,9 +237,7 @@ TEST_CASE("Test endpoint fails when token is bad", auto status = service.Test(nullptr, &request, &response); REQUIRE_NO_FAIL(status); CHECK_THAT(status.error_message(), - Catch::Matchers::ContainsSubstring("UNAUTHENTICATED")); - CHECK_THAT(status.error_message(), - Catch::Matchers::ContainsSubstring("UNAUTHENTICATED")); + Catch::Matchers::ContainsSubstring("not authenticated")); } TEST_CASE( @@ -935,6 +933,38 @@ TEST_CASE("Table with large json row", "[integration][write-batch]") { REQUIRE(res->GetValue(0, 0) == 0); } + { + // Empty string for the block size falls back to default value, + // but sync fails due to default block size being too small. + ::fivetran_sdk::WriteBatchRequest request; + (*request.mutable_configuration())["motherduck_token"] = token; + (*request.mutable_configuration())["motherduck_database"] = + TEST_DATABASE_NAME; + (*request.mutable_configuration())[MD_PROP_CSV_BLOCK_SIZE] = ""; + + make_book_table(request, table_name); + + const std::string filename = "huge_books.csv"; + const std::string filepath = TEST_RESOURCES_DIR + filename; + + request.add_replace_files(filepath); + + ::fivetran_sdk::WriteBatchResponse response; + auto status = service.WriteBatch(nullptr, &request, &response); + REQUIRE_FALSE(status.ok()); + CHECK_THAT(status.error_message(), + Catch::Matchers::ContainsSubstring( + "straddling object straddles two block boundaries")); + } + + { + // check no rows were inserted + auto res = con->Query("SELECT count(*) FROM " + table_name); + REQUIRE_NO_FAIL(res); + REQUIRE(res->RowCount() == 1); + REQUIRE(res->GetValue(0, 0) == 0); + } + { // succeed when block_size is increased ::fivetran_sdk::WriteBatchRequest request;