X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=t%2Fdatabase.t;h=997d04c1a7d70d0bdd895fcb19e3940197369db0;hb=8e4a00010331fe5243c9550a7adce09e9e044a23;hp=d4edfb2662dc81e5624b72d6f44102075f0c3714;hpb=eefcd42a336641c8927b29d12c5c59443212468f;p=chaz%2Fp5-File-KDBX diff --git a/t/database.t b/t/database.t index d4edfb2..997d04c 100644 --- a/t/database.t +++ b/t/database.t @@ -9,8 +9,9 @@ use lib "$Bin/lib"; use TestCommon; use File::KDBX; +use File::Temp qw(tempfile); use Test::Deep; -use Test::More; +use Test::More 1.001004_001; use Time::Piece; subtest 'Create a new database' => sub { @@ -48,7 +49,7 @@ subtest 'Clone' => sub { my @objects = $copy->objects->each; subtest 'Cloned objects refer to the cloned database' => sub { plan tests => scalar @_; - for my $object (@objects) { + for my $object (@_) { my $object_kdbx = eval { $object->kdbx }; is $object_kdbx, $copy, 'Object: ' . $object->label; } @@ -132,7 +133,7 @@ subtest 'Recycle bin' => sub { is $kdbx->entries->size, 1, 'Database is not empty'; is $kdbx->entries(searching => 1)->size, 0, 'Database has no entries if searching'; - cmp_ok $bin->entries_deeply->size, '==', 1, 'Recycle bin has an entry'; + cmp_ok $bin->all_entries->size, '==', 1, 'Recycle bin has an entry'; $entry->recycle_or_remove; is $kdbx->entries->size, 0, 'Remove entry if it is already in the recycle bin'; @@ -170,4 +171,24 @@ subtest 'Maintenance' => sub { is $entry->custom_icon_uuid, $icon_uuid, 'Uses of removed icon change'; }; +subtest 'Dumping to filesystem' => sub { + my $kdbx = File::KDBX->new; + $kdbx->add_entry(title => 'Foo', password => 'whatever'); + + my ($fh, $filepath) = tempfile('kdbx-XXXXXX', TMPDIR => 1, UNLINK => 1); + close($fh); + + $kdbx->dump($filepath, 'a'); + + my $kdbx2 = File::KDBX->load($filepath, 'a'); + my $entry = $kdbx2->entries->map(sub { $_->title.'/'.$_->expand_password })->next; + is $entry, 'Foo/whatever', 'Dump and load an entry'; + + $kdbx->dump($filepath, key => 'a', atomic => 0); + + $kdbx2 = File::KDBX->load($filepath, 'a'); + $entry = $kdbx2->entries->map(sub { $_->title.'/'.$_->expand_password })->next; + is $entry, 'Foo/whatever', 'Dump and load an entry (non-atomic)'; +}; + done_testing;