more testing

This commit is contained in:
Edwin Eefting 2020-05-14 18:47:29 +02:00
parent b22113aad4
commit bc17825582
3 changed files with 67 additions and 5 deletions

@ -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...")

@ -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

@ -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):