1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 01:37:20 +00:00

move (r)list cmds tests to own module

This commit is contained in:
Thomas Waldmann 2022-09-12 21:55:23 +02:00
parent fcf7ca5e10
commit a07311101a
3 changed files with 136 additions and 117 deletions

View file

@ -2030,123 +2030,6 @@ def test_create_read_special_broken_symlink(self):
# output = self.cmd('foo', self.repository_location, '--old')
# self.assert_in('"--old" has been deprecated. Use "--new" instead', output)
def test_list_prefix(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test-1", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "something-else-than-test-1", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "test-2", src_dir)
output = self.cmd(f"--repo={self.repository_location}", "rlist", "--glob-archives=test-*")
self.assert_in("test-1", output)
self.assert_in("test-2", output)
self.assert_not_in("something-else", output)
def test_list_format(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", src_dir)
output_1 = self.cmd(f"--repo={self.repository_location}", "list", "test")
output_2 = self.cmd(
f"--repo={self.repository_location}",
"list",
"test",
"--format",
"{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}{NEWLINE}",
)
output_3 = self.cmd(f"--repo={self.repository_location}", "list", "test", "--format", "{mtime:%s} {path}{NL}")
self.assertEqual(output_1, output_2)
self.assertNotEqual(output_1, output_3)
def test_archives_format(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "--comment", "comment 1", "test-1", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "--comment", "comment 2", "test-2", src_dir)
output_1 = self.cmd(f"--repo={self.repository_location}", "rlist")
output_2 = self.cmd(
f"--repo={self.repository_location}", "rlist", "--format", "{archive:<36} {time} [{id}]{NL}"
)
self.assertEqual(output_1, output_2)
output_1 = self.cmd(f"--repo={self.repository_location}", "rlist", "--short")
self.assertEqual(output_1, "test-1\ntest-2\n")
output_1 = self.cmd(f"--repo={self.repository_location}", "rlist", "--format", "{barchive}/")
self.assertEqual(output_1, "test-1/test-2/")
output_3 = self.cmd(f"--repo={self.repository_location}", "rlist", "--format", "{name} {comment}{NL}")
self.assert_in("test-1 comment 1\n", output_3)
self.assert_in("test-2 comment 2\n", output_3)
def test_list_hash(self):
self.create_regular_file("empty_file", size=0)
self.create_regular_file("amb", contents=b"a" * 1000000)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
output = self.cmd(f"--repo={self.repository_location}", "list", "test", "--format", "{sha256} {path}{NL}")
assert "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0 input/amb" in output
assert "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 input/empty_file" in output
def test_list_consider_checkpoints(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test1", src_dir)
# these are not really a checkpoints, but they look like some:
self.cmd(f"--repo={self.repository_location}", "create", "test2.checkpoint", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "test3.checkpoint.1", src_dir)
output = self.cmd(f"--repo={self.repository_location}", "rlist")
assert "test1" in output
assert "test2.checkpoint" not in output
assert "test3.checkpoint.1" not in output
output = self.cmd(f"--repo={self.repository_location}", "rlist", "--consider-checkpoints")
assert "test1" in output
assert "test2.checkpoint" in output
assert "test3.checkpoint.1" in output
def test_list_chunk_counts(self):
self.create_regular_file("empty_file", size=0)
self.create_regular_file("two_chunks")
with open(os.path.join(self.input_path, "two_chunks"), "wb") as fd:
fd.write(b"abba" * 2000000)
fd.write(b"baab" * 2000000)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
output = self.cmd(
f"--repo={self.repository_location}", "list", "test", "--format", "{num_chunks} {unique_chunks} {path}{NL}"
)
assert "0 0 input/empty_file" in output
assert "2 2 input/two_chunks" in output
def test_list_size(self):
self.create_regular_file("compressible_file", size=10000)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "-C", "lz4", "test", "input")
output = self.cmd(f"--repo={self.repository_location}", "list", "test", "--format", "{size} {path}{NL}")
size, path = output.split("\n")[1].split(" ")
assert int(size) == 10000
def test_list_json(self):
self.create_regular_file("file1", size=1024 * 80)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
list_repo = json.loads(self.cmd(f"--repo={self.repository_location}", "rlist", "--json"))
repository = list_repo["repository"]
assert len(repository["id"]) == 64
checkts(repository["last_modified"])
assert list_repo["encryption"]["mode"] == RK_ENCRYPTION[13:]
assert "keyfile" not in list_repo["encryption"]
archive0 = list_repo["archives"][0]
checkts(archive0["time"])
list_archive = self.cmd(f"--repo={self.repository_location}", "list", "test", "--json-lines")
items = [json.loads(s) for s in list_archive.splitlines()]
assert len(items) == 2
file1 = items[1]
assert file1["path"] == "input/file1"
assert file1["size"] == 81920
list_archive = self.cmd(
f"--repo={self.repository_location}", "list", "test", "--json-lines", "--format={sha256}"
)
items = [json.loads(s) for s in list_archive.splitlines()]
assert len(items) == 2
file1 = items[1]
assert file1["path"] == "input/file1"
assert file1["sha256"] == "b2915eb69f260d8d3c25249195f2c8f4f716ea82ec760ae929732c0262442b2b"
def test_log_json(self):
self.create_test_files()
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)

View file

@ -0,0 +1,74 @@
import json
import os
from ...constants import * # NOQA
from . import ArchiverTestCaseBase, src_dir, RK_ENCRYPTION
class ArchiverTestCase(ArchiverTestCaseBase):
def test_list_format(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", src_dir)
output_1 = self.cmd(f"--repo={self.repository_location}", "list", "test")
output_2 = self.cmd(
f"--repo={self.repository_location}",
"list",
"test",
"--format",
"{mode} {user:6} {group:6} {size:8d} {mtime} {path}{extra}{NEWLINE}",
)
output_3 = self.cmd(f"--repo={self.repository_location}", "list", "test", "--format", "{mtime:%s} {path}{NL}")
self.assertEqual(output_1, output_2)
self.assertNotEqual(output_1, output_3)
def test_list_hash(self):
self.create_regular_file("empty_file", size=0)
self.create_regular_file("amb", contents=b"a" * 1000000)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
output = self.cmd(f"--repo={self.repository_location}", "list", "test", "--format", "{sha256} {path}{NL}")
assert "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0 input/amb" in output
assert "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 input/empty_file" in output
def test_list_chunk_counts(self):
self.create_regular_file("empty_file", size=0)
self.create_regular_file("two_chunks")
with open(os.path.join(self.input_path, "two_chunks"), "wb") as fd:
fd.write(b"abba" * 2000000)
fd.write(b"baab" * 2000000)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
output = self.cmd(
f"--repo={self.repository_location}", "list", "test", "--format", "{num_chunks} {unique_chunks} {path}{NL}"
)
assert "0 0 input/empty_file" in output
assert "2 2 input/two_chunks" in output
def test_list_size(self):
self.create_regular_file("compressible_file", size=10000)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "-C", "lz4", "test", "input")
output = self.cmd(f"--repo={self.repository_location}", "list", "test", "--format", "{size} {path}{NL}")
size, path = output.split("\n")[1].split(" ")
assert int(size) == 10000
def test_list_json(self):
self.create_regular_file("file1", size=1024 * 80)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
list_archive = self.cmd(f"--repo={self.repository_location}", "list", "test", "--json-lines")
items = [json.loads(s) for s in list_archive.splitlines()]
assert len(items) == 2
file1 = items[1]
assert file1["path"] == "input/file1"
assert file1["size"] == 81920
list_archive = self.cmd(
f"--repo={self.repository_location}", "list", "test", "--json-lines", "--format={sha256}"
)
items = [json.loads(s) for s in list_archive.splitlines()]
assert len(items) == 2
file1 = items[1]
assert file1["path"] == "input/file1"
assert file1["sha256"] == "b2915eb69f260d8d3c25249195f2c8f4f716ea82ec760ae929732c0262442b2b"

View file

@ -0,0 +1,62 @@
import json
from ...constants import * # NOQA
from . import ArchiverTestCaseBase, src_dir, RK_ENCRYPTION, checkts
class ArchiverTestCase(ArchiverTestCaseBase):
def test_rlist_glob(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test-1", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "something-else-than-test-1", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "test-2", src_dir)
output = self.cmd(f"--repo={self.repository_location}", "rlist", "--glob-archives=test-*")
self.assert_in("test-1", output)
self.assert_in("test-2", output)
self.assert_not_in("something-else", output)
def test_archives_format(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "--comment", "comment 1", "test-1", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "--comment", "comment 2", "test-2", src_dir)
output_1 = self.cmd(f"--repo={self.repository_location}", "rlist")
output_2 = self.cmd(
f"--repo={self.repository_location}", "rlist", "--format", "{archive:<36} {time} [{id}]{NL}"
)
self.assertEqual(output_1, output_2)
output_1 = self.cmd(f"--repo={self.repository_location}", "rlist", "--short")
self.assertEqual(output_1, "test-1\ntest-2\n")
output_1 = self.cmd(f"--repo={self.repository_location}", "rlist", "--format", "{barchive}/")
self.assertEqual(output_1, "test-1/test-2/")
output_3 = self.cmd(f"--repo={self.repository_location}", "rlist", "--format", "{name} {comment}{NL}")
self.assert_in("test-1 comment 1\n", output_3)
self.assert_in("test-2 comment 2\n", output_3)
def test_rlist_consider_checkpoints(self):
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test1", src_dir)
# these are not really a checkpoints, but they look like some:
self.cmd(f"--repo={self.repository_location}", "create", "test2.checkpoint", src_dir)
self.cmd(f"--repo={self.repository_location}", "create", "test3.checkpoint.1", src_dir)
output = self.cmd(f"--repo={self.repository_location}", "rlist")
assert "test1" in output
assert "test2.checkpoint" not in output
assert "test3.checkpoint.1" not in output
output = self.cmd(f"--repo={self.repository_location}", "rlist", "--consider-checkpoints")
assert "test1" in output
assert "test2.checkpoint" in output
assert "test3.checkpoint.1" in output
def test_rlist_json(self):
self.create_regular_file("file1", size=1024 * 80)
self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
list_repo = json.loads(self.cmd(f"--repo={self.repository_location}", "rlist", "--json"))
repository = list_repo["repository"]
assert len(repository["id"]) == 64
checkts(repository["last_modified"])
assert list_repo["encryption"]["mode"] == RK_ENCRYPTION[13:]
assert "keyfile" not in list_repo["encryption"]
archive0 = list_repo["archives"][0]
checkts(archive0["time"])