[PATCH 6/7] Use callback to get list of stored files in testcases

Michael Hanselmann public at hansmi.ch
Wed Aug 13 21:16:01 UTC 2008


From: Michael Hanselmann <hansmi at hansmi-mac-zrh.local>

---
 lib/Brackup/Test.pm         |   11 +++++++++--
 t/03-combine-little-files.t |   17 ++++++++++-------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/lib/Brackup/Test.pm b/lib/Brackup/Test.pm
index 9ce4564..66babdd 100644
--- a/lib/Brackup/Test.pm
+++ b/lib/Brackup/Test.pm
@@ -73,13 +73,20 @@ sub do_backup {
     ok(-e $meta_filename, "metafile exists");
     push @to_unlink, $meta_filename;
 
-    ok(eval { $backup->backup($meta_filename) }, "backup succeeded");
+    my @stored_files;
+    ok(eval {
+        $backup->backup2(backup_file => $meta_filename,
+            cb_end_file => sub {
+                my ($file, @stored_chunks) = @_;
+                push @stored_files, [$file, @stored_chunks];
+            });
+    }, "backup succeeded");
     if ($@) {
         warn "Died running backup: $@\n";
     }
     ok(-s $meta_filename, "backup file has size");
 
-    return wantarray ? ($meta_filename, $backup, $target) : $meta_filename;
+    return wantarray ? ($meta_filename, $backup, $target, @stored_files) : $meta_filename;
 }
 
 sub do_restore {
diff --git a/t/03-combine-little-files.t b/t/03-combine-little-files.t
index f655f67..5abbfa9 100644
--- a/t/03-combine-little-files.t
+++ b/t/03-combine-little-files.t
@@ -14,7 +14,7 @@ close($digdb_fh);
 my $root_dir = "$Bin/data";
 ok(-d $root_dir, "test data to backup exists");
 
-my ($backup_file, $backup) =
+my ($backup_file, $backup, undef, @stored_files) =
     do_backup(
               with_confsec => sub {
                   my $csec = shift;
@@ -27,13 +27,16 @@ my ($backup_file, $backup) =
 
 # see if dup files were only stored once
 my %seen;
-$backup->foreach_saved_file(sub {
-    my ($file, $slist) = @_;
-    return unless $file->path =~ /000-dup[12]\.txt$/;
-    foreach my $sc (@$slist) {
-        $seen{$sc->to_meta}++;
+
+foreach (@stored_files) {
+    my ($file, $slist) = @{$_};
+    if ($file->path =~ /000-dup[12]\.txt$/) {
+        foreach my $sc (@$slist) {
+            $seen{$sc->to_meta}++;
+        }
     }
-});
+}
+
 is(scalar keys %seen, 1, "stored just one uniq copy of 000-dup[12]");
 is((%seen)[-1], 2, "and stored it twice");
 like((%seen)[0], qr/-/, "and it was stored in a range");
-- 
1.5.5.3



More information about the brackup mailing list