add tests related to snapshots
This commit is contained in:
+28
-1
@@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from zfs_backup import ZFSPath
|
||||
from unittest import mock
|
||||
|
||||
from zfs_backup import ZFSPath, Dataset, Snapshot
|
||||
|
||||
|
||||
class TestZFSPath:
|
||||
@@ -156,3 +158,28 @@ class TestZFSPath:
|
||||
)
|
||||
def test_replace_pool(self, instance1, instance2):
|
||||
assert instance1.replace_pool(instance2.pool_name) == instance2
|
||||
|
||||
|
||||
class TestZFS:
|
||||
@pytest.mark.parametrize("string", ["tank", "tank/ROOT", "tank/ROOT/default"])
|
||||
def test_get_snapshots(self, string):
|
||||
path = ZFSPath.from_string(string)
|
||||
ds = Dataset(path)
|
||||
for snapshot in ds.snapshots:
|
||||
assert snapshot.dataset == ds
|
||||
|
||||
|
||||
class TestDataset:
|
||||
@pytest.mark.parametrize("zfspath", ["tank", "tank/ROOT", "tank/ROOT/default"])
|
||||
def test__clean_old_snapshots_for_interval(self, zfspath):
|
||||
"""Check that only snapshots that are direct children of the dataset are found during cleanup."""
|
||||
|
||||
def validate_snapshot_selection(snapshot: Snapshot):
|
||||
print(snapshot) # show output with "pytest -s"
|
||||
str(snapshot).startswith(f"{zfspath}@")
|
||||
|
||||
dataset = Dataset(ZFSPath.from_string(zfspath))
|
||||
with mock.patch.object(
|
||||
Snapshot, "destroy", lambda snapshot: validate_snapshot_selection(snapshot)
|
||||
):
|
||||
dataset._clean_old_snapshots_for_interval("daily", 999)
|
||||
|
||||
Reference in New Issue
Block a user