]> Sergey Matveev's repositories - public-inbox.git/blob - t/v1-add-remove-add.t
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / t / v1-add-remove-add.t
1 # Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use PublicInbox::MIME;
7 use PublicInbox::Import;
8 use PublicInbox::TestCommon;
9 require_mods(qw(DBD::SQLite Search::Xapian));
10 require PublicInbox::SearchIdx;
11 my ($inboxdir, $for_destroy) = tmpdir();
12 is(system(qw(git init --bare -q), $inboxdir), 0);
13 my $ibx = {
14         inboxdir => $inboxdir,
15         name => 'test-add-remove-add',
16         -primary_address => 'test@example.com',
17 };
18 $ibx = PublicInbox::Inbox->new($ibx);
19 my $mime = PublicInbox::MIME->create(
20         header => [
21                 From => 'a@example.com',
22                 To => 'test@example.com',
23                 Subject => 'this is a subject',
24                 Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
25                 'Message-ID' => '<a-mid@b>',
26         ],
27         body => "hello world\n",
28 );
29 my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
30 ok($im->add($mime), 'message added');
31 ok($im->remove($mime), 'message added');
32 ok($im->add($mime), 'message added again');
33 $im->done;
34 my $rw = PublicInbox::SearchIdx->new($ibx, 1);
35 $rw->index_sync;
36 my $msgs = $ibx->recent({limit => 10});
37 is($msgs->[0]->{mid}, 'a-mid@b', 'message exists in history');
38 is(scalar @$msgs, 1, 'only one message in history');
39 is($ibx->mm->num_for('a-mid@b'), 2, 'exists with second article number');
40
41 done_testing();