Blame | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
# Test script for snapShotReport function
# This validates the report generation logic for various scenarios
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/..";
use ZFS_Utils qw(snapShotReport $verboseLoggingLevel);
# Enable verbose logging for testing
$ZFS_Utils::verboseLoggingLevel = 4;
$ZFS_Utils::displayLogsOnConsole = 0; # Suppress log output for cleaner test display
print "=" x 70 . "\n";
print "Testing snapShotReport function\n";
print "=" x 70 . "\n\n";
# Test 1: UNCHANGED - no changes between original and current
print "Test 1: UNCHANGED scenario\n";
print "-" x 70 . "\n";
my $original1 = [
'pool/data@2025-12-18',
'pool/data/child@2025-12-18',
];
my $current1 = [
'pool/data@2025-12-18',
'pool/data/child@2025-12-18',
];
my $report1 = snapShotReport('pool/data', $original1, $current1);
print "Report:\n";
foreach my $line (@$report1) {
print " $line\n";
}
print "\n";
# Test 2: ADDED - new dataset with no original
print "Test 2: ADDED scenario\n";
print "-" x 70 . "\n";
my $original2 = [];
my $current2 = [
'pool/backup@2025-12-19',
];
my $report2 = snapShotReport('pool/backup', $original2, $current2);
print "Report:\n";
foreach my $line (@$report2) {
print " $line\n";
}
print "\n";
# Test 3: Changed - snapshots added between original and current
print "Test 3: Changed scenario (snapshots added)\n";
print "-" x 70 . "\n";
my $original3 = [
'pool/data@2025-12-15',
];
my $current3 = [
'pool/data@2025-12-15',
'pool/data@2025-12-16',
'pool/data@2025-12-17',
'pool/data@2025-12-18',
];
my $report3 = snapShotReport('pool/data', $original3, $current3);
print "Report:\n";
foreach my $line (@$report3) {
print " $line\n";
}
print "\n";
# Test 4: CONSISTENT - parent and all children changed in same way
print "Test 4: CONSISTENT scenario (parent and children all changed)\n";
print "-" x 70 . "\n";
my $original4 = [
'pool/data@2025-12-15',
'pool/data/child@2025-12-15',
'pool/data/child/grandchild@2025-12-15',
];
my $current4 = [
'pool/data@2025-12-15',
'pool/data@2025-12-16',
'pool/data@2025-12-17',
'pool/data@2025-12-18',
'pool/data/child@2025-12-15',
'pool/data/child@2025-12-16',
'pool/data/child@2025-12-17',
'pool/data/child@2025-12-18',
'pool/data/child/grandchild@2025-12-15',
'pool/data/child/grandchild@2025-12-16',
'pool/data/child/grandchild@2025-12-17',
'pool/data/child/grandchild@2025-12-18',
];
my $report4 = snapShotReport('pool/data', $original4, $current4);
print "Report:\n";
foreach my $line (@$report4) {
print " $line\n";
}
print "\n";
# Test 5: Mixed - parent and children have different changes
print "Test 5: Mixed scenario (inconsistent changes)\n";
print "-" x 70 . "\n";
my $original5 = [
'pool/data@2025-12-15',
'pool/data/child@2025-12-15',
];
my $current5 = [
'pool/data@2025-12-15',
'pool/data@2025-12-16',
'pool/data@2025-12-18', # Parent has 2 new snapshots
'pool/data/child@2025-12-15',
'pool/data/child@2025-12-18', # Child has 1 new snapshot (different pattern)
];
my $report5 = snapShotReport('pool/data', $original5, $current5);
print "Report:\n";
foreach my $line (@$report5) {
print " $line\n";
}
print "\n";
# Test 6: CONSISTENT UNCHANGED - parent and all children unchanged
print "Test 6: CONSISTENT UNCHANGED scenario\n";
print "-" x 70 . "\n";
my $original6 = [
'pool/data@2025-12-18',
'pool/data/child@2025-12-18',
'pool/data/child/grandchild@2025-12-18',
];
my $current6 = [
'pool/data@2025-12-18',
'pool/data/child@2025-12-18',
'pool/data/child/grandchild@2025-12-18',
];
my $report6 = snapShotReport('pool/data', $original6, $current6);
print "Report:\n";
foreach my $line (@$report6) {
print " $line\n";
}
print "\n";
# Test 7: CONSISTENT ADDED - parent and all children are new
print "Test 7: CONSISTENT ADDED scenario\n";
print "-" x 70 . "\n";
my $original7 = [];
my $current7 = [
'pool/newdata@2025-12-19',
'pool/newdata/child@2025-12-19',
];
my $report7 = snapShotReport('pool/newdata', $original7, $current7);
print "Report:\n";
foreach my $line (@$report7) {
print " $line\n";
}
print "\n";
# Test 8: Complex with timestamps
print "Test 8: Complex scenario with timestamps\n";
print "-" x 70 . "\n";
my $original8 = [
'pool/data@2025-12-18_10:00:00',
];
my $current8 = [
'pool/data@2025-12-18_10:00:00',
'pool/data@2025-12-18_11:00:00',
'pool/data@2025-12-18_12:00:00',
'pool/data@2025-12-18_13:00:00',
'pool/data@2025-12-18_14:00:00',
'pool/data@2025-12-18_15:00:00',
];
my $report8 = snapShotReport('pool/data', $original8, $current8);
print "Report:\n";
foreach my $line (@$report8) {
print " $line\n";
}
print "\n";
print "=" x 70 . "\n";
print "All tests completed\n";
print "=" x 70 . "\n";