2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
5 use PublicInbox::Config;
6 use PublicInbox::Spawn qw(spawn);
7 require_cmd('sqlite3');
8 require_mods(qw(DBD::SQLite HTTP::Request::Common Plack::Test URI::Escape
9 Plack::Builder IO::Uncompress::Gunzip));
10 use_ok($_) for qw(Plack::Test HTTP::Request::Common);
11 require_ok 'PublicInbox::Msgmap';
12 require_ok 'PublicInbox::AltId';
13 require_ok 'PublicInbox::WWW';
14 my ($tmpdir, $for_destroy) = tmpdir();
17 my $ibx = create_inbox 'test', indexlevel => 'basic', sub {
19 $im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
21 Message-Id: <a@example.com>
25 my $spec = "serial:$aid:file=blah.sqlite3";
26 my $altid = PublicInbox::AltId->new($ibx, $spec, 1);
27 $altid->mm_alt->mid_set(1, 'a@example.com');
28 $cfgpath = "$ibx->{inboxdir}/cfg";
29 open my $fh, '>', $cfgpath or BAIL_OUT "open $cfgpath: $!";
30 print $fh <<EOF or BAIL_OUT $!;
32 inboxdir = $ibx->{inboxdir}
33 address = $ibx->{-primary_address}
35 url = http://example.com/test
37 close $fh or BAIL_OUT $!;
39 $cfgpath //= "$ibx->{inboxdir}/cfg";
40 my $cfg = PublicInbox::Config->new($cfgpath);
41 my $www = PublicInbox::WWW->new($cfg);
42 my $cmpfile = "$tmpdir/cmp.sqlite3";
45 my $res = $cb->(POST("/test/$aid.sql.gz"));
46 is($res->code, 200, 'retrieved gzipped dump');
47 IO::Uncompress::Gunzip::gunzip(\($res->content) => \(my $buf));
48 pipe(my ($r, $w)) or die;
49 my $cmd = ['sqlite3', $cmpfile];
50 my $pid = spawn($cmd, undef, { 0 => $r });
53 is(waitpid($pid, 0), $pid, 'sqlite3 exited');
54 is($?, 0, 'sqlite3 loaded dump');
55 my $mm_cmp = PublicInbox::Msgmap->new_file($cmpfile);
56 is($mm_cmp->mid_for(1), 'a@example.com', 'sqlite3 dump valid');
58 unlink $cmpfile or die;
60 test_psgi(sub { $www->call(@_) }, $client);
62 my $env = { PI_CONFIG => $cfgpath, TMPDIR => $tmpdir };
63 test_httpd($env, $client);