borg/dedupestore/test.py

48 lines
1.6 KiB
Python
Raw Normal View History

2010-10-16 09:45:36 +00:00
import os
import shutil
import tempfile
import unittest
from archiver import Archiver
class Test(unittest.TestCase):
def setUp(self):
self.archiver = Archiver()
self.tmpdir = tempfile.mkdtemp()
self.store_path = os.path.join(self.tmpdir, 'store')
def tearDown(self):
shutil.rmtree(self.tmpdir)
def dedupestore(self, *args, **kwargs):
exit_code = kwargs.get('exit_code', 0)
self.assertEqual(exit_code, self.archiver.run(args))
def create_src_archive(self, name):
src_dir = os.path.join(os.getcwd(), os.path.dirname(__file__))
self.dedupestore('create', self.store_path + '::' + name, src_dir)
def test_basic_functionality(self):
self.create_src_archive('test')
self.dedupestore('list', self.store_path)
self.dedupestore('list', self.store_path + '::test')
self.dedupestore('info', self.store_path + '::test')
self.dedupestore('verify', self.store_path + '::test')
dest_dir = os.path.join(self.tmpdir, 'dest')
self.dedupestore('extract', self.store_path + '::test', dest_dir)
self.dedupestore('delete', self.store_path + '::test')
def test_corrupted_store(self):
self.create_src_archive('test')
self.dedupestore('verify', self.store_path + '::test')
fd = open(os.path.join(self.tmpdir, 'store', 'bands', '0', '0'), 'r+')
2010-10-16 09:45:36 +00:00
fd.seek(1000)
fd.write('X')
fd.close()
self.dedupestore('verify', self.store_path + '::test', exit_code=1)
if __name__ == '__main__':
unittest.main()