Ver Fonte

Add two additional tests.

Jonas Borgström há 11 anos atrás
pai
commit
b5b0b7b322
2 ficheiros alterados com 27 adições e 0 exclusões
  1. 12 0
      attic/testsuite/hashindex.py
  2. 15 0
      attic/testsuite/repository.py

+ 12 - 0
attic/testsuite/hashindex.py

@@ -63,4 +63,16 @@ class HashIndexTestCase(AtticTestCase):
         idx.flush()
         self.assert_equal(initial_size, os.path.getsize(idx_name.name))
 
+    def test_read_only(self):
+        """Make sure read_only indices work even they contain a lot of tombstones
+        """
+        idx_name = tempfile.NamedTemporaryFile()
+        idx = NSIndex.create(idx_name.name)
+        for x in range(100):
+            idx[bytes('%-0.32d' % x, 'ascii')] = x, x
+        for x in range(99):
+            del idx[bytes('%-0.32d' % x, 'ascii')]
+        idx.flush()
+        idx2 = NSIndex(idx_name.name, readonly=True)
+        self.assert_equal(idx2[bytes('%-0.32d' % 99, 'ascii')], (99, 99))
 

+ 15 - 0
attic/testsuite/repository.py

@@ -1,6 +1,7 @@
 import os
 import shutil
 import tempfile
+from attic.hashindex import NSIndex
 from attic.helpers import Location
 from attic.remote import RemoteRepository
 from attic.repository import Repository
@@ -48,6 +49,20 @@ class RepositoryTestCase(AtticTestCase):
         self.repository.commit()
         self.assert_equal(self.repository.get(b'00000000000000000000000000000001'), b'bar')
 
+    def test_index_rebuild(self):
+        """Verify that repository index rebuild works properly
+        """
+        def extract_and_unlink_index():
+            index_name = [n for n in os.listdir(os.path.join(self.tmppath, 'repository')) if n.startswith('index')][0]
+            idx = NSIndex(os.path.join(self.tmppath, 'repository', index_name))
+            os.unlink(os.path.join(self.tmppath, 'repository', index_name))
+            return list(idx.iteritems())
+        self.test2()
+        self.repository.close()
+        before = extract_and_unlink_index()
+        self.open()
+        self.assert_equal(before, extract_and_unlink_index())
+
     def test_consistency(self):
         """Test cache consistency
         """