]> Sergey Matveev's repositories - public-inbox.git/blob - t/v2-add-remove-add.t
7cce249376ea1a5a320af59d0de3b38c98de4398
[public-inbox.git] / t / v2-add-remove-add.t
1 # Copyright (C) 2018-2019 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::TestCommon;
8 require_git(2.6);
9
10 foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
11         eval "require $mod";
12         plan skip_all => "$mod missing for v2-add-remove-add.t" if $@;
13 }
14 use_ok 'PublicInbox::V2Writable';
15 my ($inboxdir, $for_destroy) = tmpdir();
16 my $ibx = {
17         inboxdir => "$inboxdir/v2",
18         name => 'test-v2writable',
19         version => 2,
20         -primary_address => 'test@example.com',
21 };
22 $ibx = PublicInbox::Inbox->new($ibx);
23 my $mime = PublicInbox::MIME->create(
24         header => [
25                 From => 'a@example.com',
26                 To => 'test@example.com',
27                 Subject => 'this is a subject',
28                 Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
29                 'Message-ID' => '<a-mid@b>',
30         ],
31         body => "hello world\n",
32 );
33 my $im = PublicInbox::V2Writable->new($ibx, 1);
34 $im->{parallel} = 0;
35 ok($im->add($mime), 'message added');
36 ok($im->remove($mime), 'message added');
37 ok($im->add($mime), 'message added again');
38 $im->done;
39 my $msgs = $ibx->recent({limit => 1000});
40 is($msgs->[0]->{mid}, 'a-mid@b', 'message exists in history');
41 is(scalar @$msgs, 1, 'only one message in history');
42
43 done_testing();