From 7c372cf211a88543aaf292b2199a64391e0ca6b7 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Mon, 7 Mar 2022 22:59:50 +0100 Subject: [PATCH] test check skipping --- README.md | 2 +- tests/test_zfscheck.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a9ee4d..ba3681d 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ An important feature that's missing from other tools is a reliable `--test` opti * Uses progressive thinning for older snapshots. * Uses zfs-holds on important snapshots to prevent accidental deletion. * Automatic resuming of failed transfers. -* Easy migration from existing zfs backups. +* Easy migration from other zfs backup systems to zfs-autobackup. * Gracefully handles datasets that no longer exist on source. * Complete and clean logging. * Easy installation: diff --git a/tests/test_zfscheck.py b/tests/test_zfscheck.py index 96cb97d..4f75b59 100644 --- a/tests/test_zfscheck.py +++ b/tests/test_zfscheck.py @@ -103,6 +103,40 @@ dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798 shelltest("cp tests/data/partial /tmp/testtree") shelltest("cp tests/data/whole_whole2_partial /tmp/testtree") + #################################### + with self.subTest("Generate, skip 1"): + with OutputIO() as buf: + with redirect_stdout(buf): + self.assertFalse(ZfsCheck("/tmp/testtree --skip=1".split(" "), print_arguments=False).run()) + + #since order varies, just check count (there is one empty line for some reason, only when testing like this) + print(buf.getvalue().split("\n")) + self.assertEqual(len(buf.getvalue().split("\n")),4) + + ###################################### + with self.subTest("Compare, all incorrect, skip 1"): + + # store on disk for next step, add error + with open("/tmp/testhashes", "w") as fh: + fh.write(""" +partial 0 642027d63bb0afd7e0ba197f2c66ad03e3d70deX +whole 0 3c0bf91170d873b8e327d3bafb6bc074580d11bX +whole2 0 2e863f1fcccd6642e4e28453eba10d2d3f74d79X +whole_whole2 0 959e6b58078f0cfd2fb3d37e978fda51820473fX +whole_whole2_partial 0 309ffffba2e1977d12f3b7469971f30d28b94bdX +""") + + with OutputIO() as buf: + with redirect_stdout(buf): + self.assertEqual(ZfsCheck("/tmp/testtree --check=/tmp/testhashes --skip=1".split(" "), print_arguments=False).run(), 3) + + print(buf.getvalue()) + self.assertMultiLineEqual("""partial: Chunk 0 failed: 642027d63bb0afd7e0ba197f2c66ad03e3d70deX 642027d63bb0afd7e0ba197f2c66ad03e3d70de1 +whole2: Chunk 0 failed: 2e863f1fcccd6642e4e28453eba10d2d3f74d79X 2e863f1fcccd6642e4e28453eba10d2d3f74d798 +whole_whole2_partial: Chunk 0 failed: 309ffffba2e1977d12f3b7469971f30d28b94bdX 309ffffba2e1977d12f3b7469971f30d28b94bd8 +""",buf.getvalue()) + + #################################### with self.subTest("Generate"): with OutputIO() as buf: with redirect_stdout(buf): @@ -126,6 +160,7 @@ whole_whole2_partial 0 309ffffba2e1977d12f3b7469971f30d28b94bd8 with open("/tmp/testhashes", "w") as fh: fh.write(buf.getvalue() + "whole_whole2_partial 0 309ffffba2e1977d12f3b7469971f30d28b94bdX") + #################################### with self.subTest("Compare"): with OutputIO() as buf: with redirect_stdout(buf):