user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
ea21a0fe97e0bbc9a30ad38ec2fce1d9503f5e14 blob 1491 bytes (raw)

 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
 
#!perl -w
# Copyright (C) 2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
require_mods(qw(json DBD::SQLite Search::Xapian));
use_ok 'PublicInbox::LeiXkwIdx';
use PublicInbox::Git;
my ($tmpdir, $for_destroy) = tmpdir;
my ($ro_home, $cfg_path) = setup_public_inboxes;
my $git = PublicInbox::Git->new("$ro_home/t1");
my $xkw = PublicInbox::LeiXkwIdx->new("$tmpdir/xkw", { git => $git });
my $smsg = {
	blob => '9bf1002c49eb075df47247b74d69bcd555e23422',
	kw => ['seen'],
};
my $req = { blob => $smsg->{blob} };
my $eml = eml_load('t/utf8.eml');
is_deeply([$xkw->get_xkw($eml, $smsg)], [], 'no keywords, yet');
is($xkw->{xdb}->get_doccount, 0, 'no documents created');

my @d = $xkw->set_xkw($eml, $smsg);
is(scalar(@d), 1, 'set one docid');
like($d[0], qr/\A\d+\z/, 'set a numeric docid');

is_deeply([$xkw->get_xkw($eml, $req)], ['seen'], 'got keywords back');

$smsg->{kw} = [qw(seen answered)];
is_deeply([$xkw->set_xkw($eml, $smsg)], \@d, 'updated existing doc');
is_deeply([$xkw->get_xkw($eml, $req)], [qw(answered seen)],
	'got keywords back');
undef $xkw;

$xkw = PublicInbox::LeiXkwIdx->new("$tmpdir/xkw", { git => $git });
is_deeply([$xkw->get_xkw($eml, $req)], [qw(answered seen)],
	'got keywords back after auto-commit');

is_deeply([$xkw->clear_xkw($eml, $req)], \@d, 'keywords cleared');
is_deeply([$xkw->get_xkw($eml, $req)], [], 'keywords gone');

done_testing;
debug log:

solving ea21a0fe ...
found ea21a0fe in https://public-inbox.org/meta/20210303140139.7637-1-e@80x24.org/

applying [1/1] https://public-inbox.org/meta/20210303140139.7637-1-e@80x24.org/
diff --git a/t/lei_xkw.t b/t/lei_xkw.t
new file mode 100644
index 00000000..ea21a0fe

Checking patch t/lei_xkw.t...
Applied patch t/lei_xkw.t cleanly.

index at:
100644 ea21a0fe97e0bbc9a30ad38ec2fce1d9503f5e14	t/lei_xkw.t

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).