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 script for snapShotReport function
4
# This validates the report generation logic for various scenarios
5
 
6
use strict;
7
use warnings;
8
use FindBin;
9
use lib "$FindBin::Bin/..";
10
use ZFS_Utils qw(snapShotReport $verboseLoggingLevel);
11
 
12
# Enable verbose logging for testing
13
$ZFS_Utils::verboseLoggingLevel = 4;
14
$ZFS_Utils::displayLogsOnConsole = 0;  # Suppress log output for cleaner test display
15
 
16
print "=" x 70 . "\n";
17
print "Testing snapShotReport function\n";
18
print "=" x 70 . "\n\n";
19
 
20
# Test 1: UNCHANGED - no changes between original and current
21
print "Test 1: UNCHANGED scenario\n";
22
print "-" x 70 . "\n";
23
my $original1 = [
24
    'pool/data@2025-12-18',
25
    'pool/data/child@2025-12-18',
26
];
27
my $current1 = [
28
    'pool/data@2025-12-18',
29
    'pool/data/child@2025-12-18',
30
];
31
my $report1 = snapShotReport('pool/data', $original1, $current1);
32
print "Report:\n";
33
foreach my $line (@$report1) {
34
    print "  $line\n";
35
}
36
print "\n";
37
 
38
# Test 2: ADDED - new dataset with no original
39
print "Test 2: ADDED scenario\n";
40
print "-" x 70 . "\n";
41
my $original2 = [];
42
my $current2 = [
43
    'pool/backup@2025-12-19',
44
];
45
my $report2 = snapShotReport('pool/backup', $original2, $current2);
46
print "Report:\n";
47
foreach my $line (@$report2) {
48
    print "  $line\n";
49
}
50
print "\n";
51
 
52
# Test 3: Changed - snapshots added between original and current
53
print "Test 3: Changed scenario (snapshots added)\n";
54
print "-" x 70 . "\n";
55
my $original3 = [
56
    'pool/data@2025-12-15',
57
];
58
my $current3 = [
59
    'pool/data@2025-12-15',
60
    'pool/data@2025-12-16',
61
    'pool/data@2025-12-17',
62
    'pool/data@2025-12-18',
63
];
64
my $report3 = snapShotReport('pool/data', $original3, $current3);
65
print "Report:\n";
66
foreach my $line (@$report3) {
67
    print "  $line\n";
68
}
69
print "\n";
70
 
71
# Test 4: CONSISTENT - parent and all children changed in same way
72
print "Test 4: CONSISTENT scenario (parent and children all changed)\n";
73
print "-" x 70 . "\n";
74
my $original4 = [
75
    'pool/data@2025-12-15',
76
    'pool/data/child@2025-12-15',
77
    'pool/data/child/grandchild@2025-12-15',
78
];
79
my $current4 = [
80
    'pool/data@2025-12-15',
81
    'pool/data@2025-12-16',
82
    'pool/data@2025-12-17',
83
    'pool/data@2025-12-18',
84
    'pool/data/child@2025-12-15',
85
    'pool/data/child@2025-12-16',
86
    'pool/data/child@2025-12-17',
87
    'pool/data/child@2025-12-18',
88
    'pool/data/child/grandchild@2025-12-15',
89
    'pool/data/child/grandchild@2025-12-16',
90
    'pool/data/child/grandchild@2025-12-17',
91
    'pool/data/child/grandchild@2025-12-18',
92
];
93
my $report4 = snapShotReport('pool/data', $original4, $current4);
94
print "Report:\n";
95
foreach my $line (@$report4) {
96
    print "  $line\n";
97
}
98
print "\n";
99
 
100
# Test 5: Mixed - parent and children have different changes
101
print "Test 5: Mixed scenario (inconsistent changes)\n";
102
print "-" x 70 . "\n";
103
my $original5 = [
104
    'pool/data@2025-12-15',
105
    'pool/data/child@2025-12-15',
106
];
107
my $current5 = [
108
    'pool/data@2025-12-15',
109
    'pool/data@2025-12-16',
110
    'pool/data@2025-12-18',  # Parent has 2 new snapshots
111
    'pool/data/child@2025-12-15',
112
    'pool/data/child@2025-12-18',  # Child has 1 new snapshot (different pattern)
113
];
114
my $report5 = snapShotReport('pool/data', $original5, $current5);
115
print "Report:\n";
116
foreach my $line (@$report5) {
117
    print "  $line\n";
118
}
119
print "\n";
120
 
121
# Test 6: CONSISTENT UNCHANGED - parent and all children unchanged
122
print "Test 6: CONSISTENT UNCHANGED scenario\n";
123
print "-" x 70 . "\n";
124
my $original6 = [
125
    'pool/data@2025-12-18',
126
    'pool/data/child@2025-12-18',
127
    'pool/data/child/grandchild@2025-12-18',
128
];
129
my $current6 = [
130
    'pool/data@2025-12-18',
131
    'pool/data/child@2025-12-18',
132
    'pool/data/child/grandchild@2025-12-18',
133
];
134
my $report6 = snapShotReport('pool/data', $original6, $current6);
135
print "Report:\n";
136
foreach my $line (@$report6) {
137
    print "  $line\n";
138
}
139
print "\n";
140
 
141
# Test 7: CONSISTENT ADDED - parent and all children are new
142
print "Test 7: CONSISTENT ADDED scenario\n";
143
print "-" x 70 . "\n";
144
my $original7 = [];
145
my $current7 = [
146
    'pool/newdata@2025-12-19',
147
    'pool/newdata/child@2025-12-19',
148
];
149
my $report7 = snapShotReport('pool/newdata', $original7, $current7);
150
print "Report:\n";
151
foreach my $line (@$report7) {
152
    print "  $line\n";
153
}
154
print "\n";
155
 
156
# Test 8: Complex with timestamps
157
print "Test 8: Complex scenario with timestamps\n";
158
print "-" x 70 . "\n";
159
my $original8 = [
160
    'pool/data@2025-12-18_10:00:00',
161
];
162
my $current8 = [
163
    'pool/data@2025-12-18_10:00:00',
164
    'pool/data@2025-12-18_11:00:00',
165
    'pool/data@2025-12-18_12:00:00',
166
    'pool/data@2025-12-18_13:00:00',
167
    'pool/data@2025-12-18_14:00:00',
168
    'pool/data@2025-12-18_15:00:00',
169
];
170
my $report8 = snapShotReport('pool/data', $original8, $current8);
171
print "Report:\n";
172
foreach my $line (@$report8) {
173
    print "  $line\n";
174
}
175
print "\n";
176
 
177
print "=" x 70 . "\n";
178
print "All tests completed\n";
179
print "=" x 70 . "\n";