|
3 | 3 | # Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | # -------------------------------------------------------------------------------------------- |
5 | 5 |
|
6 | | -import contextlib |
7 | 6 | import io |
8 | 7 | import json |
9 | 8 | import os |
10 | 9 | import subprocess |
11 | 10 | import tempfile |
12 | | -import pytest |
13 | 11 |
|
14 | 12 | from azext_confcom.custom import acifragmentgen_confcom, fragment_push, fragment_attach |
15 | 13 |
|
16 | | -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), "..")) |
17 | | -SAMPLES_DIR = os.path.abspath(os.path.join(TEST_DIR, "..", "..", "..", "samples")) |
18 | | - |
19 | | - |
20 | | -@pytest.fixture() |
21 | | -def docker_image(): |
22 | | - |
23 | | - registry_id = subprocess.run( |
24 | | - ["docker", "run", "-d", "-p", "0:5000", "registry:2"], |
25 | | - stdout=subprocess.PIPE, |
26 | | - text=True, |
27 | | - ).stdout |
28 | | - |
29 | | - registry_port = subprocess.run( |
30 | | - ["docker", "port", registry_id], |
31 | | - stdout=subprocess.PIPE, |
32 | | - text=True, |
33 | | - ).stdout.split(":")[-1].strip() |
34 | | - |
35 | | - test_container_ref = f"localhost:{registry_port}/hello-world:latest" |
36 | | - subprocess.run(["docker", "pull", "hello-world"]) |
37 | | - subprocess.run(["docker", "tag", "hello-world", test_container_ref]) |
38 | | - subprocess.run(["docker", "push", test_container_ref]) |
39 | | - |
40 | | - with tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8", delete=True) as temp_file: |
41 | | - json.dump({ |
42 | | - "version": "1.0.0", |
43 | | - "containers": [ |
44 | | - { |
45 | | - "name": "hello-world", |
46 | | - "properties": { |
47 | | - "image": test_container_ref, |
48 | | - }, |
49 | | - } |
50 | | - ] |
51 | | - }, temp_file) |
52 | | - temp_file.flush() |
53 | | - |
54 | | - yield test_container_ref, temp_file.name |
55 | | - |
56 | | - subprocess.run(["docker", "stop", registry_id]) |
57 | | - |
58 | | - |
59 | | -@pytest.fixture(scope="session") |
60 | | -def cert_chain(): |
61 | | - with tempfile.TemporaryDirectory() as temp_dir: |
62 | | - subprocess.run( |
63 | | - [ |
64 | | - os.path.join(SAMPLES_DIR, "certs", "create_certchain.sh"), |
65 | | - temp_dir |
66 | | - ], |
67 | | - check=True, |
68 | | - ) |
69 | | - yield temp_dir |
70 | | - |
71 | 14 |
|
72 | 15 | def test_acifragmentgen_fragment_gen(docker_image): |
73 | 16 |
|
|
0 commit comments