X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fplack.t;h=31ec58daa99761eff6e9a1664a60c3391711f066;hb=a5409589fe53734ed073dddb15f0a8033052986b;hp=3bc4433f9ae3ce73cedf1d124790a8e238c8ed27;hpb=a6134a0ca3ac69f2dfe353019c35eb36db3d831e;p=public-inbox.git diff --git a/t/plack.t b/t/plack.t index 3bc4433f..31ec58da 100644 --- a/t/plack.t +++ b/t/plack.t @@ -1,4 +1,4 @@ -# Copyright (C) 2014, Eric Wong and all contributors +# Copyright (C) 2014-2015 all contributors # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) use strict; use warnings; @@ -83,24 +83,81 @@ EOF test_psgi($app, sub { my ($cb) = @_; - my $atomurl = 'http://example.com/test/atom.xml'; + my $atomurl = 'http://example.com/test/new.atom'; my $res = $cb->(GET('http://example.com/test/')); is(200, $res->code, 'success response received'); like($res->content, qr!href="\Q$atomurl\E"!, 'atom URL generated'); - like($res->content, qr!href="m/blah%40example\.com\.html"!, + like($res->content, qr!href="blah%40example\.com/"!, 'index generated'); }); + my $pfx = 'http://example.com/test'; test_psgi($app, sub { my ($cb) = @_; - my $pfx = 'http://example.com/test'; my $res = $cb->(GET($pfx . '/atom.xml')); is(200, $res->code, 'success response received for atom'); like($res->content, - qr!link href="\Q$pfx\E/m/blah%40example\.com\.html"!, + qr!link\s+href="\Q$pfx\E/blah%40example\.com/"!s, 'atom feed generated correct URL'); }); + + foreach my $t (('', 'f/')) { + test_psgi($app, sub { + my ($cb) = @_; + my $path = "/blah%40example.com/$t"; + my $res = $cb->(GET($pfx . $path)); + is(200, $res->code, "success for $path"); + like($res->content, qr!hihi - Me!, + "HTML returned"); + }); + } + test_psgi($app, sub { + my ($cb) = @_; + my $res = $cb->(GET($pfx . '/blah%40example.com/raw')); + is(200, $res->code, 'success response received for /*/raw'); + like($res->content, qr!^From !sm, "mbox returned"); + }); + + # legacy redirects + foreach my $t (qw(m f)) { + test_psgi($app, sub { + my ($cb) = @_; + my $res = $cb->(GET($pfx . "/$t/blah%40example.com.txt")); + is(301, $res->code, "redirect for old $t .txt link"); + my $location = $res->header('Location'); + like($location, qr!/blah%40example\.com/raw\z!, + ".txt redirected to /raw"); + }); + } + + my %umap = ( + 'm' => '', + 'f' => 'f/', + 't' => 't/', + ); + while (my ($t, $e) = each %umap) { + test_psgi($app, sub { + my ($cb) = @_; + my $res = $cb->(GET($pfx . "/$t/blah%40example.com.html")); + is(301, $res->code, "redirect for old $t .html link"); + my $location = $res->header('Location'); + like($location, + qr!/blah%40example\.com/$e(?:#u)?\z!, + ".html redirected to new location"); + }); + } + foreach my $sfx (qw(mbox mbox.gz)) { + test_psgi($app, sub { + my ($cb) = @_; + my $res = $cb->(GET($pfx . "/t/blah%40example.com.$sfx")); + is(301, $res->code, 'redirect for old thread link'); + my $location = $res->header('Location'); + like($location, + qr!/blah%40example\.com/t\.mbox(?:\.gz)?\z!, + "$sfx redirected to /mbox.gz"); + }); + } } done_testing();