Subversion Repositories zfs_utils

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
64 rodolico 1
#!/usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
use FindBin;
6
use lib "$FindBin::Bin/..";
7
use ZFS_Utils qw(getLatestSnapshots $verboseLoggingLevel);
8
 
9
# Set verbosity for detailed output
10
$verboseLoggingLevel = 4;
11
 
12
print "=" x 60 . "\n";
13
print "Testing getLatestSnapshots function\n";
14
print "=" x 60 . "\n\n";
15
 
16
# Test data: snapshots with various date formats
17
my @test_snapshots = (
18
    'pool/data@2025-01-01',
19
    'pool/data@2025-06-15',
20
    'pool/data@2025-12-18',
21
    'pool/data@2025-03-10',
22
    'pool/data/child@2025-02-01',
23
    'pool/data/child@2025-12-01',
24
    'pool/data/child@2025-08-15',
25
    'pool/data/child/grandchild@2025-11-01',
26
    'pool/data/child/grandchild@2025-12-17',
27
    'pool/data/other@2025-12-01_10:30:00',
28
    'pool/data/other@2025-12-01_15:45:30',
29
    'pool/data/other@2025-12-01_08:00:00',
30
    'pool/backup@prefix_2025-01-01_suffix',
31
    'pool/backup@prefix_2025-12-18_suffix',
32
    'pool/backup@no_date_here',  # Should be skipped
33
);
34
 
35
print "Input snapshots (" . scalar(@test_snapshots) . "):\n";
36
foreach my $snap (@test_snapshots) {
37
    print "  $snap\n";
38
}
39
print "\n";
40
 
41
print "Calling getLatestSnapshots...\n";
42
print "-" x 60 . "\n";
43
my $result = getLatestSnapshots(\@test_snapshots);
44
print "-" x 60 . "\n\n";
45
 
46
print "Latest snapshots per filesystem (" . scalar(@$result) . "):\n";
47
foreach my $snap (sort @$result) {
48
    print "  $snap\n";
49
}
50
print "\n";
51
 
52
# Verify results
53
my %expected = (
54
    'pool/data' => 'pool/data@2025-12-18',
55
    'pool/data/child' => 'pool/data/child@2025-12-01',
56
    'pool/data/child/grandchild' => 'pool/data/child/grandchild@2025-12-17',
57
    'pool/data/other' => 'pool/data/other@2025-12-01_15:45:30',
58
    'pool/backup' => 'pool/backup@prefix_2025-12-18_suffix',
59
);
60
 
61
print "Validation:\n";
62
my $all_pass = 1;
63
my %found;
64
 
65
foreach my $snap (@$result) {
66
    my ($fs) = split /@/, $snap;
67
    $found{$fs} = $snap;
68
}
69
 
70
foreach my $fs (sort keys %expected) {
71
    if ($found{$fs} eq $expected{$fs}) {
72
        print "  ✓ PASS: $fs -> $found{$fs}\n";
73
    } else {
74
        print "  ✗ FAIL: $fs -> expected '$expected{$fs}', got '$found{$fs}'\n";
75
        $all_pass = 0;
76
    }
77
}
78
 
79
# Check that we didn't get unexpected filesystems
80
foreach my $fs (sort keys %found) {
81
    unless (exists $expected{$fs}) {
82
        print "  ⚠ UNEXPECTED: $fs -> $found{$fs}\n";
83
        $all_pass = 0;
84
    }
85
}
86
 
87
print "\n";
88
print "=" x 60 . "\n";
89
if ($all_pass) {
90
    print "ALL TESTS PASSED\n";
91
    exit 0;
92
} else {
93
    print "SOME TESTS FAILED\n";
94
    exit 1;
95
}
96
print "=" x 60 . "\n";