From e688b27ef71b0b86953755d54f30bdd0edbf2c32 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 21 Oct 2016 18:17:29 +0100 Subject: FS mailstore & tests the store has also gained a ->remove method --- t/lib/Test/Sietima/MailStore.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 't/lib') diff --git a/t/lib/Test/Sietima/MailStore.pm b/t/lib/Test/Sietima/MailStore.pm index 60054c3..2925fd3 100644 --- a/t/lib/Test/Sietima/MailStore.pm +++ b/t/lib/Test/Sietima/MailStore.pm @@ -1,7 +1,8 @@ package Test::Sietima::MailStore; use Moo; use Sietima::Policy; -use List::AllUtils qw(all); +use List::AllUtils qw(all first_index); +use Digest::SHA1 qw(sha1_hex); use namespace::clean; with 'Sietima::MailStore'; @@ -14,10 +15,11 @@ has _mails => ( sub clear { shift->_mails([]) } sub store ($self,$mail,@tags) { - my $id = time(); + my $str = $mail->as_string; + my $id = sha1_hex($str); push $self->_mails->@*, { id => $id, - mail => $mail->as_string, + mail => $str, tags => { map {$_ => 1;} @tags, }, }; return $id; @@ -45,4 +47,11 @@ sub retrieve_by_id ($self,$id) { return; } +sub remove($self,$id) { + my $idx = first_index { $_->{id} eq $id } $self->_mails->@*; + return unless defined $idx; + splice $self->_mails->@*,$idx,1; + return; +} + 1; -- cgit v1.2.3