diff options
author | dakkar <dakkar@thenautilus.net> | 2016-10-21 18:17:29 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2016-10-21 18:25:44 +0100 |
commit | e688b27ef71b0b86953755d54f30bdd0edbf2c32 (patch) | |
tree | 4e4b834eefd1bdef40f9d249effe1c0494e13fb8 /t/tests | |
parent | fix test library for newer Test2::Compare (diff) | |
download | Sietima-e688b27ef71b0b86953755d54f30bdd0edbf2c32.tar.gz Sietima-e688b27ef71b0b86953755d54f30bdd0edbf2c32.tar.bz2 Sietima-e688b27ef71b0b86953755d54f30bdd0edbf2c32.zip |
FS mailstore & tests
the store has also gained a ->remove method
Diffstat (limited to 't/tests')
-rw-r--r-- | t/tests/sietima/mailstore.t | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/t/tests/sietima/mailstore.t b/t/tests/sietima/mailstore.t new file mode 100644 index 0000000..2c2c74a --- /dev/null +++ b/t/tests/sietima/mailstore.t @@ -0,0 +1,117 @@ +#!perl +use lib 't/lib'; +use Test::Sietima; +use Email::Stuffer; +use Path::Tiny; + +sub mkmail($id) { + Email::Stuffer + ->from("from-${id}\@example.com") + ->to("to-${id}\@example.com") + ->subject("subject $id") + ->text_body("body $id \nbody body\n") + ->email; +} + +sub chkmail($id) { + object { + call [header=>'from'] => "from-${id}\@example.com"; + call [header=>'to'] => "to-${id}\@example.com"; + call [header=>'subject'] => "subject $id"; + call body => match qr{\bbody \Q$id\E\b}; + }; +} + +sub chk_multimail(@ids) { + return bag { + for my $id (@ids) { + item hash { + field id => D(); + field mail => chkmail($id); + end; + }; + } + end; + }; +} + +sub test_store($store) { + my %stored_id; + + subtest 'storing' => sub { + ok($stored_id{1}=$store->store(mkmail(1),'tag1','tag2')); + ok($stored_id{2}=$store->store(mkmail(2),'tag2')); + ok($stored_id{3}=$store->store(mkmail(3),'tag1')); + }; + + subtest 'retrieving by id' => sub { + is( + $store->retrieve_by_id($stored_id{$_}), + chkmail($_), + ) for 1..3; + }; + + subtest 'retrieving by tag' => sub { + my $tag1 = $store->retrieve_by_tags('tag1'); + is( + $tag1, + chk_multimail(1,3), + 'tag1 should have mails 1 & 3', + ); + + my $tag2 = $store->retrieve_by_tags('tag2'); + is( + $tag2, + chk_multimail(1,2), + 'tag1 should have mails 1 & 2', + ); + + my $tag12 = $store->retrieve_by_tags('tag2','tag1'); + is( + $tag12, + chk_multimail(1), + 'tag1+tag2 should have mail 1', + ); + + my $tag_all = $store->retrieve_by_tags(); + is( + $tag_all, + chk_multimail(1,2,3), + 'no tags should retrieve all mails', + ); + }; + + subtest 'removing' => sub { + $store->remove($stored_id{2}); + is( + $store->retrieve_by_tags('tag2'), + chk_multimail(1), + 'remove should remove', + ); + }; + + subtest 'clearing' => sub { + $store->clear; + is( + $store->retrieve_by_tags(), + [], + 'clear should clear', + ); + }; +} + +subtest 'test store' => sub { + require Test::Sietima::MailStore; + + test_store(Test::Sietima::MailStore->new); +}; + +subtest 'file store' => sub { + require Sietima::MailStore::FS; + + my $root = Path::Tiny->tempdir; + + test_store(Test::Sietima::MailStore->new({root => $root})); +}; + +done_testing; |