summaryrefslogtreecommitdiff
path: root/0198-isolate-isula-search-ut-in-registry_images_ut.patch
blob: f7d57544fac3b0caa0e33947fc05e525391adb78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From 487191cf6bbedc14524056dd653bdc920e78f545 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
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 <zhongtao17@huawei.com>
---
 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