Add two additional tests.

This commit is contained in:
Jonas Borgström 2013-10-10 22:24:06 +02:00
parent 9e9ece675d
commit b5b0b7b322
2 changed files with 27 additions and 0 deletions

View File

@ -63,4 +63,16 @@ class HashIndexTestCase(AtticTestCase):
idx.flush() idx.flush()
self.assert_equal(initial_size, os.path.getsize(idx_name.name)) 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))

View File

@ -1,6 +1,7 @@
import os import os
import shutil import shutil
import tempfile import tempfile
from attic.hashindex import NSIndex
from attic.helpers import Location from attic.helpers import Location
from attic.remote import RemoteRepository from attic.remote import RemoteRepository
from attic.repository import Repository from attic.repository import Repository
@ -48,6 +49,20 @@ class RepositoryTestCase(AtticTestCase):
self.repository.commit() self.repository.commit()
self.assert_equal(self.repository.get(b'00000000000000000000000000000001'), b'bar') 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): def test_consistency(self):
"""Test cache consistency """Test cache consistency
""" """