From 37a9f49d8d14987acce139dbbcc9a1943bf7651f Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sat, 30 May 2020 13:45:23 +0200 Subject: [PATCH] more tests --- bin/zfs-autobackup | 3 ++- test_zfsautobackup.py | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/bin/zfs-autobackup b/bin/zfs-autobackup index 67fec5d..036ed81 100755 --- a/bin/zfs-autobackup +++ b/bin/zfs-autobackup @@ -1707,7 +1707,8 @@ class ZfsAutobackup: target_datasets.append(target_dataset) #ensure parents exists - if not self.args.no_send and not target_dataset.parent.exists: + #TODO: this isnt perfect yet, in some cases it can create parents when it shouldn't. + if not self.args.no_send and not target_dataset.parent in target_datasets and not target_dataset.parent.exists: target_dataset.parent.create_filesystem(parents=True) #determine common zpool features diff --git a/test_zfsautobackup.py b/test_zfsautobackup.py index b7af05d..b0a5cfe 100644 --- a/test_zfsautobackup.py +++ b/test_zfsautobackup.py @@ -5,6 +5,7 @@ class TestZfsAutobackup(unittest2.TestCase): def setUp(self): prepare_zpools() + self.longMessage=True def test_defaults(self): @@ -183,3 +184,54 @@ test_target1/test_source2/fs2/sub test_target1/test_source2/fs2/sub@test-20101111000000 """) + + def test_nosnapshot(self): + # r=shelltest("zfs snapshot test_source1/fs1@othersimple") + # r=shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") + + with patch('time.strftime', return_value="20101111000000"): + self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-snapshot".split(" ")).run()) + + r=shelltest("zfs list -H -o name -r -t all") + #(only parents are created ) + #TODO: it probably shouldn't create these + self.assertMultiLineEqual(r,""" +test_source1 +test_source1/fs1 +test_source1/fs1/sub +test_source2 +test_source2/fs2 +test_source2/fs2/sub +test_source2/fs3 +test_source2/fs3/sub +test_target1 +test_target1/test_source1 +test_target1/test_source2 +test_target1/test_source2/fs2 +""") + + + def test_nosend(self): + # r=shelltest("zfs snapshot test_source1/fs1@othersimple") + # r=shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") + + with patch('time.strftime', return_value="20101111000000"): + self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-send".split(" ")).run()) + + r=shelltest("zfs list -H -o name -r -t all") + #(only parents are created ) + #TODO: it probably shouldn't create these + self.assertMultiLineEqual(r,""" +test_source1 +test_source1/fs1 +test_source1/fs1@test-20101111000000 +test_source1/fs1/sub +test_source1/fs1/sub@test-20101111000000 +test_source2 +test_source2/fs2 +test_source2/fs2/sub +test_source2/fs2/sub@test-20101111000000 +test_source2/fs3 +test_source2/fs3/sub +test_target1 +""")