diff --git a/basetest.py b/basetest.py index 4c86344..779c9ee 100644 --- a/basetest.py +++ b/basetest.py @@ -9,6 +9,15 @@ from pprint import * from bin.zfs_autobackup import * +def shelltest(cmd): + """execute and print result as nice copypastable string for unit tests (adds extra newlines on top/bottom)""" + ret=(subprocess.check_output(cmd , shell=True).decode('utf-8')) + print("######### result of: {}".format(cmd)) + print(ret,end='') + print("#########") + ret='\n'+ret + return(ret) + def prepare_zpools(): print("Preparing zfs filesystems...") diff --git a/run_tests b/run_tests index 71a77a5..701aabf 100755 --- a/run_tests +++ b/run_tests @@ -1,3 +1,6 @@ #!/bin/bash -coverage run --source bin.zfs_autobackup -m unittest -v $@; coverage report +coverage run --source bin.zfs_autobackup -m unittest -v $@ + +echo +coverage report diff --git a/test_zfsnode.py b/test_zfsnode.py index 9f1adee..a91d95c 100644 --- a/test_zfsnode.py +++ b/test_zfsnode.py @@ -13,13 +13,63 @@ class TestZfsNode(unittest.TestCase): description="[Source]" node=ZfsNode("test", logger, description=description) - with self.subTest("### no changes, no snapshot"): - node.consistent_snapshot(node.selected_datasets, "snap1", 100000) - s=pformat(subprocess.check_call("zfs list -r -t all" , shell=True)) - print(s) + with self.subTest("first snapshot"): + node.consistent_snapshot(node.selected_datasets, "test-1",100000) + r=shelltest("zfs list -H -o name -r -t all") + self.assertEqual(r,""" +test_source1 +test_source1/fs1 +test_source1/fs1@test-1 +test_source1/fs1/sub +test_source1/fs1/sub@test-1 +test_source2 +test_source2/fs2 +test_source2/fs2/sub +test_source2/fs2/sub@test-1 +test_source2/fs3 +test_source2/fs3/sub +test_target1 +""") + with self.subTest("second snapshot, no changes, no snapshot"): + node.consistent_snapshot(node.selected_datasets, "test-2",100000) + r=shelltest("zfs list -H -o name -r -t all") + self.assertEqual(r,""" +test_source1 +test_source1/fs1 +test_source1/fs1@test-1 +test_source1/fs1/sub +test_source1/fs1/sub@test-1 +test_source2 +test_source2/fs2 +test_source2/fs2/sub +test_source2/fs2/sub@test-1 +test_source2/fs3 +test_source2/fs3/sub +test_target1 +""") + with self.subTest("second snapshot, no changes, empty snapshot"): + node.consistent_snapshot(node.selected_datasets, "test-2",0) + r=shelltest("zfs list -H -o name -r -t all") + self.assertEqual(r,""" +test_source1 +test_source1/fs1 +test_source1/fs1@test-1 +test_source1/fs1@test-2 +test_source1/fs1/sub +test_source1/fs1/sub@test-1 +test_source1/fs1/sub@test-2 +test_source2 +test_source2/fs2 +test_source2/fs2/sub +test_source2/fs2/sub@test-1 +test_source2/fs2/sub@test-2 +test_source2/fs3 +test_source2/fs3/sub +test_target1 +""") def test_getselected(self):