diff options
author | uzhas <uzhas@ydb.tech> | 2022-10-05 17:41:39 +0300 |
---|---|---|
committer | uzhas <uzhas@ydb.tech> | 2022-10-05 17:41:39 +0300 |
commit | 4a2681b051fb9aebe7e64eb44ac0d00b62f7f237 (patch) | |
tree | 62fba07d770536a60eaf9d15a03d03f71280d624 | |
parent | 8784416337d4c07db27cc749fb846210f29c622f (diff) | |
download | ydb-4a2681b051fb9aebe7e64eb44ac0d00b62f7f237.tar.gz |
add ut for http_router
-rw-r--r-- | ydb/core/public_http/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ydb/core/public_http/http_router_ut.cpp | 54 | ||||
-rw-r--r-- | ydb/core/public_http/ut/CMakeLists.darwin.txt | 50 | ||||
-rw-r--r-- | ydb/core/public_http/ut/CMakeLists.linux.txt | 54 | ||||
-rw-r--r-- | ydb/core/public_http/ut/CMakeLists.txt | 13 |
5 files changed, 172 insertions, 0 deletions
diff --git a/ydb/core/public_http/CMakeLists.txt b/ydb/core/public_http/CMakeLists.txt index 5470a8ce84b..082237a8dd0 100644 --- a/ydb/core/public_http/CMakeLists.txt +++ b/ydb/core/public_http/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(protos) +add_subdirectory(ut) add_library(ydb-core-public_http) target_compile_options(ydb-core-public_http PRIVATE diff --git a/ydb/core/public_http/http_router_ut.cpp b/ydb/core/public_http/http_router_ut.cpp new file mode 100644 index 00000000000..ce4704ecb1d --- /dev/null +++ b/ydb/core/public_http/http_router_ut.cpp @@ -0,0 +1,54 @@ +#include <library/cpp/testing/unittest/registar.h> +#include "http_router.h" + +using namespace NKikimr::NPublicHttp; +using namespace NActors; + +namespace { +THttpHandler AsTestHandler(IActor* a) { + return [a](const THttpRequestContext&) { + return a; + }; +} +} + +Y_UNIT_TEST_SUITE(HttpRouter) { + Y_UNIT_TEST(Basic) { + IActor* const a1 = reinterpret_cast<IActor*>(1); + IActor* const a2 = reinterpret_cast<IActor*>(2); + THolder<TActorSystemSetup> setup(new TActorSystemSetup()); + TActorSystem actorSystem(setup); + THttpRequestContext ctx(&actorSystem, new NHttp::THttpIncomingRequest(), {}, {}, {}); + + THttpRequestRouter router; + router.RegisterHandler(HTTP_METHOD_GET, "/apix/v1/fq/query", AsTestHandler(a1)); + router.RegisterHandler(HTTP_METHOD_GET, "/apix/v1/fq/query/{query_id}", AsTestHandler(a2)); + UNIT_ASSERT_VALUES_EQUAL(router.GetSize(), 2); + + std::optional<THandlerWithParams> resolve1 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq"sv); + UNIT_ASSERT(!resolve1); + + std::optional<THandlerWithParams> resolve2 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq/query/1234/status"sv); + UNIT_ASSERT(!resolve2); + + std::optional<THandlerWithParams> resolve3 = router.ResolveHandler(HTTP_METHOD_POST, "/apix/v1/fq/query"sv); + UNIT_ASSERT(!resolve3); + + std::optional<THandlerWithParams> resolve4 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq/query"sv); + UNIT_ASSERT(resolve4); + UNIT_ASSERT_VALUES_EQUAL(resolve4->PathPattern, "/apix/v1/fq/query"); + UNIT_ASSERT(resolve4->Handler); + UNIT_ASSERT_EQUAL(resolve4->Handler(ctx), a1); + UNIT_ASSERT_VALUES_EQUAL(resolve4->PathParams.size(), 0u); + + std::optional<THandlerWithParams> resolve5 = router.ResolveHandler(HTTP_METHOD_GET, "/apix/v1/fq/query/1234"sv); + UNIT_ASSERT(resolve5); + UNIT_ASSERT_VALUES_EQUAL(resolve5->PathPattern, "/apix/v1/fq/query/{query_id}"); + UNIT_ASSERT(resolve5->Handler); + UNIT_ASSERT_EQUAL(resolve5->Handler(ctx), a2); + UNIT_ASSERT_VALUES_EQUAL(resolve5->PathParams.size(), 1u); + + UNIT_ASSERT_VALUES_EQUAL(resolve5->PathParams.begin()->first, "query_id"); + UNIT_ASSERT_VALUES_EQUAL(resolve5->PathParams.begin()->second, "1234"); + } +} diff --git a/ydb/core/public_http/ut/CMakeLists.darwin.txt b/ydb/core/public_http/ut/CMakeLists.darwin.txt new file mode 100644 index 00000000000..2bc578a05f5 --- /dev/null +++ b/ydb/core/public_http/ut/CMakeLists.darwin.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-core-public_http-ut) +target_compile_options(ydb-core-public_http-ut PRIVATE + -DUSE_CURRENT_UDF_ABI_VERSION +) +target_include_directories(ydb-core-public_http-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/public_http +) +target_link_libraries(ydb-core-public_http-ut PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-cpuid_check + cpp-testing-unittest_main + ydb-core-public_http + udf-service-exception_policy + yql-sql-pg_dummy + ydb-services-kesus + ydb-services-persqueue_cluster_discovery +) +target_link_options(ydb-core-public_http-ut PRIVATE + -Wl,-no_deduplicate + -Wl,-sdk_version,10.15 + -fPIC + -fPIC + -framework + CoreFoundation +) +target_sources(ydb-core-public_http-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/public_http/http_router_ut.cpp +) +add_test( + NAME + ydb-core-public_http-ut + COMMAND + ydb-core-public_http-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-core-public_http-ut) diff --git a/ydb/core/public_http/ut/CMakeLists.linux.txt b/ydb/core/public_http/ut/CMakeLists.linux.txt new file mode 100644 index 00000000000..0912fc606cb --- /dev/null +++ b/ydb/core/public_http/ut/CMakeLists.linux.txt @@ -0,0 +1,54 @@ + +# 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-core-public_http-ut) +target_compile_options(ydb-core-public_http-ut PRIVATE + -DUSE_CURRENT_UDF_ABI_VERSION +) +target_include_directories(ydb-core-public_http-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/public_http +) +target_link_libraries(ydb-core-public_http-ut PUBLIC + contrib-libs-cxxsupp + yutil + cpp-malloc-tcmalloc + libs-tcmalloc-no_percpu_cache + library-cpp-cpuid_check + cpp-testing-unittest_main + ydb-core-public_http + udf-service-exception_policy + yql-sql-pg_dummy + ydb-services-kesus + ydb-services-persqueue_cluster_discovery +) +target_link_options(ydb-core-public_http-ut PRIVATE + -ldl + -lrt + -Wl,--no-as-needed + -fPIC + -fPIC + -lpthread + -lrt + -ldl +) +target_sources(ydb-core-public_http-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/public_http/http_router_ut.cpp +) +add_test( + NAME + ydb-core-public_http-ut + COMMAND + ydb-core-public_http-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-core-public_http-ut) diff --git a/ydb/core/public_http/ut/CMakeLists.txt b/ydb/core/public_http/ut/CMakeLists.txt new file mode 100644 index 00000000000..79468a5d8d0 --- /dev/null +++ b/ydb/core/public_http/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 AND NOT ANDROID) + include(CMakeLists.linux.txt) +endif() |