From: Brian Warner Date: Tue, 4 Mar 2008 21:42:25 +0000 (-0700) Subject: test_util.py: get 100% test coverage for hashutil.py X-Git-Tag: allmydata-tahoe-0.9.0~72 X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/reliability?a=commitdiff_plain;h=4daa817502b18640c481ec91d85e114e9a168d94;p=tahoe-lafs%2Ftahoe-lafs.git test_util.py: get 100% test coverage for hashutil.py --- diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index 9c2c0cca..d80f0903 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -384,6 +384,11 @@ class DeferredUtilTests(unittest.TestCase): self.failUnless(f.check(RuntimeError)) class HashUtilTests(unittest.TestCase): + + def test_random_key(self): + k = hashutil.random_key() + self.failUnlessEqual(len(k), hashutil.KEYLEN) + def test_sha256d(self): h1 = hashutil.tagged_hash("tag1", "value") h2 = hashutil.tagged_hasher("tag1") @@ -408,3 +413,34 @@ class HashUtilTests(unittest.TestCase): h2.update("data") h2 = h2.digest() self.failUnlessEqual(h1, h2) + + def test_hashers(self): + h1 = hashutil.block_hash("foo") + h2 = hashutil.block_hasher() + h2.update("foo") + self.failUnlessEqual(h1, h2.digest()) + + h1 = hashutil.uri_extension_hash("foo") + h2 = hashutil.uri_extension_hasher() + h2.update("foo") + self.failUnlessEqual(h1, h2.digest()) + + h1 = hashutil.plaintext_hash("foo") + h2 = hashutil.plaintext_hasher() + h2.update("foo") + self.failUnlessEqual(h1, h2.digest()) + + h1 = hashutil.crypttext_hash("foo") + h2 = hashutil.crypttext_hasher() + h2.update("foo") + self.failUnlessEqual(h1, h2.digest()) + + h1 = hashutil.crypttext_segment_hash("foo") + h2 = hashutil.crypttext_segment_hasher() + h2.update("foo") + self.failUnlessEqual(h1, h2.digest()) + + h1 = hashutil.plaintext_segment_hash("foo") + h2 = hashutil.plaintext_segment_hasher() + h2.update("foo") + self.failUnlessEqual(h1, h2.digest())