From 6d9eee86f1ea75c0f2666dc4282d8b10fee63e7b Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 28 Mar 2014 14:22:39 +0000 Subject: CacheKeyComputer Tests: Update to explicitly test for memoisation Explicitly test that we get the same result twice when computing ids and keys for the same artifact. This has the effect of verifying that the memoisation code is correctly operating. Signed-Off-By: Daniel Silverstone --- morphlib/cachekeycomputer_tests.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py index 4e73e905..dd10307f 100644 --- a/morphlib/cachekeycomputer_tests.py +++ b/morphlib/cachekeycomputer_tests.py @@ -148,6 +148,19 @@ class CacheKeyComputerTests(unittest.TestCase): validchars = '0123456789abcdef' return len(s) == 64 and all([c in validchars for c in s]) + 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)) + + 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) + hash1 = self.ckc._hash_id(id1) + hash2 = self.ckc._hash_id(id2) + self.assertEqual(hash1, hash2) + def test_compute_key_returns_sha256(self): artifact = self._find_artifact('system-rootfs') self.assertTrue(self._valid_sha256( -- cgit v1.2.1