|
14 | 14 |
|
15 | 15 | import taskcluster_urls as liburls |
16 | 16 |
|
| 17 | +from taskgraph.config import GraphConfig |
17 | 18 | from taskgraph.util import docker |
18 | 19 |
|
19 | 20 | from .mockedopen import MockedOpen |
@@ -269,3 +270,81 @@ def test_stream_context_tar(self): |
269 | 270 | ) |
270 | 271 | finally: |
271 | 272 | shutil.rmtree(tmp) |
| 273 | + |
| 274 | + def test_image_paths_with_custom_kind(self): |
| 275 | + """Test image_paths function with graph_config parameter.""" |
| 276 | + temp_dir = tempfile.mkdtemp() |
| 277 | + try: |
| 278 | + # Create the kinds directory structure |
| 279 | + kinds_dir = os.path.join(temp_dir, "kinds", "docker-test-image") |
| 280 | + os.makedirs(kinds_dir) |
| 281 | + |
| 282 | + # Create the kind.yml file with task definitions |
| 283 | + kind_yml_path = os.path.join(kinds_dir, "kind.yml") |
| 284 | + with open(kind_yml_path, "w") as f: |
| 285 | + f.write("tasks:\n") |
| 286 | + f.write(" test-image:\n") |
| 287 | + f.write(" definition: test-image\n") |
| 288 | + f.write(" another-image:\n") |
| 289 | + f.write(" definition: custom-path\n") |
| 290 | + |
| 291 | + # Create graph config pointing to our test directory |
| 292 | + temp_graph_config = GraphConfig( |
| 293 | + { |
| 294 | + "trust-domain": "test-domain", |
| 295 | + "docker-image-kind": "docker-test-image", |
| 296 | + }, |
| 297 | + temp_dir, |
| 298 | + ) |
| 299 | + |
| 300 | + paths = docker.image_paths(temp_graph_config) |
| 301 | + |
| 302 | + expected_docker_dir = os.path.join(temp_graph_config.root_dir, "docker") |
| 303 | + self.assertEqual( |
| 304 | + paths["test-image"], os.path.join(expected_docker_dir, "test-image") |
| 305 | + ) |
| 306 | + self.assertEqual( |
| 307 | + paths["another-image"], os.path.join(expected_docker_dir, "custom-path") |
| 308 | + ) |
| 309 | + finally: |
| 310 | + shutil.rmtree(temp_dir) |
| 311 | + |
| 312 | + def test_parse_volumes_with_graph_config(self): |
| 313 | + """Test parse_volumes function with graph_config parameter.""" |
| 314 | + temp_dir = tempfile.mkdtemp() |
| 315 | + try: |
| 316 | + kinds_dir = os.path.join(temp_dir, "kinds", "docker-test-image") |
| 317 | + os.makedirs(kinds_dir) |
| 318 | + |
| 319 | + kind_yml_path = os.path.join(kinds_dir, "kind.yml") |
| 320 | + with open(kind_yml_path, "w") as f: |
| 321 | + f.write("tasks:\n") |
| 322 | + f.write(" test-image:\n") |
| 323 | + f.write(" definition: test-image\n") |
| 324 | + |
| 325 | + docker_dir = os.path.join(temp_dir, "docker") |
| 326 | + os.makedirs(docker_dir) |
| 327 | + |
| 328 | + image_dir = os.path.join(docker_dir, "test-image") |
| 329 | + os.makedirs(image_dir) |
| 330 | + |
| 331 | + dockerfile_path = os.path.join(image_dir, "Dockerfile") |
| 332 | + with open(dockerfile_path, "wb") as fh: |
| 333 | + fh.write(b"VOLUME /foo/bar \n") |
| 334 | + fh.write(b"VOLUME /hello /world \n") |
| 335 | + |
| 336 | + test_graph_config = GraphConfig( |
| 337 | + { |
| 338 | + "trust-domain": "test-domain", |
| 339 | + "docker-image-kind": "docker-test-image", |
| 340 | + }, |
| 341 | + temp_dir, |
| 342 | + ) |
| 343 | + |
| 344 | + volumes = docker.parse_volumes("test-image", test_graph_config) |
| 345 | + |
| 346 | + expected_volumes = {"/foo/bar", "/hello", "/world"} |
| 347 | + self.assertEqual(volumes, expected_volumes) |
| 348 | + |
| 349 | + finally: |
| 350 | + shutil.rmtree(temp_dir) |
0 commit comments