]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_upload.py: add test to exercise CHK hashing variations
authorBrian Warner <warner@allmydata.com>
Thu, 7 Feb 2008 03:03:35 +0000 (20:03 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 7 Feb 2008 03:03:35 +0000 (20:03 -0700)
src/allmydata/test/test_upload.py

index 1e135811d33376ba6eaf483be99e49860d5bec6d..a189231166d5c04c93b31d58907e25b1cb38a6c9 100644 (file)
@@ -8,6 +8,8 @@ from cStringIO import StringIO
 from allmydata import upload, encode, uri
 from allmydata.interfaces import IFileURI
 from allmydata.util.assertutil import precondition
+from allmydata.util.deferredutil import DeferredListShouldSucceed
+from allmydata.util import idlib
 from foolscap import eventual
 
 MiB = 1024*1024
@@ -440,6 +442,44 @@ class PeerSelection(unittest.TestCase):
         d.addCallback(_check)
         return d
 
+class StorageIndex(unittest.TestCase):
+    def test_params_must_matter(self):
+        DATA = "I am some data"
+        u = upload.Data(DATA)
+        eu = upload.EncryptAnUploadable(u)
+        d1 = eu.get_storage_index()
+
+        # CHK means the same data should encrypt the same way
+        u = upload.Data(DATA)
+        eu = upload.EncryptAnUploadable(u)
+        d1a = eu.get_storage_index()
+
+        # but if we change the encoding parameters, it should be different
+        u = upload.Data(DATA)
+        u.encoding_param_k = u.default_encoding_param_k + 1
+        eu = upload.EncryptAnUploadable(u)
+        d2 = eu.get_storage_index()
+
+        # and if we use a random key, it should be different than the CHK
+        u = upload.Data(DATA, contenthashkey=False)
+        eu = upload.EncryptAnUploadable(u)
+        d3 = eu.get_storage_index()
+        # and different from another instance
+        u = upload.Data(DATA, contenthashkey=False)
+        eu = upload.EncryptAnUploadable(u)
+        d4 = eu.get_storage_index()
+
+        d = DeferredListShouldSucceed([d1,d1a,d2,d3,d4])
+        def _done(res):
+            si1, si1a, si2, si3, si4 = res
+            self.failUnlessEqual(si1, si1a)
+            self.failIfEqual(si1, si2)
+            self.failIfEqual(si1, si3)
+            self.failIfEqual(si1, si4)
+            self.failIfEqual(si3, si4)
+        d.addCallback(_done)
+        return d
+
 
 # TODO:
 #  upload with exactly 75 peers (shares_of_happiness)