-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_borg_stack.py
More file actions
72 lines (60 loc) · 3.54 KB
/
test_borg_stack.py
File metadata and controls
72 lines (60 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import subprocess
from tempfile import mkdtemp
from unittest.case import TestCase
class BorgStackTestCase(TestCase):
def setUp(self):
self.tmdir = mkdtemp(prefix='borg_stack_test_')
self.path_to_repo = os.path.join(self.tmdir, 'repo')
subprocess.check_call(['borg', 'init', '--encryption', 'none', self.path_to_repo])
self.source_dir_relative = 'source_dir'
self.source_dir = os.path.join(self.tmdir, self.source_dir_relative)
os.mkdir(self.source_dir)
self.put_test_file('initial_content')
self.mount_point = os.path.join(self.tmdir, 'mount_point')
def put_test_file(self, content):
self.test_file_path = os.path.join(self.source_dir, 'test_file')
with open(self.test_file_path, 'w') as file:
file.write(content)
def test_create_and_list(self):
output = subprocess.check_output(['borg-stack', 'list', self.path_to_repo + '::test_stack_*']).decode()
self.assertNotIn('test_stack_1', output)
self.assertNotIn('test_stack_2', output)
self.assertNotIn('test_stack_3', output)
subprocess.check_call(['borg-stack', 'create', self.path_to_repo + '::test_stack_1*', self.source_dir])
output = subprocess.check_output(['borg-stack', 'list', self.path_to_repo + '::test_stack_*']).decode()
self.assertIn('test_stack_1', output)
self.assertNotIn('test_stack_2', output)
self.assertNotIn('test_stack_3', output)
subprocess.check_call(['borg-stack', 'create', self.path_to_repo + '::test_stack_2*', self.test_file_path])
output = subprocess.check_output(['borg-stack', 'list', self.path_to_repo + '::test_stack_*']).decode()
self.assertIn('test_stack_1', output)
self.assertIn('test_stack_2', output)
self.assertNotIn('test_stack_3', output)
subprocess.check_call(['borg-stack', 'create', self.path_to_repo + '::test_stack_3*', self.source_dir])
output = subprocess.check_output(['borg-stack', 'list', self.path_to_repo + '::test_stack_*']).decode()
self.assertIn('test_stack_1', output)
self.assertIn('test_stack_2', output)
self.assertIn('test_stack_3', output)
def test_delete(self):
subprocess.check_call(['borg-stack', 'delete', self.path_to_repo + '::test_stack_*'])
output = subprocess.check_output(['borg-stack', 'list', self.path_to_repo + '::test_stack_*']).decode()
self.assertFalse(output)
def test_mount_and_umount(self):
subprocess.check_call(
['borg-stack', 'create', self.path_to_repo + '::test_stack_1*', self.source_dir_relative],
cwd=self.tmdir,
)
subprocess.check_call(['borg-stack', 'mount', self.path_to_repo + '::test_stack_*', self.mount_point])
with open(os.path.join(self.mount_point, 'merged-repo-test_stack_/source_dir/test_file')) as file:
self.assertEqual('initial_content', file.read())
subprocess.check_call(['borg-stack', 'umount', self.mount_point])
self.put_test_file('updated_content')
subprocess.check_call(
['borg-stack', 'create', self.path_to_repo + '::test_stack_2*', self.source_dir_relative],
cwd=self.tmdir,
)
subprocess.check_call(['borg-stack', 'mount', self.path_to_repo + '::test_stack_*', self.mount_point])
with open(os.path.join(self.mount_point, 'merged-repo-test_stack_/source_dir/test_file')) as file:
self.assertEqual('updated_content', file.read())
subprocess.check_call(['borg-stack', 'umount', self.mount_point])