summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--META.json1
-rw-r--r--cpanfile1
-rw-r--r--t/02_parsing.t49
3 files changed, 51 insertions, 0 deletions
diff --git a/META.json b/META.json
index 4bcfd27..84544c4 100644
--- a/META.json
+++ b/META.json
@@ -47,6 +47,7 @@
},
"test" : {
"requires" : {
+ "Test::Differences" : "0",
"Test::Exception" : "0",
"Test::MockObject" : "0",
"Test::More" : "0.98"
diff --git a/cpanfile b/cpanfile
index b73c790..e52f40d 100644
--- a/cpanfile
+++ b/cpanfile
@@ -4,5 +4,6 @@ on 'test' => sub {
requires 'Test::More', '0.98';
requires 'Test::MockObject';
requires 'Test::Exception';
+ requires 'Test::Differences';
};
diff --git a/t/02_parsing.t b/t/02_parsing.t
new file mode 100644
index 0000000..3f1f385
--- /dev/null
+++ b/t/02_parsing.t
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::MockObject;
+use Test::Differences;
+
+use App::BorgRestore;
+
+# Only log calls to $db->add_path
+my $db = Test::MockObject->new();
+$db->set_true(qw(add_path -begin_work -commit -vacuum -add_archive_name));
+$db->mock('-get_archive_id', sub {return 'prefix-archive-1' if $_[1] eq 'archive-1';});
+$db->mock('-get_archive_names', sub {return []});
+
+my $borg = Test::MockObject->new();
+$borg->set_list('borg_list', ['archive-1']);
+$borg->mock('list_archive', sub {
+ my ($self, $archive, $cb) = @_;
+ $cb->("XXX, 1970-01-01 01:00:05 .");
+ $cb->("XXX, 1970-01-01 01:00:10 boot");
+ $cb->("XXX, 1970-01-01 01:00:20 boot/grub");
+ $cb->("XXX, 1970-01-01 01:00:08 boot/grub/grub.cfg");
+ $cb->("XXX, 1970-01-01 01:00:13 boot/foo");
+ $cb->("XXX, 1970-01-01 01:00:13 boot/foo/blub");
+ $cb->("XXX, 1970-01-01 01:00:19 boot/foo/bar");
+ } );
+
+# Call the actual function we want to test
+my $app = App::BorgRestore->new({}, {borg => $borg, db => $db});
+$app->handle_added_archives($db, ['archive-1']);
+
+# Check if $db->add_path has been called properly
+my (@calls, @a);
+push @calls, [@a] while @a = $db->next_call();
+
+# sort by path
+@calls = sort {$a->[1][2] cmp $b->[1][2];} @calls;
+
+eq_or_diff(\@calls, [
+ ['add_path', [$db, 'prefix-archive-1', 'boot', 20]],
+ ['add_path', [$db, 'prefix-archive-1', 'boot/foo', 19]],
+ ['add_path', [$db, 'prefix-archive-1', 'boot/foo/bar', 19]],
+ ['add_path', [$db, 'prefix-archive-1', 'boot/foo/blub', 13]],
+ ['add_path', [$db, 'prefix-archive-1', 'boot/grub', 20]],
+ ['add_path', [$db, 'prefix-archive-1', 'boot/grub/grub.cfg', 8]],
+ ], "Database is populated with the correct timestamps");
+
+done_testing;