File: action_list_test.py

package info (click to toggle)
rdiff-backup 2.2.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,640 kB
  • sloc: python: 24,129; javascript: 9,512; sh: 1,230; ansic: 580; makefile: 36
file content (174 lines) | stat: -rw-r--r-- 5,693 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""
Test the list action with api version >= 201
"""
import os
import unittest

import commontest as comtst
import fileset


class ActionListTest(unittest.TestCase):
    """
    Test that rdiff-backup properly lists files and increments
    """

    def setUp(self):
        self.base_dir = os.path.join(comtst.abs_test_dir, b"action_list")
        self.from1_struct = {
            "from1": {"contents": {
                "fileChanged": {"content": "initial"},
                "fileOld": {},
                "fileUnchanged": {"content": "unchanged"},
            }}
        }
        self.from1_path = os.path.join(self.base_dir, b"from1")
        self.from2_struct = {
            "from2": {"contents": {
                "fileChanged": {"content": "modified"},
                "fileNew": {},
                "fileUnchanged": {"content": "unchanged"},
            }}
        }
        self.from2_path = os.path.join(self.base_dir, b"from2")
        fileset.create_fileset(self.base_dir, self.from1_struct)
        fileset.create_fileset(self.base_dir, self.from2_struct)
        fileset.remove_fileset(self.base_dir, {"bak": {"type": "dir"}})
        self.bak_path = os.path.join(self.base_dir, b"bak")
        self.success = False
        # we backup twice to the same backup repository at different times
        comtst.rdiff_backup_action(
            True, True, self.from1_path, self.bak_path,
            ("--api-version", "201", "--current-time", "111111"),
            b"backup", ())
        comtst.rdiff_backup_action(
            True, True, self.from2_path, self.bak_path,
            ("--api-version", "201", "--current-time", "222222"),
            b"backup", ())

    def test_action_listfilesattime(self):
        """test the list files at time action"""
        # we list the files at different times
        self.assertEqual(comtst.rdiff_backup_action(
            False, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files",), return_stdout=True),
            b""".
fileChanged
fileNew
fileUnchanged
""")
        self.assertEqual(comtst.rdiff_backup_action(
            True, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files", "--at", "111111"), return_stdout=True),
            b""".
fileChanged
fileOld
fileUnchanged
""")
        self.assertEqual(comtst.rdiff_backup_action(
            True, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files", "--at", "15000"), return_stdout=True),
            b""".
fileChanged
fileOld
fileUnchanged
""")
        self.assertEqual(comtst.rdiff_backup_action(
            True, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files", "--at", "1B"), return_stdout=True),
            b""".
fileChanged
fileOld
fileUnchanged
""")

        # all tests were successful
        self.success = True

    def test_action_listfileschangedsince(self):
        """test the list files at time action"""
        # we list the files at different times
        self.assertEqual(comtst.rdiff_backup_action(
            False, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files", "--changed-since", "now"), return_stdout=True),
            b"""""")
        self.assertEqual(comtst.rdiff_backup_action(
            True, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files", "--changed-since", "111111"), return_stdout=True),
            b"""changed fileChanged
new     fileNew
deleted fileOld
""")
        self.assertEqual(comtst.rdiff_backup_action(
            True, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files", "--changed-since", "15000"), return_stdout=True),
            b"""changed fileChanged
new     fileNew
deleted fileOld
""")
        self.assertEqual(comtst.rdiff_backup_action(
            True, None, self.bak_path, None,
            ("--api-version", "201"),
            b"list", ("files", "--changed-since", "1B"), return_stdout=True),
            b"""changed fileChanged
new     fileNew
deleted fileOld
""")

        # all tests were successful
        self.success = True

    def test_action_listincrements(self):
        """test the list increments action, without and with size"""
        # we need to use a regex for different timezones
        self.assertRegex(comtst.rdiff_backup_action(
            False, None, self.bak_path, None,
            ("--api-version", "201", "--parsable"),
            b"list", ("increments", ), return_stdout=True),
            b"""---
- base: increments.1970-01-0[12]T[0-9][0-9][:-][25]1[:-]51.*.dir
  time: 111111
  type: directory
- base: bak
  time: 222222
  type: directory
...

""")
        # we need to use a regex for different filesystem types
        # especially directories can have any kind of size
        self.assertRegex(comtst.rdiff_backup_action(
            False, None, self.bak_path, None,
            ("--api-version", "201", "--parsable"),
            b"list", ("increments", "--size"), return_stdout=True),
            b"""---
- size: [0-9]+
  time: 111111
  total_size: [0-9]+
- size: [0-9]+
  time: 222222
  total_size: [0-9]+
...

""")

        # all tests were successful
        self.success = True

    def tearDown(self):
        # we clean-up only if the test was successful
        if self.success:
            fileset.remove_fileset(self.base_dir, self.from1_struct)
            fileset.remove_fileset(self.base_dir, self.from2_struct)
            fileset.remove_fileset(self.base_dir, {"bak": {"type": "dir"}})


if __name__ == "__main__":
    unittest.main()