App-Wallflower

 view release on metacpan or  search on metacpan

t/20-get.t  view on Meta::CPAN

    [   '/klonk/' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        Path::Tiny->new( 'klonk', 'index.html' ),
        'Hello, World!'
    ],
    [   '/clunk' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        'clunk', 'Hello, World!'
    ],
];

push @tests, [
    'content in a glob',
    Path::Tiny->tempdir( CLEANUP => 1 ),
    sub {
        [   200,
            [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
            do {
                my $file = Path::Tiny->new( $tests[0][1], 'index.html' );
                open my $fh, '<', $file or die "Can't open $file: $!";
                $fh;
                }
        ];
    },
    [   '/' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        'index.html',
        'Hello, World!'
    ],
];

push @tests, [
    'content in an object',
    Path::Tiny->tempdir( CLEANUP => 1 ),
    sub {
        [   200,
            [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
            do {

                package Clange;
                sub new { bless [ 'Hello,', ' ', 'World!' ] }
                sub getline { shift @{ $_[0] } }
                sub close   { }
                __PACKAGE__->new();
                }
        ];
    },
    [   '/' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        'index.html',
        'Hello, World!'
    ],
];

push @tests, [
    'status in the URL',
    Path::Tiny->tempdir( CLEANUP => 1 ),
    sub {
        my $env = shift;
        my ($status) = $env->{REQUEST_URI} =~ m{/(\d\d\d)$}g;
        $status ||= 404;
        [   $status,
            [   'Content-Type'   => 'text/plain',
                'Content-Length' => length $status
            ],
            [$status]
        ];
    },
    [   "/200" => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 3 ],
        '200', '200'
    ],
    [   "/403" => 403,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 3 ],
        '', ''
    ],
    [   "/blah" => 404,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 3 ],
        '', ''
    ],
];

push @tests, [
    'app that dies',
    Path::Tiny->tempdir( CLEANUP => 1 ),
    sub {die},
    [   '/' => 500,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 21 ], '', ''
    ],
];

my $last_modified = time2str( time - 10 );
push @tests, [
    'app supporting If-Modified-Since',
    Path::Tiny->tempdir( CLEANUP => 1 ),
    do {
        sub {
            my $env = shift;
            my $since = $env->{HTTP_IF_MODIFIED_SINCE} || '';
            return $last_modified eq $since
              ? [ 304, [], '' ]
              : [ 200,
                  [
                    'Content-Type'   => 'text/plain',
                    'Content-Length' => 13,
                    'Last-Modified'  => $last_modified,
                  ],
                  ['Hello, World!']
                ];
        };
    },
    [
        '/' => 200,
        [
            'Content-Type'   => 'text/plain',
            'Content-Length' => 13,
            'Last-Modified'  => $last_modified
        ],
        'index.html',
        'Hello, World!'
    ],
    [ '/' => 304, [], 'index.html', 'Hello, World!' ],
];

push @tests, [
    'not respecting directory semantics',
    Path::Tiny->tempdir( CLEANUP => 1 ),
    sub {
        [   200,
            [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
            [ 'Hello,', ' ', 'World!' ]
        ];
    },
    [ 'http://localhost//foo' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        'foo',
        'Hello, World!'



( run in 0.819 second using v1.01-cache-2.11-cpan-788537b7465 )