diff options
author | uzhas <uzhas@ydb.tech> | 2022-09-17 10:20:48 +0300 |
---|---|---|
committer | uzhas <uzhas@ydb.tech> | 2022-09-17 10:20:48 +0300 |
commit | f7ac351009be051be95861cb7735fd76f368089c (patch) | |
tree | 5ca2692fda77e97fd41fccc50e7d4fc647fad057 | |
parent | 28dcdc0d65fba31bc1e2215741a4af228992938e (diff) | |
download | ydb-f7ac351009be051be95861cb7735fd76f368089c.tar.gz |
add tests to normalize path
6 files changed, 147 insertions, 1 deletions
diff --git a/ydb/library/yql/providers/s3/provider/CMakeLists.txt b/ydb/library/yql/providers/s3/provider/CMakeLists.txt index f3605fe34b..3d12e8f632 100644 --- a/ydb/library/yql/providers/s3/provider/CMakeLists.txt +++ b/ydb/library/yql/providers/s3/provider/CMakeLists.txt @@ -6,6 +6,7 @@ # original buildsystem will not be accepted. +add_subdirectory(ut) add_library(providers-s3-provider) target_compile_options(providers-s3-provider PRIVATE @@ -16,6 +17,7 @@ target_link_libraries(providers-s3-provider PUBLIC yutil contrib-libs-re2 library-cpp-json + cpp-protobuf-util library-cpp-random_provider library-cpp-retry library-cpp-time_provider diff --git a/ydb/library/yql/providers/s3/provider/ut/CMakeLists.darwin.txt b/ydb/library/yql/providers/s3/provider/ut/CMakeLists.darwin.txt new file mode 100644 index 0000000000..b9f4092db4 --- /dev/null +++ b/ydb/library/yql/providers/s3/provider/ut/CMakeLists.darwin.txt @@ -0,0 +1,46 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(ydb-library-yql-providers-s3-provider-ut) +target_compile_options(ydb-library-yql-providers-s3-provider-ut PRIVATE + -DUSE_CURRENT_UDF_ABI_VERSION +) +target_include_directories(ydb-library-yql-providers-s3-provider-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/s3/provider +) +target_link_libraries(ydb-library-yql-providers-s3-provider-ut PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-cpuid_check + cpp-testing-unittest_main + providers-s3-provider +) +target_link_options(ydb-library-yql-providers-s3-provider-ut PRIVATE + -Wl,-no_deduplicate + -Wl,-sdk_version,10.15 + -fPIC + -fPIC + -framework + CoreFoundation +) +target_sources(ydb-library-yql-providers-s3-provider-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/s3/provider/yql_s3_path_ut.cpp +) +add_test( + NAME + ydb-library-yql-providers-s3-provider-ut + COMMAND + ydb-library-yql-providers-s3-provider-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-library-yql-providers-s3-provider-ut) diff --git a/ydb/library/yql/providers/s3/provider/ut/CMakeLists.linux.txt b/ydb/library/yql/providers/s3/provider/ut/CMakeLists.linux.txt new file mode 100644 index 0000000000..a652e4bea6 --- /dev/null +++ b/ydb/library/yql/providers/s3/provider/ut/CMakeLists.linux.txt @@ -0,0 +1,50 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(ydb-library-yql-providers-s3-provider-ut) +target_compile_options(ydb-library-yql-providers-s3-provider-ut PRIVATE + -DUSE_CURRENT_UDF_ABI_VERSION +) +target_include_directories(ydb-library-yql-providers-s3-provider-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/s3/provider +) +target_link_libraries(ydb-library-yql-providers-s3-provider-ut PUBLIC + contrib-libs-cxxsupp + yutil + cpp-malloc-tcmalloc + libs-tcmalloc-no_percpu_cache + library-cpp-cpuid_check + cpp-testing-unittest_main + providers-s3-provider +) +target_link_options(ydb-library-yql-providers-s3-provider-ut PRIVATE + -ldl + -lrt + -Wl,--no-as-needed + -fPIC + -fPIC + -lpthread + -lrt + -ldl +) +target_sources(ydb-library-yql-providers-s3-provider-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/s3/provider/yql_s3_path_ut.cpp +) +add_test( + NAME + ydb-library-yql-providers-s3-provider-ut + COMMAND + ydb-library-yql-providers-s3-provider-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-library-yql-providers-s3-provider-ut) diff --git a/ydb/library/yql/providers/s3/provider/ut/CMakeLists.txt b/ydb/library/yql/providers/s3/provider/ut/CMakeLists.txt new file mode 100644 index 0000000000..dbfe6fa2c4 --- /dev/null +++ b/ydb/library/yql/providers/s3/provider/ut/CMakeLists.txt @@ -0,0 +1,13 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (APPLE) + include(CMakeLists.darwin.txt) +elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE) + include(CMakeLists.linux.txt) +endif() diff --git a/ydb/library/yql/providers/s3/provider/yql_s3_path.cpp b/ydb/library/yql/providers/s3/provider/yql_s3_path.cpp index 2fd6b89f3f..600c50a3c7 100644 --- a/ydb/library/yql/providers/s3/provider/yql_s3_path.cpp +++ b/ydb/library/yql/providers/s3/provider/yql_s3_path.cpp @@ -7,7 +7,9 @@ namespace NYql::NS3 { TString NormalizePath(const TString& path, char slash) { - YQL_ENSURE(!path.empty()); + if (path.empty()) { + throw yexception() << "Path should not be empty"; + } TString result; bool start = true; for (char c : path) { diff --git a/ydb/library/yql/providers/s3/provider/yql_s3_path_ut.cpp b/ydb/library/yql/providers/s3/provider/yql_s3_path_ut.cpp new file mode 100644 index 0000000000..f2ecaa8487 --- /dev/null +++ b/ydb/library/yql/providers/s3/provider/yql_s3_path_ut.cpp @@ -0,0 +1,33 @@ +#include <ydb/library/yql/providers/s3/provider/yql_s3_path.h> + +#include <library/cpp/testing/unittest/registar.h> + +namespace NYql::NS3 { + +Y_UNIT_TEST_SUITE(TPathTests) { + Y_UNIT_TEST(NormalizeEmpty) { + UNIT_ASSERT_EXCEPTION_CONTAINS(NormalizePath(""), std::exception, "Path should not be empty"); + } + + Y_UNIT_TEST(NormalizeSlashes) { + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("/"), "/"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("//"), "/"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("///"), "/"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("////////////"), "/"); + } + + Y_UNIT_TEST(NormalizeNoSlashes) { + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("a"), "a"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("abc"), "abc"); + } + + Y_UNIT_TEST(NormalizeWithSlashes) { + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("a/b/c"), "a/b/c"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("a/b/c/"), "a/b/c/"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("/a/b/c"), "a/b/c"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("/a/b/c/"), "a/b/c/"); + UNIT_ASSERT_VALUES_EQUAL(NormalizePath("///a/b/c///"), "a/b/c/"); + } +} + +} |