X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fpsgi_v2.t;h=c4f808695b000110d84d69605f5e6e42a2437d2e;hb=fc92ce8845ac5f09939722537624fa48441f7c0b;hp=65448dc435a3d9925942233c60f4fd98e3243d72;hpb=2a49233ab00a366251974824658a20bf68e519da;p=public-inbox.git diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 65448dc4..c4f80869 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -1,24 +1,21 @@ -# Copyright (C) 2018 all contributors +# Copyright (C) 2018-2020 all contributors # License: AGPL-3.0+ use strict; use warnings; use Test::More; -use File::Temp qw/tempdir/; +use PublicInbox::TestCommon; +require_git(2.6); use PublicInbox::MIME; use PublicInbox::Config; -use PublicInbox::WWW; use PublicInbox::MID qw(mids); -my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test - URI::Escape Plack::Builder); -foreach my $mod (@mods) { - eval "require $mod"; - plan skip_all => "$mod missing for psgi_v2_dupes.t" if $@; -} -use_ok($_) for @mods; +require_mods(qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test + URI::Escape Plack::Builder)); +use_ok($_) for (qw(HTTP::Request::Common Plack::Test)); +use_ok 'PublicInbox::WWW'; use_ok 'PublicInbox::V2Writable'; -my $mainrepo = tempdir('pi-v2_dupes-XXXXXX', TMPDIR => 1, CLEANUP => 1); +my ($inboxdir, $for_destroy) = tmpdir(); my $ibx = { - mainrepo => $mainrepo, + inboxdir => $inboxdir, name => 'test-v2writable', version => 2, -primary_address => 'test@example.com', @@ -52,15 +49,18 @@ $new_mid = $mids->[1]; $im->done; my $cfgpfx = "publicinbox.v2test"; -my $cfg = { - "$cfgpfx.address" => $ibx->{-primary_address}, - "$cfgpfx.mainrepo" => $mainrepo, -}; -my $config = PublicInbox::Config->new($cfg); +my $cfg = <{-primary_address} +$cfgpfx.inboxdir=$inboxdir +EOF +my $config = PublicInbox::Config->new(\$cfg); my $www = PublicInbox::WWW->new($config); my ($res, $raw, @from_); test_psgi(sub { $www->call(@_) }, sub { my ($cb) = @_; + $res = $cb->(GET('/v2test/description')); + like($res->content, qr!\$INBOX_DIR/description missing!, + 'got v2 description missing message'); $res = $cb->(GET('/v2test/a-mid@b/raw')); $raw = $res->content; like($raw, qr/^hello world$/m, 'got first message'); @@ -153,10 +153,20 @@ test_psgi(sub { $www->call(@_) }, sub { $res = $cb->(GET('/v2test/?q=m:a-mid@b&x=t')); is($res->code, 200, 'success with threaded search'); my $raw = $res->content; - ok($raw =~ s/\A.*>Results 1-3 of 3Results 1-3 of 3\b//s, 'got all results'); + my @over = ($raw =~ m/\d{4}-\d+-\d+\s+\d+:\d+ +(?:\d+\% )?(.+)$/gm); is_deeply(\@over, [ '(GET('/v2test/?q=m:a-mid@b&x=A')); + is($res->code, 200, 'success with Atom search'); + SKIP: { + require_mods(qw(XML::TreePP), 2); + my $t = XML::TreePP->new->parse($res->content); + like($t->{feed}->{-xmlns}, qr/\bAtom\b/, + 'looks like an an Atom feed'); + is(scalar @{$t->{feed}->{entry}}, 3, 'parsed three entries'); + }; + local $SIG{__WARN__} = 'DEFAULT'; $res = $cb->(GET('/v2test/a-mid@b/')); $raw = $res->content; @@ -166,7 +176,7 @@ test_psgi(sub { $www->call(@_) }, sub { @from_ = ($raw =~ m/>From: /mg); is(scalar(@from_), 3, 'three From: lines'); foreach my $mid ('a-mid@b', $new_mid, $third) { - like($raw, qr/<\Q$mid\E>/s, "Message-ID $mid shown"); + like($raw, qr!>\Q$mid\E!s, "Message-ID $mid shown"); } like($raw, qr/\b3\+ messages\b/, 'thread overview shown'); @@ -200,8 +210,10 @@ test_psgi(sub { $www->call(@_) }, sub { $res = $cb->(GET('/v2test/0/info/refs')); is($res->code, 200, 'got info refs for dumb clones'); + $res = $cb->(GET('/v2test/0.git/info/refs')); + is($res->code, 200, 'got info refs for dumb clones w/ .git suffix'); $res = $cb->(GET('/v2test/info/refs')); - is($res->code, 404, 'unpartitioned git URL fails'); + is($res->code, 404, 'v2 git URL w/o shard fails'); # ensure conflicted attachments can be resolved foreach my $body (qw(old new)) { @@ -238,6 +250,8 @@ test_psgi(sub { $www->call(@_) }, sub { is($old->content, 'old', 'got expected old content'); is($new->content, 'new', 'got expected new content'); } + $res = $cb->(GET('/v2test/?t=1970'.'01'.'01'.'000000')); + is($res->code, 404, '404 for out-of-range t= param'); }); done_testing();