Skip to content

Commit 98f6407

Browse files
committed
Adding a unittest.
1 parent 4c995ff commit 98f6407

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

stackinator/mirror.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ def _load_mirrors(self, cmdline_cache: Optional[str]) -> Dict[str, Dict]:
5454
else:
5555
mirrors = {}
5656

57+
try:
58+
schema.MirrorsValidator.validate(mirrors)
59+
except ValueError as err:
60+
raise MirrorError("Mirror config does not comply with schema.\n{err}")
61+
5762
# Add or set the cache given on the command line as the buildcache destination
5863
if cmdline_cache is not None:
5964
# If the mirror name given on the command line isn't in the config, assume it
6065
# is the URL to a build cache.
61-
if cmdline_cache in mirrors:
66+
if cmdline_cache not in mirrors:
6267
mirrors['cmdline_cache'] = {
6368
'url': cmdline_cache,
6469
'description': "Cache configured via command line.",
@@ -74,16 +79,10 @@ def _load_mirrors(self, cmdline_cache: Optional[str]) -> Dict[str, Dict]:
7479
mirror['cache'] = True
7580

7681
# Load the cache as defined by the deprecated 'cache.yaml' file.
77-
mirrors['legacy_cache_cfg'] = self._load_legacy_cache()
78-
82+
legacy_cache = self._load_legacy_cache()
83+
if legacy_cache is not None:
84+
mirrors['legacy_cache_cfg'] = legacy_cache
7985

80-
try:
81-
# validate the yaml, including anything we added
82-
schema.MirrorsValidator.validate(mirrors)
83-
except ValueError as err:
84-
raise MirrorError(
85-
"Mirror config does not comply with schema.\n{err}"
86-
)
8786

8887
caches = [mirror for mirror in mirrors.values() if mirror['cache']]
8988
if len(caches) > 1:
@@ -92,7 +91,7 @@ def _load_mirrors(self, cmdline_cache: Optional[str]) -> Dict[str, Dict]:
9291
"Some of these may have come from a legacy 'cache.yaml' or the '--cache' option.\n"
9392
f"{self._pp_yaml(caches)}")
9493

95-
return {name: mirror for name, mirror in raw.items() if mirror["enabled"]}
94+
return {name: mirror for name, mirror in mirrors.items() if mirror["enabled"]}
9695

9796
@staticmethod
9897
def _pp_yaml(object):

unittests/test_mirrors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ def test_mirror_init(systems_path, valid_mirrors):
3030
assert mir["enabled"]
3131
# test that cmdline_cache gets added to mirrors?
3232

33+
def test_command_line_cache(systems_path):
34+
"""Check that adding a cache from the command line works."""
35+
36+
mirrors = mirror.Mirrors(systems_path/'mirror-ok', cmdline_cache=systems_path.as_posix())
37+
38+
assert len(mirrors.mirrors) == 4
39+
40+
3341
def test_create_spack_mirrors_yaml(systems_path):
3442
pass
3543

3644
def test_create_bootstrap_configs():
3745
pass
3846

3947
def test_key_setup():
40-
pass
48+
pass

0 commit comments

Comments
 (0)