Skip to content

Commit 9829bfc

Browse files
committed
Unit test tweaking.
1 parent 5c5faed commit 9829bfc

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

stackinator/mirror.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ def _load_mirrors(self, cmdline_cache: Optional[pathlib.Path]) -> Dict[str, Dict
6666
except ValueError as err:
6767
raise MirrorError(f"Mirror config does not comply with schema.\n{err}")
6868

69-
caches = {name: mirror for name, mirror in mirrors.items() if mirror['cache']}
69+
caches = [name for name, mirror in mirrors.items() if mirror['cache']]
7070
if len(caches) > 1:
7171
raise MirrorError(
7272
"Mirror config has more than one mirror specified as the build cache destination.\n"
7373
f"{self._pp_yaml(caches)}")
74+
elif caches:
75+
cache = mirrors[caches[0]]
76+
if not cache.get('private_key'):
77+
raise MirrorError(f"Mirror build cache config '{caches[0]}' missing a required 'private_key' path.")
7478

7579
# Load the cache as defined by the deprecated 'cache.yaml' file.
7680
if cmdline_cache is not None:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
root: /tmp/foo
2+
key: ../../test-gpg-priv.asc

unittests/data/systems/mirror-ok/mirrors.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ disabled-mirror:
55
enabled: false
66
buildcache-mirror:
77
url: https://mirror.spack.io
8+
private_key: '../test-gpg-priv.asc'
89
cache: true
910
bootstrap-mirror:
1011
url: https://mirror.spack.io
11-
bootstrap: true
12+
bootstrap: true

unittests/test_mirrors.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ def test_mirror_init(systems_path, valid_mirrors):
3434
def test_command_line_cache(systems_path):
3535
"""Check that adding a cache from the command line works."""
3636

37-
mirrors = mirror.Mirrors(systems_path/'mirror-basic',
38-
cmdline_cache=systems_path/'mirror-basic/cache.yaml')
37+
mirrors = mirror.Mirrors(systems_path/'mirror-ok',
38+
cmdline_cache=systems_path/'mirror-ok/cache.yaml')
3939

40-
assert len(mirrors.mirrors) == 3
40+
assert len(mirrors.mirrors) == 4
41+
# This should always be the build cache even though one is already defined.
4142
assert mirrors.build_cache_mirror == 'cmdline_cache'
4243
cache_mirror = mirrors.mirrors['cmdline_cache']
4344
assert cache_mirror['url'] == '/tmp/foo'
@@ -46,12 +47,6 @@ def test_command_line_cache(systems_path):
4647
assert not cache_mirror['bootstrap']
4748
assert cache_mirror['mount_specific']
4849

49-
def test_multi_buildcache(systems_path):
50-
"""Make sure we throw appropriate errors when there's more than one build cache defined."""
51-
52-
53-
54-
5550
def test_create_spack_mirrors_yaml(systems_path):
5651
pass
5752

0 commit comments

Comments
 (0)