|
15 | 15 | "" |
16 | 16 |
|
17 | 17 | load("@rules_testing//lib:test_suite.bzl", "test_suite") |
18 | | -load("//python/private/pypi:simpleapi_download.bzl", "simpleapi_download") # buildifier: disable=bzl-visibility |
| 18 | +load("//python/private/pypi:simpleapi_download.bzl", "simpleapi_download", "strip_empty_path_segments") # buildifier: disable=bzl-visibility |
19 | 19 |
|
20 | 20 | _tests = [] |
21 | 21 |
|
22 | 22 | def _test_simple(env): |
23 | 23 | calls = [] |
24 | 24 |
|
25 | | - def read_simpleapi(ctx, url, attr, cache, block): |
| 25 | + def read_simpleapi(ctx, url, attr, cache, get_auth, block): |
26 | 26 | _ = ctx # buildifier: disable=unused-variable |
27 | 27 | _ = attr |
28 | 28 | _ = cache |
| 29 | + _ = get_auth |
29 | 30 | env.expect.that_bool(block).equals(False) |
30 | 31 | calls.append(url) |
31 | 32 | if "foo" in url and "main" in url: |
@@ -73,10 +74,11 @@ def _test_fail(env): |
73 | 74 | calls = [] |
74 | 75 | fails = [] |
75 | 76 |
|
76 | | - def read_simpleapi(ctx, url, attr, cache, block): |
| 77 | + def read_simpleapi(ctx, url, attr, cache, get_auth, block): |
77 | 78 | _ = ctx # buildifier: disable=unused-variable |
78 | 79 | _ = attr |
79 | 80 | _ = cache |
| 81 | + _ = get_auth |
80 | 82 | env.expect.that_bool(block).equals(False) |
81 | 83 | calls.append(url) |
82 | 84 | if "foo" in url: |
@@ -119,6 +121,121 @@ def _test_fail(env): |
119 | 121 |
|
120 | 122 | _tests.append(_test_fail) |
121 | 123 |
|
| 124 | +def _test_download_url(env): |
| 125 | + downloads = {} |
| 126 | + |
| 127 | + def download(url, output, **kwargs): |
| 128 | + _ = kwargs # buildifier: disable=unused-variable |
| 129 | + downloads[url[0]] = output |
| 130 | + return struct(success = True) |
| 131 | + |
| 132 | + simpleapi_download( |
| 133 | + ctx = struct( |
| 134 | + os = struct(environ = {}), |
| 135 | + download = download, |
| 136 | + read = lambda i: "contents of " + i, |
| 137 | + path = lambda i: "path/for/" + i, |
| 138 | + ), |
| 139 | + attr = struct( |
| 140 | + index_url_overrides = {}, |
| 141 | + index_url = "https://example.com/main/simple/", |
| 142 | + extra_index_urls = [], |
| 143 | + sources = ["foo", "bar", "baz"], |
| 144 | + envsubst = [], |
| 145 | + ), |
| 146 | + cache = {}, |
| 147 | + parallel_download = False, |
| 148 | + get_auth = lambda ctx, urls, ctx_attr: struct(), |
| 149 | + ) |
| 150 | + |
| 151 | + env.expect.that_dict(downloads).contains_exactly({ |
| 152 | + "https://example.com/main/simple/bar/": "path/for/https___example_com_main_simple_bar.html", |
| 153 | + "https://example.com/main/simple/baz/": "path/for/https___example_com_main_simple_baz.html", |
| 154 | + "https://example.com/main/simple/foo/": "path/for/https___example_com_main_simple_foo.html", |
| 155 | + }) |
| 156 | + |
| 157 | +_tests.append(_test_download_url) |
| 158 | + |
| 159 | +def _test_download_url_parallel(env): |
| 160 | + downloads = {} |
| 161 | + |
| 162 | + def download(url, output, **kwargs): |
| 163 | + _ = kwargs # buildifier: disable=unused-variable |
| 164 | + downloads[url[0]] = output |
| 165 | + return struct(wait = lambda: struct(success = True)) |
| 166 | + |
| 167 | + simpleapi_download( |
| 168 | + ctx = struct( |
| 169 | + os = struct(environ = {}), |
| 170 | + download = download, |
| 171 | + read = lambda i: "contents of " + i, |
| 172 | + path = lambda i: "path/for/" + i, |
| 173 | + ), |
| 174 | + attr = struct( |
| 175 | + index_url_overrides = {}, |
| 176 | + index_url = "https://example.com/main/simple/", |
| 177 | + extra_index_urls = [], |
| 178 | + sources = ["foo", "bar", "baz"], |
| 179 | + envsubst = [], |
| 180 | + ), |
| 181 | + cache = {}, |
| 182 | + parallel_download = True, |
| 183 | + get_auth = lambda ctx, urls, ctx_attr: struct(), |
| 184 | + ) |
| 185 | + |
| 186 | + env.expect.that_dict(downloads).contains_exactly({ |
| 187 | + "https://example.com/main/simple/bar/": "path/for/https___example_com_main_simple_bar.html", |
| 188 | + "https://example.com/main/simple/baz/": "path/for/https___example_com_main_simple_baz.html", |
| 189 | + "https://example.com/main/simple/foo/": "path/for/https___example_com_main_simple_foo.html", |
| 190 | + }) |
| 191 | + |
| 192 | +_tests.append(_test_download_url_parallel) |
| 193 | + |
| 194 | +def _test_download_envsubst_url(env): |
| 195 | + downloads = {} |
| 196 | + |
| 197 | + def download(url, output, **kwargs): |
| 198 | + _ = kwargs # buildifier: disable=unused-variable |
| 199 | + downloads[url[0]] = output |
| 200 | + return struct(success = True) |
| 201 | + |
| 202 | + simpleapi_download( |
| 203 | + ctx = struct( |
| 204 | + os = struct(environ = {"INDEX_URL": "https://example.com/main/simple/"}), |
| 205 | + download = download, |
| 206 | + read = lambda i: "contents of " + i, |
| 207 | + path = lambda i: "path/for/" + i, |
| 208 | + ), |
| 209 | + attr = struct( |
| 210 | + index_url_overrides = {}, |
| 211 | + index_url = "$INDEX_URL", |
| 212 | + extra_index_urls = [], |
| 213 | + sources = ["foo", "bar", "baz"], |
| 214 | + envsubst = ["INDEX_URL"], |
| 215 | + ), |
| 216 | + cache = {}, |
| 217 | + parallel_download = False, |
| 218 | + get_auth = lambda ctx, urls, ctx_attr: struct(), |
| 219 | + ) |
| 220 | + |
| 221 | + env.expect.that_dict(downloads).contains_exactly({ |
| 222 | + "https://example.com/main/simple/bar/": "path/for/~index_url~_bar.html", |
| 223 | + "https://example.com/main/simple/baz/": "path/for/~index_url~_baz.html", |
| 224 | + "https://example.com/main/simple/foo/": "path/for/~index_url~_foo.html", |
| 225 | + }) |
| 226 | + |
| 227 | +_tests.append(_test_download_envsubst_url) |
| 228 | + |
| 229 | +def _test_strip_empty_path_segments(env): |
| 230 | + env.expect.that_str(strip_empty_path_segments("no/scheme//is/unchanged")).equals("no/scheme//is/unchanged") |
| 231 | + env.expect.that_str(strip_empty_path_segments("scheme://with/no/empty/segments")).equals("scheme://with/no/empty/segments") |
| 232 | + env.expect.that_str(strip_empty_path_segments("scheme://with//empty/segments")).equals("scheme://with/empty/segments") |
| 233 | + env.expect.that_str(strip_empty_path_segments("scheme://with///multiple//empty/segments")).equals("scheme://with/multiple/empty/segments") |
| 234 | + env.expect.that_str(strip_empty_path_segments("scheme://with//trailing/slash/")).equals("scheme://with/trailing/slash/") |
| 235 | + env.expect.that_str(strip_empty_path_segments("scheme://with/trailing/slashes///")).equals("scheme://with/trailing/slashes/") |
| 236 | + |
| 237 | +_tests.append(_test_strip_empty_path_segments) |
| 238 | + |
122 | 239 | def simpleapi_download_test_suite(name): |
123 | 240 | """Create the test suite. |
124 | 241 |
|
|
0 commit comments