Skip to content

Commit 14e77fc

Browse files
committed
unit tests for mirrors
1 parent d1c1dc1 commit 14e77fc

File tree

8 files changed

+64
-2
lines changed

8 files changed

+64
-2
lines changed

stackinator/mirror.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _load_mirrors(self, cmdline_cache: Optional[str]) -> List[Dict]:
4343
raw = yaml.load(fid, Loader=yaml.Loader)
4444

4545
# validate the yaml
46-
#schema.CacheValidator.validate(raw)
46+
schema.CacheValidator.validate(raw)
4747

4848
mirrors = [mirror for mirror in raw if mirror["enabled"]]
4949
else:
@@ -197,7 +197,7 @@ def _key_setup(self, key_store: pathlib.Path):
197197
f"Check the key listed in mirrors.yaml in system config.")
198198

199199
file_type = magic.from_buffer(binary_key, mime=True)
200-
print("magic type:" , file_type)
200+
201201
if file_type != "application/x-gnupg-keyring":
202202
raise MirrorError(
203203
f"Key for mirror {mirror["name"]} is not a valid GPG key. \n"

unittests/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a bad key
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- name: bad-key
2+
url: https://mirror.spack.io
3+
public_key: /bad_key.gpg
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- name: bad-key-path
2+
url: https://mirror.spack.io
3+
public_key: /path/doesnt/exist
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- name: bad-url
2+
url: google.com
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- name: fake-mirror
2+
url: https://google.com
3+
- name: disabled-mirror
4+
url: https://google.com
5+
enabled: false
6+
- name: buildcache-mirror
7+
url: https://cache.spack.io/
8+
buildcache: true
9+
- name: bootstrap-mirror
10+
url: https://mirror.spack.io
11+
bootstrap: true

unittests/test_mirrors.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
import pathlib
3+
import stackinator.mirror as mirror
4+
import yaml
5+
6+
@pytest.fixture
7+
def test_path():
8+
return pathlib.Path(__file__).parent.resolve()
9+
10+
@pytest.fixture
11+
def systems_path(test_path):
12+
return test_path / "data" / "systems"
13+
14+
@pytest.fixture
15+
def valid_mirrors(systems_path):
16+
mirrors = {}
17+
mirrors["fake-mirror"] = {'url': 'https://google.com'}
18+
mirrors["buildcache-mirror"] = {'url': 'https://cache.spack.io/', 'buildcache': True}
19+
mirrors["bootstrap-mirror"] = {'url': 'https://mirror.spack.io', 'bootstrap': True}
20+
return mirrors
21+
22+
def test_mirror_init(systems_path, valid_mirrors):
23+
path = systems_path / "mirror_ok"
24+
mirrors = mirror.Mirrors(path)
25+
print(valid_mirrors)
26+
print(mirrors)
27+
assert mirrors == valid_mirrors
28+
assert mirrors.bootstrap_mirrors == [mirror for mirror in valid_mirrors if mirror["bootstrap"]]
29+
assert mirrors.build_cache_mirror == [mirror for mirror in valid_mirrors if mirror['buildcache']]
30+
# assert disabled mirror not in mirrors
31+
for mir in mirrors:
32+
assert mir["enabled"]
33+
# test that cmdline_cache gets added to mirrors?
34+
35+
def test_create_spack_mirrors_yaml(systems_path):
36+
pass
37+
38+
def test_create_bootstrap_configs():
39+
pass
40+
41+
def test_key_setup():
42+
pass

0 commit comments

Comments
 (0)