From 428e6edc1349bf0e629b9581c36e159ea1ff5c05 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Tue, 4 Apr 2023 16:10:58 +0200 Subject: [PATCH] fix some tests --- tests/test_sendrecvpipes.py | 117 +++++++++++++++++++++++++++--------- tests/test_zfsnode.py | 4 +- 2 files changed, 91 insertions(+), 30 deletions(-) diff --git a/tests/test_sendrecvpipes.py b/tests/test_sendrecvpipes.py index 48e2a07..c4f4ed5 100644 --- a/tests/test_sendrecvpipes.py +++ b/tests/test_sendrecvpipes.py @@ -2,87 +2,146 @@ import zfs_autobackup.compressors from basetest import * import time + class TestSendRecvPipes(unittest2.TestCase): """test input/output pipes for zfs send and recv""" def setUp(self): prepare_zpools() - self.longMessage=True - - + self.longMessage = True def test_send_basics(self): """send basics (remote/local send pipe)""" - with self.subTest("local local pipe"): with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("remote local pipe"): - with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) + with patch('time.strftime', return_value="test-20101111000001"): + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--ssh-source=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("local remote pipe"): - with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-target=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) + with patch('time.strftime', return_value="test-20101111000002"): + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--ssh-target=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("remote remote pipe"): - with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--ssh-target=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) + with patch('time.strftime', return_value="test-20101111000003"): + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--ssh-source=localhost", "--ssh-target=localhost", "--send-pipe=dd bs=1M", + "--recv-pipe=dd bs=2M"]).run()) + + r = shelltest("zfs list -H -o name -r -t all test_target1") + self.assertMultiLineEqual(r, """ +test_target1 +test_target1/test_source1 +test_target1/test_source1/fs1 +test_target1/test_source1/fs1@test-20101111000000 +test_target1/test_source1/fs1@test-20101111000001 +test_target1/test_source1/fs1@test-20101111000002 +test_target1/test_source1/fs1@test-20101111000003 +test_target1/test_source1/fs1/sub +test_target1/test_source1/fs1/sub@test-20101111000000 +test_target1/test_source1/fs1/sub@test-20101111000001 +test_target1/test_source1/fs1/sub@test-20101111000002 +test_target1/test_source1/fs1/sub@test-20101111000003 +test_target1/test_source2 +test_target1/test_source2/fs2 +test_target1/test_source2/fs2/sub +test_target1/test_source2/fs2/sub@test-20101111000000 +test_target1/test_source2/fs2/sub@test-20101111000001 +test_target1/test_source2/fs2/sub@test-20101111000002 +test_target1/test_source2/fs2/sub@test-20101111000003 +""") def test_compress(self): """send basics (remote/local send pipe)""" for compress in zfs_autobackup.compressors.COMPRESS_CMDS.keys(): - - with self.subTest("compress "+compress): + with self.subTest("compress " + compress): with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--compress="+compress]).run()) + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--verbose", + "--compress=" + compress]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") def test_buffer(self): """test different buffer configurations""" - with self.subTest("local local pipe"): with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--buffer=1M" ]).run()) + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--buffer=1M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("remote local pipe"): - with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--buffer=1M"]).run()) + with patch('time.strftime', return_value="test-20101111000001"): + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--verbose", "--exclude-received", "--no-holds", + "--no-progress", "--ssh-source=localhost", "--buffer=1M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("local remote pipe"): - with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-target=localhost", "--buffer=1M"]).run()) + with patch('time.strftime', return_value="test-20101111000002"): + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--ssh-target=localhost", "--buffer=1M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("remote remote pipe"): - with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--ssh-target=localhost", "--buffer=1M"]).run()) + with patch('time.strftime', return_value="test-20101111000003"): + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--ssh-source=localhost", "--ssh-target=localhost", "--buffer=1M"]).run()) + + r = shelltest("zfs list -H -o name -r -t all test_target1") + self.assertMultiLineEqual(r, """ +test_target1 +test_target1/test_source1 +test_target1/test_source1/fs1 +test_target1/test_source1/fs1@test-20101111000000 +test_target1/test_source1/fs1@test-20101111000001 +test_target1/test_source1/fs1@test-20101111000002 +test_target1/test_source1/fs1@test-20101111000003 +test_target1/test_source1/fs1/sub +test_target1/test_source1/fs1/sub@test-20101111000000 +test_target1/test_source1/fs1/sub@test-20101111000001 +test_target1/test_source1/fs1/sub@test-20101111000002 +test_target1/test_source1/fs1/sub@test-20101111000003 +test_target1/test_source2 +test_target1/test_source2/fs2 +test_target1/test_source2/fs2/sub +test_target1/test_source2/fs2/sub@test-20101111000000 +test_target1/test_source2/fs2/sub@test-20101111000001 +test_target1/test_source2/fs2/sub@test-20101111000002 +test_target1/test_source2/fs2/sub@test-20101111000003 +""") def test_rate(self): """test rate limit""" - - start=time.time() + start = time.time() with patch('time.strftime', return_value="test-20101111000000"): - self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--rate=50k" ]).run()) - - #not a great way of verifying but it works. - self.assertGreater(time.time()-start, 5) - + self.assertFalse(ZfsAutobackup( + ["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--rate=50k"]).run()) + # not a great way of verifying but it works. + self.assertGreater(time.time() - start, 5) diff --git a/tests/test_zfsnode.py b/tests/test_zfsnode.py index f32216b..813abd4 100644 --- a/tests/test_zfsnode.py +++ b/tests/test_zfsnode.py @@ -166,7 +166,9 @@ test_target1 logger = LogStub() description = "[Source]" node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) - s = pformat(node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=1)) + (selected_datasets, excluded_datasets)=node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, + exclude_unchanged=1) + s = pformat(selected_datasets) print(s) # basics