File: 002-to-app.t

package info (click to toggle)
libhttp-throwable-perl 0.028-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 428 kB
  • sloc: perl: 1,354; makefile: 2; sh: 1
file content (79 lines) | stat: -rw-r--r-- 2,501 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl

use strict;
use warnings;

use HTTP::Throwable::Factory;

use Test::More;
use Plack::Test;
use Plack::Builder;
use HTTP::Request::Common qw[ GET ];

test_psgi(
    app => builder {
        mount '/old' => HTTP::Throwable::Factory->new_exception(
            MovedPermanently => { location => '/new' }
        );
        mount '/new' => sub {
            [ 200, [], ['HERE']];
        };
    },
    client => sub {
        my $cb = shift;

        {
            my $req = GET "/old";
            my $res = $cb->($req);
            is($res->code, 301, '... got the right status code');
            is($res->header('Content-Type'), 'text/plain', '... got the right Content-Type header');
            is($res->header('Content-Length'), 21, '... got the right Content-Length header');
            is($res->header('Location'), '/new', '... got the right Allow header');
            is($res->content, '301 Moved Permanently', '... got the right content body');
        }
        {
            my $req = GET "/new";
            my $res = $cb->($req);
            is($res->code, 200, '... got the right status code');
            is($res->content, 'HERE', '... got the right content body');
        }
    }
);

test_psgi(
    app => HTTP::Throwable::Factory->new_exception(
        MethodNotAllowed => { allow => [ qw(POST PUT) ] }
    ),
    client => sub {
        my $cb = shift;

        {
            my $req = GET "/";
            my $res = $cb->($req);
            is($res->code, 405, '... got the right status code');
            is($res->header('Content-Type'), 'text/plain', '... got the right Content-Type header');
            is($res->header('Content-Length'), 22, '... got the right Content-Length header');
            is($res->header('Allow'), 'POST,PUT', '... got the right Allow header');
            is($res->content, '405 Method Not Allowed', '... got the right content body');
        }
    }
);

test_psgi(
    app => HTTP::Throwable::Factory->new_exception('NotFound'),
    client => sub {
        my $cb = shift;

        {
            my $req = GET "/";
            my $res = $cb->($req);
            is($res->code, 404, '... got the right status code');
            is($res->header('Content-Type'), 'text/plain', '... got the right Content-Type header');
            is($res->header('Content-Length'), 13, '... got the right Content-Length header');
            is($res->content, '404 Not Found', '... got the right content body');
        }
    }
);


done_testing;