From a6ef292ee6aca67cef76ebcee0d6bca19698ff39 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 6 Sep 2018 12:31:20 +0200 Subject: Add handle_added_archives db test Signed-off-by: Florian Pritz --- t/handle_added_archives_with_db.t | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 t/handle_added_archives_with_db.t diff --git a/t/handle_added_archives_with_db.t b/t/handle_added_archives_with_db.t new file mode 100644 index 0000000..e0c44ce --- /dev/null +++ b/t/handle_added_archives_with_db.t @@ -0,0 +1,42 @@ +use strict; +use warnings; + +use POSIX qw(tzset); +use Test::Differences; +use Test::MockObject; +use Test::More; + +use App::BorgRestore; + +my $db = App::BorgRestore::DB->new(":memory:", 0); + +$ENV{TZ} = 'UTC'; +tzset; + +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 00:00:05 ."); + $cb->("XXX, 1970-01-01 00:00:10 boot"); + $cb->("XXX, 1970-01-01 00:00:20 boot/grub"); + $cb->("XXX, 1970-01-01 00:00:08 boot/grub/grub.cfg"); + $cb->("XXX, 1970-01-01 00:00:13 boot/foo"); + $cb->("XXX, 1970-01-01 00:00:13 boot/foo/blub"); + $cb->("XXX, 1970-01-01 00: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(['archive-1']); + +# check database content +eq_or_diff($db->get_archives_for_path('boot'), [{archive => 'archive-1', modification_time => 20},]); +eq_or_diff($db->get_archives_for_path('boot/foo'), [{archive => 'archive-1', modification_time => 19},]); +eq_or_diff($db->get_archives_for_path('boot/foo/bar'), [{archive => 'archive-1', modification_time => 19},]); +eq_or_diff($db->get_archives_for_path('boot/foo/blub'), [{archive => 'archive-1', modification_time => 13},]); +eq_or_diff($db->get_archives_for_path('boot/grub'), [{archive => 'archive-1', modification_time => 20},]); +eq_or_diff($db->get_archives_for_path('boot/grub/grub.cfg'), [{archive => 'archive-1', modification_time => 8},]); + + +done_testing; -- cgit v1.2.3-24-g4f1b