summaryrefslogtreecommitdiff
path: root/morphlib/cachekeycomputer_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/cachekeycomputer_tests.py')
-rw-r--r--morphlib/cachekeycomputer_tests.py69
1 files changed, 14 insertions, 55 deletions
diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py
index 8558db6d..55936f94 100644
--- a/morphlib/cachekeycomputer_tests.py
+++ b/morphlib/cachekeycomputer_tests.py
@@ -83,18 +83,14 @@ class CacheKeyComputerTests(unittest.TestCase):
- morph: stratum2
''',
}.iteritems():
- source = morphlib.source.Source(
- 'repo', 'original/ref', 'sha', 'tree',
- loader.load_from_string(text), name)
- self.source_pool.add(source)
+ morph = loader.load_from_string(text)
+ sources = morphlib.source.make_sources('repo', 'original/ref',
+ name, 'sha1',
+ 'tree', morph)
+ for source in sources:
+ self.source_pool.add(source)
# FIXME: This should use MorphologyFactory
m = source.morphology
- if m['kind'] == 'system':
- m.builds_artifacts = [m['name'] + '-rootfs']
- elif m['kind'] == 'stratum':
- m.builds_artifacts = [m['name']]
- elif m['kind'] == 'chunk':
- m.builds_artifacts = [m['name']]
self.build_env = DummyBuildEnvironment({
"LOGNAME": "foouser",
"MORPH_ARCH": "dummy",
@@ -127,7 +123,7 @@ class CacheKeyComputerTests(unittest.TestCase):
self.ckc._hash_tuple = inccount(self.ckc._hash_tuple, 'tuple')
artifact = self._find_artifact('system-rootfs')
- self.ckc.compute_key(artifact)
+ self.ckc.compute_key(artifact.source)
self.assertNotEqual(runcount['thing'], 0)
self.assertNotEqual(runcount['dict'], 0)
@@ -140,13 +136,13 @@ class CacheKeyComputerTests(unittest.TestCase):
def test_compute_twice_same_key(self):
artifact = self._find_artifact('system-rootfs')
- self.assertEqual(self.ckc.compute_key(artifact),
- self.ckc.compute_key(artifact))
+ self.assertEqual(self.ckc.compute_key(artifact.source),
+ self.ckc.compute_key(artifact.source))
def test_compute_twice_same_id(self):
artifact = self._find_artifact('system-rootfs')
- id1 = self.ckc.get_cache_id(artifact)
- id2 = self.ckc.get_cache_id(artifact)
+ id1 = self.ckc.get_cache_id(artifact.source)
+ id2 = self.ckc.get_cache_id(artifact.source)
hash1 = self.ckc._hash_id(id1)
hash2 = self.ckc._hash_id(id2)
self.assertEqual(hash1, hash2)
@@ -154,50 +150,13 @@ class CacheKeyComputerTests(unittest.TestCase):
def test_compute_key_returns_sha256(self):
artifact = self._find_artifact('system-rootfs')
self.assertTrue(self._valid_sha256(
- self.ckc.compute_key(artifact)))
+ self.ckc.compute_key(artifact.source)))
def test_different_env_gives_different_key(self):
artifact = self._find_artifact('system-rootfs')
- oldsha = self.ckc.compute_key(artifact)
+ oldsha = self.ckc.compute_key(artifact.source)
build_env = copy.deepcopy(self.build_env)
build_env.env["USER"] = "brian"
ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
- self.assertNotEqual(oldsha, ckc.compute_key(artifact))
-
- def test_same_morphology_text_but_changed_sha1_gives_same_cache_key(self):
- old_artifact = self._find_artifact('system-rootfs')
- morphology = old_artifact.source.morphology
- new_source = morphlib.source.Source('repo', 'original/ref', 'newsha',
- 'tree', morphology,
- old_artifact.source.filename)
- sp = morphlib.sourcepool.SourcePool()
- for source in self.source_pool:
- if source == old_artifact.source:
- sp.add(new_source)
- else:
- sp.add(source)
- artifacts = self.artifact_resolver.resolve_artifacts(sp)
- for new_artifact in artifacts:
- if new_artifact.source == new_source:
- break
- else:
- self.assertTrue(False)
-
- old_sha = self.ckc.compute_key(old_artifact)
- new_sha = self.ckc.compute_key(new_artifact)
- self.assertEqual(old_sha, new_sha)
-
- def test_same_morphology_added_to_source_pool_only_appears_once(self):
- loader = morphlib.morphloader.MorphologyLoader()
- m = loader.load_from_string(
- '''
- name: chunk
- kind: chunk
- ''')
- src = morphlib.source.Source('repo', 'original/ref', 'sha', 'tree', m,
- 'chunk.morph')
- sp = morphlib.sourcepool.SourcePool()
- sp.add(src)
- sp.add(src)
- self.assertEqual(1, len([s for s in sp if s == src]))
+ self.assertNotEqual(oldsha, ckc.compute_key(artifact.source))