|
4 | 4 |
|
5 | 5 | import os |
6 | 6 | import shutil |
7 | | -import sys |
8 | 7 |
|
9 | 8 | import pytest |
10 | 9 |
|
11 | 10 | import oras.client |
12 | 11 |
|
13 | 12 | here = os.path.abspath(os.path.dirname(__file__)) |
14 | 13 |
|
15 | | -registry_host = os.environ.get("ORAS_HOST") |
16 | | -registry_port = os.environ.get("ORAS_PORT") |
17 | | -with_auth = os.environ.get("ORAS_AUTH") == "true" |
18 | | -oras_user = os.environ.get("ORAS_USER", "myuser") |
19 | | -oras_pass = os.environ.get("ORAS_PASS", "mypass") |
20 | 14 |
|
21 | | - |
22 | | -def setup_module(module): |
23 | | - """ |
24 | | - Ensure the registry port and host is in the environment. |
25 | | - """ |
26 | | - if not registry_host or not registry_port: |
27 | | - sys.exit( |
28 | | - "You must export ORAS_HOST and ORAS_PORT for a running registry before running tests." |
29 | | - ) |
30 | | - if with_auth and not oras_user or not oras_pass: |
31 | | - sys.exit("To test auth you need to export ORAS_USER and ORAS_PASS") |
32 | | - |
33 | | - |
34 | | -registry = f"{registry_host}:{registry_port}" |
35 | | -target = f"{registry}/dinosaur/artifact:v1" |
36 | | -target_dir = f"{registry}/dinosaur/directory:v1" |
37 | | - |
38 | | - |
39 | | -def test_basic_oras(): |
| 15 | +def test_basic_oras(registry): |
40 | 16 | """ |
41 | 17 | Basic tests for oras (without authentication) |
42 | 18 | """ |
43 | 19 | client = oras.client.OrasClient(hostname=registry, insecure=True) |
44 | 20 | assert "Python version" in client.version() |
45 | 21 |
|
46 | 22 |
|
47 | | -@pytest.mark.skipif(not with_auth, reason="basic auth is needed for login/logout") |
48 | | -def test_login_logout(): |
| 23 | +@pytest.mark.with_auth(True) |
| 24 | +def test_login_logout(registry, credentials): |
49 | 25 | """ |
50 | 26 | Login and logout are all we can test with basic auth! |
51 | 27 | """ |
52 | 28 | client = oras.client.OrasClient(hostname=registry, insecure=True) |
53 | 29 | res = client.login( |
54 | | - hostname=registry, username=oras_user, password=oras_pass, insecure=True |
| 30 | + hostname=registry, |
| 31 | + username=credentials.user, |
| 32 | + password=credentials.password, |
| 33 | + insecure=True, |
55 | 34 | ) |
56 | 35 | assert res["Status"] == "Login Succeeded" |
57 | 36 | client.logout(registry) |
58 | 37 |
|
59 | 38 |
|
60 | | -@pytest.mark.skipif(with_auth, reason="token auth is needed for push and pull") |
61 | | -def test_basic_push_pull(tmp_path): |
| 39 | +@pytest.mark.with_auth(False) |
| 40 | +def test_basic_push_pull(tmp_path, registry, credentials, target): |
62 | 41 | """ |
63 | 42 | Basic tests for oras (without authentication) |
64 | 43 | """ |
@@ -88,8 +67,8 @@ def test_basic_push_pull(tmp_path): |
88 | 67 | assert res.status_code == 201 |
89 | 68 |
|
90 | 69 |
|
91 | | -@pytest.mark.skipif(with_auth, reason="token auth is needed for push and pull") |
92 | | -def test_get_delete_tags(tmp_path): |
| 70 | +@pytest.mark.with_auth(False) |
| 71 | +def test_get_delete_tags(tmp_path, registry, credentials, target): |
93 | 72 | """ |
94 | 73 | Test creationg, getting, and deleting tags. |
95 | 74 | """ |
@@ -139,8 +118,8 @@ def test_get_many_tags(): |
139 | 118 | assert len(tags) == 10 |
140 | 119 |
|
141 | 120 |
|
142 | | -@pytest.mark.skipif(with_auth, reason="token auth is needed for push and pull") |
143 | | -def test_directory_push_pull(tmp_path): |
| 121 | +@pytest.mark.with_auth(False) |
| 122 | +def test_directory_push_pull(tmp_path, registry, credentials, target_dir): |
144 | 123 | """ |
145 | 124 | Test push and pull for directory |
146 | 125 | """ |
|
0 commit comments