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
# Test that parseSnapshotDateTime can be imported from ZFS_Utils
4
# This verifies it's correctly exported
5
 
6
use strict;
7
use warnings;
8
use FindBin;
9
use lib "$FindBin::Bin/..";
10
use ZFS_Utils qw(parseSnapshotDateTime);
11
 
12
print "Testing parseSnapshotDateTime import from ZFS_Utils\n";
13
print "=" x 60 . "\n";
14
 
15
# Test that the function is available
16
if (defined &parseSnapshotDateTime) {
17
   print "✓ parseSnapshotDateTime is available after import\n";
18
} else {
19
   print "✗ FAIL: parseSnapshotDateTime not available\n";
20
   exit 1;
21
}
22
 
23
# Quick functional tests
24
print "\nTest 1: Direct date string (correct usage)\n";
25
my $test_snap1 = "2025-12-19_15:30:45";
26
my $epoch1 = parseSnapshotDateTime($test_snap1);
27
 
28
print "Debug: epoch = " . (defined $epoch1 ? $epoch1 : "undef") . "\n";
29
 
30
if (defined $epoch1 && $epoch1 > 0) {
31
   print "✓ Test 1 PASS: parseSnapshotDateTime('$test_snap1') = $epoch1\n";
32
} else {
33
   print "✗ FAIL: Function call did not return valid epoch\n";
34
   exit 1;
35
}
36
 
37
print "\nTest 2: Snapshot name with prefix (correct usage)\n";
38
my $test_snap2 = "daily_2025-12-19_15:30:45_backup";
39
my $epoch2 = parseSnapshotDateTime($test_snap2);
40
 
41
print "Debug: epoch = " . (defined $epoch2 ? $epoch2 : "undef") . "\n";
42
 
43
if (defined $epoch2 && $epoch2 > 0 && $epoch2 == $epoch1) {
44
   print "✓ Test 2 PASS: parseSnapshotDateTime('$test_snap2') = $epoch2 (same as test 1)\n";
45
} else {
46
   print "✗ FAIL: Function should extract date from snapshot name with prefix/suffix\n";
47
   exit 1;
48
}
49
 
50
print "\nTest 3: Parsing from full snapshot specification (typical usage pattern)\n";
51
my $full_snap = "pool/data\@2025-12-19_15:30:45";
52
my ($fs, $snapname) = split /\@/, $full_snap, 2;
53
my $epoch3 = parseSnapshotDateTime($snapname);  # Parse only the snapshot name portion
54
 
55
print "Debug: full=$full_snap, fs=$fs, snapname=$snapname, epoch=" . (defined $epoch3 ? $epoch3 : "undef") . "\n";
56
 
57
if (defined $epoch3 && $epoch3 > 0 && $epoch3 == $epoch1) {
58
   print "✓ Test 3 PASS: Extracted snapshot name and parsed correctly: $epoch3\n";
59
   print "  (This is how getLatestSnapshots uses the function)\n";
60
} else {
61
   print "✗ FAIL: Should work when split from full snapshot\n";
62
   exit 1;
63
}
64
 
65
print "=" x 60 . "\n";
66
print "SUCCESS: parseSnapshotDateTime is properly exported and functional\n";