Subversion Repositories zfs_utils

Rev

Blame | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl

# Test that parseSnapshotDateTime can be imported from ZFS_Utils
# This verifies it's correctly exported

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/..";
use ZFS_Utils qw(parseSnapshotDateTime);

print "Testing parseSnapshotDateTime import from ZFS_Utils\n";
print "=" x 60 . "\n";

# Test that the function is available
if (defined &parseSnapshotDateTime) {
   print "✓ parseSnapshotDateTime is available after import\n";
} else {
   print "✗ FAIL: parseSnapshotDateTime not available\n";
   exit 1;
}

# Quick functional tests
print "\nTest 1: Direct date string (correct usage)\n";
my $test_snap1 = "2025-12-19_15:30:45";
my $epoch1 = parseSnapshotDateTime($test_snap1);

print "Debug: epoch = " . (defined $epoch1 ? $epoch1 : "undef") . "\n";

if (defined $epoch1 && $epoch1 > 0) {
   print "✓ Test 1 PASS: parseSnapshotDateTime('$test_snap1') = $epoch1\n";
} else {
   print "✗ FAIL: Function call did not return valid epoch\n";
   exit 1;
}

print "\nTest 2: Snapshot name with prefix (correct usage)\n";
my $test_snap2 = "daily_2025-12-19_15:30:45_backup";
my $epoch2 = parseSnapshotDateTime($test_snap2);

print "Debug: epoch = " . (defined $epoch2 ? $epoch2 : "undef") . "\n";

if (defined $epoch2 && $epoch2 > 0 && $epoch2 == $epoch1) {
   print "✓ Test 2 PASS: parseSnapshotDateTime('$test_snap2') = $epoch2 (same as test 1)\n";
} else {
   print "✗ FAIL: Function should extract date from snapshot name with prefix/suffix\n";
   exit 1;
}

print "\nTest 3: Parsing from full snapshot specification (typical usage pattern)\n";
my $full_snap = "pool/data\@2025-12-19_15:30:45";
my ($fs, $snapname) = split /\@/, $full_snap, 2;
my $epoch3 = parseSnapshotDateTime($snapname);  # Parse only the snapshot name portion

print "Debug: full=$full_snap, fs=$fs, snapname=$snapname, epoch=" . (defined $epoch3 ? $epoch3 : "undef") . "\n";

if (defined $epoch3 && $epoch3 > 0 && $epoch3 == $epoch1) {
   print "✓ Test 3 PASS: Extracted snapshot name and parsed correctly: $epoch3\n";
   print "  (This is how getLatestSnapshots uses the function)\n";
} else {
   print "✗ FAIL: Should work when split from full snapshot\n";
   exit 1;
}

print "=" x 60 . "\n";
print "SUCCESS: parseSnapshotDateTime is properly exported and functional\n";