File: cascade_streaming.t

package info (click to toggle)
libplack-perl 0.9941-1%2Bdeb6u1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 1,472 kB
  • ctags: 600
  • sloc: perl: 7,155; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 742 bytes parent folder | download | duplicates (2)
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
use Plack::Test;
use Test::More;

use Plack::App::Cascade;
use HTTP::Request::Common;

my $cascade = Plack::App::Cascade->new;
$cascade->add( sub { return sub { my $respond = shift; $respond->([ 404, [], [ "Duh" ] ]) } } );
$cascade->add( sub { return [ 403, [ 'Content-Type', 'text/plain' ], [ "Forbidden" ] ] } );
$cascade->add( sub { return sub {
                         my $w = shift->([ 200, [ 'Content-Type', 'text/plain' ] ]);
                         $w->write("Hello");
                         $w->close;
                     } });

$cascade->catch([ 403, 404 ]);

test_psgi $cascade, sub {
    my $cb = shift;

    my $res = $cb->(GET "http://localhost/");
    is $res->code, 200;
    is $res->content, "Hello";
};

done_testing;