summaryrefslogtreecommitdiff
path: root/t/store.t
blob: b29556c0c5291915172ffa596f4f0b96d3924ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!raku 
use v6.d;
use Test;
use lib 't/lib';
use TestIndex;
use MaildirIndexer::Store;
use MaildirIndexer::Index;
 
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/$_".IOfor 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(
            Mailbox.new(:name('1'),:1confidence),
            Mailbox,
            Mailbox.new(:name('1'),:confidence(0.5)),
            Mailbox
        ),
        :name('index1')
    );
    my TestIndex $index2 .= new(
        :responses(
            Mailbox.new(:name('2'),:confidence(0.5)),
            Mailbox,
            Mailbox.new(:name('2'),:1confidence),
            Mailbox
        ),
        :name('index2')
    );
 
    my MaildirIndexer::Store $store .= new(
        :$file-channel,
        :indices($index1,$index2),
        :1workers,
    );
    $store.start;
 
    my @responses = $store.mailbox-for-email(MaildirIndexer::Email.newxx 4;
 
    is-deeply(
        @responses,
        $['1',Str,'2',Str],
        'indexes are consulted, undefs ignored, highest confidence wins',
    );
}
 
done-testing;