File: http_status.t

package info (click to toggle)
libdancer2-perl 0.400001%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,580 kB
  • sloc: perl: 8,461; makefile: 9
file content (41 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More tests => 5;

use Dancer2::Core::HTTP;

subtest "HTTP status" => sub {
    is( Dancer2::Core::HTTP->status( $_->{status} ) => $_->{expected},
        'status: '. ( $_->{status} || 'undef' ) )
        for { status => undef,          expected => undef },
            { status => 200,            expected => 200   },
            { status => 'Not Found',    expected => 404   },
            { status => 'bad_request',  expected => 400   },
            { status => 'i_m_a_teapot', expected => 418   },
            { status => 'error',        expected => 500   },
            { status => 911,            expected => 911   };
};


subtest "HTTP status_message" => sub {
    is( Dancer2::Core::HTTP->status_message( $_->{status} ) => $_->{expected},
        'status: '. ( $_->{status} || 'undef' ) )
        for { status => undef,   expected => undef                   },
            { status => 200,     expected => 'OK'                    },
            { status => 'error', expected => 'Internal Server Error' },
            { status => 911,     expected => undef                   };
};

is { Dancer2::Core::HTTP->status_mapping }->{"I'm a teapot"} 
    => 418, 'status_mapping';

is { Dancer2::Core::HTTP->code_mapping }->{418} 
    => "I'm a teapot", 'code_mapping';

subtest 'all_mappings' => sub {
    my %mappings = Dancer2::Core::HTTP->all_mappings;

    is $mappings{"I'm a teapot"} => 418;
    is $mappings{"i_m_a_teapot"} => 418;
    is $mappings{418} => "I'm a teapot";
};