summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2019-12-28 14:49:03 +0000
committerdakkar <dakkar@thenautilus.net>2019-12-28 14:49:03 +0000
commit62a685d57c44612bc251645ce3d48999e8a4c05e (patch)
tree08fe0ca73897fd86a134978ff80640193dc9d925
parenthalf-test for scandir (diff)
downloadMaildirIndexer-62a685d57c44612bc251645ce3d48999e8a4c05e.tar.gz
MaildirIndexer-62a685d57c44612bc251645ce3d48999e8a4c05e.tar.bz2
MaildirIndexer-62a685d57c44612bc251645ce3d48999e8a4c05e.zip
test multi-index store
-rw-r--r--t/lib/TestIndex.pm65
-rw-r--r--t/store.t63
2 files changed, 44 insertions, 24 deletions
diff --git a/t/lib/TestIndex.pm6 b/t/lib/TestIndex.pm6
index 730ee92..c0b0b03 100644
--- a/t/lib/TestIndex.pm6
+++ b/t/lib/TestIndex.pm6
@@ -4,6 +4,9 @@ use MaildirIndexer::Index;
unit class TestIndex does MaildirIndexer::Index;
has %.mails;
+has $.name = 'test index';
+has @.responses = ( 'foo' xx 10 );
+
has atomicint $!seen = 0;
has Int $.expect;
has $.seen-all;
@@ -28,5 +31,5 @@ method del-path(IO:D $path, Str:D $mailbox --> Nil) {
}
method mailbox-for-email(MaildirIndexer::Email:D $email --> Str) {
- return 'foo'
+ return @!responses.shift;
}
diff --git a/t/store.t b/t/store.t
index 73903df..3cedda3 100644
--- a/t/store.t
+++ b/t/store.t
@@ -6,28 +6,45 @@ use TestIndex;
use MaildirIndexer::Store;
use MaildirIndexer::Index;
-my Channel $file-channel .= new;
-my TestIndex $index .= new;
-my MaildirIndexer::Store $store .= new: :$file-channel, :indices($index), :2workers;
-
-$store.start();
-
-$index.set-expect(4);
-$file-channel.send("t/fixtures/$_".IO) for qw[one/cur/1 one/cur/2 two/cur/1 two/cur/2];
-await $index.seen-all;
-
-is-deeply(
- $index.mails,
- %(
- one => %( 't/fixtures/one/cur/1' => 1, 't/fixtures/one/cur/2' => 1 ),
- two => %( 't/fixtures/two/cur/1' => 1, 't/fixtures/two/cur/2' => 1 ),
- ),
- 'mails should be indexed',
-);
-
-is(
- $store.mailbox-for-email(MaildirIndexer::Email.new),'foo',
- 'index is consulted',
-);
+subtest 'indexing' => {
+ my Channel $file-channel .= new;
+ my TestIndex $index .= new;
+ my MaildirIndexer::Store $store .= new: :$file-channel, :indices($index), :2workers;
+
+ $store.start();
+
+ $index.set-expect(4);
+ $file-channel.send("t/fixtures/$_".IO) for qw[one/cur/1 one/cur/2 two/cur/1 two/cur/2];
+ await $index.seen-all;
+
+ is-deeply(
+ $index.mails,
+ %(
+ one => %( 't/fixtures/one/cur/1' => 1, 't/fixtures/one/cur/2' => 1 ),
+ two => %( 't/fixtures/two/cur/1' => 1, 't/fixtures/two/cur/2' => 1 ),
+ ),
+ 'mails should be indexed',
+ );
+}
+
+subtest 'finding' => {
+ my Channel $file-channel .= new;
+ my TestIndex $index1 .= new(:responses('1',Str,'1',Str),:name('index1'));
+ my TestIndex $index2 .= new(:responses('2',Str),:name('index2'));
+
+ my MaildirIndexer::Store $store .= new(
+ :$file-channel,
+ :indices($index1,$index2),
+ :1workers,
+ );
+
+ my @responses = $store.mailbox-for-email(MaildirIndexer::Email.new) xx 4;
+
+ is-deeply(
+ @responses,
+ $['1','2','1',Str],
+ 'indexes are consulted until a defined value',
+ );
+}
done-testing;