From 770389156aa038dce42c4e9789ec2cde4787a304 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Mon, 21 Feb 2022 00:44:38 +0100 Subject: [PATCH] test basicas of zfscheck --- tests/basetest.py | 2 ++ tests/test_check.py | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/tests/basetest.py b/tests/basetest.py index b090e9b..461c318 100644 --- a/tests/basetest.py +++ b/tests/basetest.py @@ -12,6 +12,8 @@ import time from pprint import * from zfs_autobackup.ZfsAutobackup import * from zfs_autobackup.ZfsAutoverify import * +from zfs_autobackup.ZfsCheck import * +from zfs_autobackup.util import * from mock import * import contextlib import sys diff --git a/tests/test_check.py b/tests/test_check.py index 85b2d8b..d05870c 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -1,13 +1,14 @@ from basetest import * -from zfs_autobackup.util import * -class TestZfsEncryption(unittest2.TestCase): +class TestZfsCheck(unittest2.TestCase): def setUp(self): pass def test_blockhash(self): + #make VERY sure this works correctly under all circumstances. + # sha1 sums of files, (bs=4096) # da39a3ee5e6b4b0d3255bfef95601890afd80709 empty # 642027d63bb0afd7e0ba197f2c66ad03e3d70de1 partial @@ -61,6 +62,36 @@ class TestZfsEncryption(unittest2.TestCase): list(block_hash("tests/data/whole_whole2_partial", count=10)), [ (0, "309ffffba2e1977d12f3b7469971f30d28b94bd8"), #whole_whole2_partial - ] - ) + ]) + + + def test_volume(self): + prepare_zpools() + + shelltest("zfs create -V200M test_source1/vol") + shelltest("zfs snapshot test_source1/vol@test") + + with OutputIO() as buf: + with redirect_stdout(buf): + self.assertFalse(ZfsCheck("test_source1/vol@test".split(" "),print_arguments=False).run()) + + print(buf.getvalue()) + self.assertEqual("""0 2c2ceccb5ec5574f791d45b63c940cff20550f9a +1 2c2ceccb5ec5574f791d45b63c940cff20550f9a +""", buf.getvalue()) + + + def test_filesystem(self): + prepare_zpools() + + shelltest("cp tests/data/whole /test_source1/testfile") + shelltest("zfs snapshot test_source1@test") + + with OutputIO() as buf: + with redirect_stdout(buf): + self.assertFalse(ZfsCheck("test_source1@test".split(" "), print_arguments=False).run()) + + print(buf.getvalue()) + self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7 +""", buf.getvalue())