From 487191cf6bbedc14524056dd653bdc920e78f545 Mon Sep 17 00:00:00 2001 From: zhongtao Date: Wed, 19 Feb 2025 11:52:59 +1400 Subject: [PATCH 198/198] isolate isula search ut in registry_images_ut Signed-off-by: zhongtao --- test/image/oci/registry/CMakeLists.txt | 10 ++- test/image/oci/registry/registry_ut.cc | 103 +++++++++++++------------ 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/test/image/oci/registry/CMakeLists.txt b/test/image/oci/registry/CMakeLists.txt index d78bb7d3..5ae59ebc 100644 --- a/test/image/oci/registry/CMakeLists.txt +++ b/test/image/oci/registry/CMakeLists.txt @@ -2,7 +2,16 @@ project(iSulad_UT) SET(EXE registry_images_ut) +if(ENABLE_IMAGE_SEARCH) + set(search_srcs + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/registry_apiv1.c + ) +else() + set(search_srcs "") +endif() + add_executable(${EXE} + ${search_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/utils.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/utils_regex.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/utils_verify.c @@ -34,7 +43,6 @@ add_executable(${EXE} ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/remote_layer_support/ro_symlink_maintain.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/registry.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/registry_apiv2.c - ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/registry_apiv1.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/http_request.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/certs.c ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/registry/auths.c diff --git a/test/image/oci/registry/registry_ut.cc b/test/image/oci/registry/registry_ut.cc index 4eacdb11..c5d9717c 100644 --- a/test/image/oci/registry/registry_ut.cc +++ b/test/image/oci/registry/registry_ut.cc @@ -395,57 +395,6 @@ int invokeHttpRequestLogin(const char *url, struct http_get_options *options, lo return 0; } -int invokeHttpRequestSearch(const char *url, struct http_get_options *options, long *response_code, int recursive_len) -{ -#define RETRY_TIMES 3 -#define SEARCH_TEST_NOT_FOUND 2 -#define SEARCH_TEST_SERVER_ERROR 5 -#define SEARCH_TEST_RETRY_SUCCESS 8 - std::string file; - char *data = nullptr; - Buffer *output_buffer = (Buffer *)options->output; - static int search_count = 0; - - ERROR("url is %s", url); - ERROR("search_count is %d", search_count); - - std::string data_path = get_dir() + "/data/oci/"; - if (strcmp(url, "https://index.docker.io/v1/_ping") == 0) { - file = data_path + "ping_v1_head"; - } else if (util_has_prefix(url, "https://index.docker.io/v1/search?q=busybox")) { - search_count++; - // test not find - if (search_count >= SEARCH_TEST_NOT_FOUND && search_count < SEARCH_TEST_NOT_FOUND + RETRY_TIMES) { - file = data_path + "search_result_404"; - } - // test server error and restry - else if ((search_count >= SEARCH_TEST_SERVER_ERROR && search_count < SEARCH_TEST_SERVER_ERROR + RETRY_TIMES) || - (search_count == SEARCH_TEST_RETRY_SUCCESS)) { - file = data_path + "search_server_error"; - } else { - file = data_path + "search_result"; - } - } else { - ERROR("%s not match failed", url); - return -1; - } - - data = util_read_text_file(file.c_str()); - if (data == nullptr) { - ERROR("read file %s failed", file.c_str()); - return -1; - } - - if (options->outputtype == HTTP_REQUEST_STRBUF) { - free(output_buffer->contents); - output_buffer->contents = util_strdup_s(data); - } - free(data); - - return 0; -} - - int invokeStorageImgCreate(const char *id, const char *parent_id, const char *metadata, struct storage_img_create_options *opts) { @@ -921,6 +870,57 @@ TEST_F(RegistryUnitTest, test_cleanup) ASSERT_EQ(remove_certs(mirror_dir), 0); } +#ifdef ENABLE_IMAGE_SEARCH +int invokeHttpRequestSearch(const char *url, struct http_get_options *options, long *response_code, int recursive_len) +{ +#define RETRY_TIMES 3 +#define SEARCH_TEST_NOT_FOUND 2 +#define SEARCH_TEST_SERVER_ERROR 5 +#define SEARCH_TEST_RETRY_SUCCESS 8 + std::string file; + char *data = nullptr; + Buffer *output_buffer = (Buffer *)options->output; + static int search_count = 0; + + ERROR("url is %s", url); + ERROR("search_count is %d", search_count); + + std::string data_path = get_dir() + "/data/oci/"; + if (strcmp(url, "https://index.docker.io/v1/_ping") == 0) { + file = data_path + "ping_v1_head"; + } else if (util_has_prefix(url, "https://index.docker.io/v1/search?q=busybox")) { + search_count++; + // test not find + if (search_count >= SEARCH_TEST_NOT_FOUND && search_count < SEARCH_TEST_NOT_FOUND + RETRY_TIMES) { + file = data_path + "search_result_404"; + } + // test server error and restry + else if ((search_count >= SEARCH_TEST_SERVER_ERROR && search_count < SEARCH_TEST_SERVER_ERROR + RETRY_TIMES) || + (search_count == SEARCH_TEST_RETRY_SUCCESS)) { + file = data_path + "search_server_error"; + } else { + file = data_path + "search_result"; + } + } else { + ERROR("%s not match failed", url); + return -1; + } + + data = util_read_text_file(file.c_str()); + if (data == nullptr) { + ERROR("read file %s failed", file.c_str()); + return -1; + } + + if (options->outputtype == HTTP_REQUEST_STRBUF) { + free(output_buffer->contents); + output_buffer->contents = util_strdup_s(data); + } + free(data); + + return 0; +} + TEST_F(RegistryUnitTest, test_search_image) { registry_search_options *options = nullptr; @@ -971,3 +971,4 @@ TEST_F(RegistryUnitTest, test_search_image) free_registry_search_options(options); } +#endif \ No newline at end of file -- 2.34.1