Blame | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/..";
use ZFS_Utils qw(getLatestSnapshots $verboseLoggingLevel);
# Set verbosity for detailed output
$verboseLoggingLevel = 4;
print "=" x 60 . "\n";
print "Testing getLatestSnapshots function\n";
print "=" x 60 . "\n\n";
# Test data: snapshots with various date formats
my @test_snapshots = (
'pool/data@2025-01-01',
'pool/data@2025-06-15',
'pool/data@2025-12-18',
'pool/data@2025-03-10',
'pool/data/child@2025-02-01',
'pool/data/child@2025-12-01',
'pool/data/child@2025-08-15',
'pool/data/child/grandchild@2025-11-01',
'pool/data/child/grandchild@2025-12-17',
'pool/data/other@2025-12-01_10:30:00',
'pool/data/other@2025-12-01_15:45:30',
'pool/data/other@2025-12-01_08:00:00',
'pool/backup@prefix_2025-01-01_suffix',
'pool/backup@prefix_2025-12-18_suffix',
'pool/backup@no_date_here', # Should be skipped
);
print "Input snapshots (" . scalar(@test_snapshots) . "):\n";
foreach my $snap (@test_snapshots) {
print " $snap\n";
}
print "\n";
print "Calling getLatestSnapshots...\n";
print "-" x 60 . "\n";
my $result = getLatestSnapshots(\@test_snapshots);
print "-" x 60 . "\n\n";
print "Latest snapshots per filesystem (" . scalar(@$result) . "):\n";
foreach my $snap (sort @$result) {
print " $snap\n";
}
print "\n";
# Verify results
my %expected = (
'pool/data' => 'pool/data@2025-12-18',
'pool/data/child' => 'pool/data/child@2025-12-01',
'pool/data/child/grandchild' => 'pool/data/child/grandchild@2025-12-17',
'pool/data/other' => 'pool/data/other@2025-12-01_15:45:30',
'pool/backup' => 'pool/backup@prefix_2025-12-18_suffix',
);
print "Validation:\n";
my $all_pass = 1;
my %found;
foreach my $snap (@$result) {
my ($fs) = split /@/, $snap;
$found{$fs} = $snap;
}
foreach my $fs (sort keys %expected) {
if ($found{$fs} eq $expected{$fs}) {
print " ✓ PASS: $fs -> $found{$fs}\n";
} else {
print " ✗ FAIL: $fs -> expected '$expected{$fs}', got '$found{$fs}'\n";
$all_pass = 0;
}
}
# Check that we didn't get unexpected filesystems
foreach my $fs (sort keys %found) {
unless (exists $expected{$fs}) {
print " ⚠ UNEXPECTED: $fs -> $found{$fs}\n";
$all_pass = 0;
}
}
print "\n";
print "=" x 60 . "\n";
if ($all_pass) {
print "ALL TESTS PASSED\n";
exit 0;
} else {
print "SOME TESTS FAILED\n";
exit 1;
}
print "=" x 60 . "\n";