Subversion Repositories zfs_utils

Rev

Rev 54 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 54 Rev 60
Line 136... Line 136...
136
        }
136
        }
137
    }
137
    }
138
}
138
}
139
 
139
 
140
if ($ok) {
140
if ($ok) {
141
    print "TEST PASS\n";
141
    print "TEST 1 (retention logic) PASS\n";
142
    exit 0;
-
 
143
} else {
142
} else {
144
    print "TEST FAIL\n";
143
    print "TEST 1 (retention logic) FAIL\n";
145
    exit 1;
144
    exit 1;
146
}
145
}
-
 
146
 
-
 
147
# TEST 2: Test the --unmatched flag
-
 
148
print "\n=== Testing --unmatched flag ===\n";
-
 
149
 
-
 
150
# Run cleanSnaps with --unmatched flag to remove snapshots that don't match the pattern
-
 
151
my $out_unmatched;
-
 
152
if ($ENV{PERL}) {
-
 
153
    $out_unmatched = qx{$ENV{PERL} -I. "$clean" -v -u 2>&1};
-
 
154
} else {
-
 
155
    $out_unmatched = qx{perl -I. "$clean" -v -u 2>&1};
-
 
156
}
-
 
157
 
-
 
158
print "=== cleanSnaps --unmatched output ===\n$out_unmatched\n";
-
 
159
 
-
 
160
my @lines_unmatched = split /\n/, $out_unmatched;
-
 
161
my @removed_unmatched = map { s/^\s+//; $_ } grep { /^\s+\S+@/ } @lines_unmatched;
-
 
162
 
-
 
163
my %removed_unmatched = map { $_ => 1 } @removed_unmatched;
-
 
164
 
-
 
165
# Expected: ONLY pool/fs@badname should be marked for removal (doesn't match pattern)
-
 
166
# All other snapshots that match the pattern should be SKIPPED (not removed)
-
 
167
my $ok2 = 1;
-
 
168
if ($removed_unmatched{'pool/fs@badname'}) {
-
 
169
    print "PASS: pool/fs\@badname marked for removal with --unmatched flag\n";
-
 
170
} else {
-
 
171
    print "FAIL: pool/fs\@badname should be marked for removal with --unmatched flag\n";
-
 
172
    $ok2 = 0;
-
 
173
}
-
 
174
 
-
 
175
# Verify that matched snapshots are NOT removed when --unmatched is used
-
 
176
my @matched_snaps = grep { $_ ne 'pool/fs@badname' } @snap_lines;
-
 
177
for my $snap (@matched_snaps) {
-
 
178
    next unless $snap =~ /@/;
-
 
179
    if ($removed_unmatched{$snap}) {
-
 
180
        print "FAIL: $snap should NOT be removed with --unmatched flag (only unmatched should be removed)\n";
-
 
181
        $ok2 = 0;
-
 
182
    }
-
 
183
}
-
 
184
 
-
 
185
# Count should be exactly 1 (only the unmatched snapshot)
-
 
186
my $unmatched_count = scalar(@removed_unmatched);
-
 
187
if ($unmatched_count != 1) {
-
 
188
    print "FAIL: Expected exactly 1 snapshot to be removed with --unmatched flag, got $unmatched_count\n";
-
 
189
    $ok2 = 0;
-
 
190
} else {
-
 
191
    print "PASS: Exactly 1 unmatched snapshot marked for removal (normal retention skipped)\n";
-
 
192
}
-
 
193
 
-
 
194
if ($ok2) {
-
 
195
    print "TEST 2 (--unmatched flag) PASS\n";
-
 
196
} else {
-
 
197
    print "TEST 2 (--unmatched flag) FAIL\n";
-
 
198
    exit 1;
-
 
199
}
-
 
200
 
-
 
201
# TEST 3: Test --version flag
-
 
202
print "\n=== Testing --version flag ===\n";
-
 
203
my $version_out;
-
 
204
if ($ENV{PERL}) {
-
 
205
    $version_out = qx{$ENV{PERL} -I. "$clean" --version 2>&1};
-
 
206
} else {
-
 
207
    $version_out = qx{perl -I. "$clean" --version 2>&1};
-
 
208
}
-
 
209
 
-
 
210
print "=== cleanSnaps --version output ===\n$version_out\n";
-
 
211
 
-
 
212
if ($version_out =~ /cleanSnaps version \d+\.\d+/) {
-
 
213
    print "TEST 3 (--version flag) PASS\n";
-
 
214
} else {
-
 
215
    print "TEST 3 (--version flag) FAIL\n";
-
 
216
    exit 1;
-
 
217
}
-
 
218
 
-
 
219
print "\n=== All tests PASSED ===\n";
-
 
220
exit 0;