diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-23 15:54:02 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-23 15:54:02 +0000 |
commit | 469459ac1a4cd3bd7b5161fe8d71567190257b56 (patch) | |
tree | 14f5ad7e2b681b56efcddd8f9ec74492b53a5dd0 /morphlib/cachedrepo_tests.py | |
parent | 7a11ffef90359abf7907fbe6d6afd153fb4ed745 (diff) | |
download | morph-469459ac1a4cd3bd7b5161fe8d71567190257b56.tar.gz |
Fix CachedRepo.resolve_ref unit test for missing SHA1
CachedRepo.resolve_ref does, effectively, this:
absref = git rev-parse --verify $ref
git log -1 --format=format:%T $absref
Roughly, "git rev-parse" takes any ref and returns the corresponding
SHA1. If the ref looks like a SHA1 (40 hex digits), it is returned
as-is, and despite --verify is not checked for existence.
"git log" then takes the SHA1 and returns the **tree** SHA1, as
opposed to the commit one, and if the commit doesn't exist, barfs.
The unit test for resolve_ref with an invalid SHA1 currently succeeds
for the wrong reason. The mocked _rev_parse fails for an unknown SHA1
(raising cliapp.AppException), which causes resolve_ref to raise
InvalidReferenceError, which the unit test expects. However, the real
implementation of _rev_parse wouldn't fail in that way, and so the
unit test doesn't test the thing it's meant to test: that resolve_ref
actually works the expected way for an unknown SHA1. What actually
happens is that resolve_ref calls _show_tree_hash, which raises
cliapp.AppException for an unknown SHA1, resulting in horror and
despair, instead of resolve_ref raising InvalidReferenceError.
This commit fixes the unit test so that it causes the right code
path in resolve_ref to be executed. This makes the unit test suite
to fail.
Diffstat (limited to 'morphlib/cachedrepo_tests.py')
-rw-r--r-- | morphlib/cachedrepo_tests.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/morphlib/cachedrepo_tests.py b/morphlib/cachedrepo_tests.py index 18704f58..b1825eba 100644 --- a/morphlib/cachedrepo_tests.py +++ b/morphlib/cachedrepo_tests.py @@ -32,8 +32,11 @@ class CachedRepoTests(unittest.TestCase): "kind": "chunk" }''' + bad_sha1_known_to_rev_parse = 'cafecafecafecafecafecafecafecafecafecafe' + def rev_parse(self, ref): output = { + self.bad_sha1_known_to_rev_parse: self.bad_sha1_known_to_rev_parse, 'a4da32f5a81c8bc6d660404724cedc3bc0914a75': 'a4da32f5a81c8bc6d660404724cedc3bc0914a75', 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9': @@ -159,7 +162,7 @@ class CachedRepoTests(unittest.TestCase): def test_fail_resolving_an_invalid_sha1_ref(self): self.assertRaises(cachedrepo.InvalidReferenceError, self.repo.resolve_ref, - '079bbfd447c8534e464ce5d40b80114c2022ebf4') + self.bad_sha1_known_to_rev_parse) def test_cat_existing_file_in_existing_ref(self): data = self.repo.cat('e28a23812eadf2fce6583b8819b9c5dbd36b9fb9', |