Web::Simple::Role
[catagits/Web-Simple.git] / t / stream_test.t
CommitLineData
1a0ea82a 1use strict;
2use warnings FATAL => 'all';
3
4use Test::More (
5 eval { require HTTP::Request::AsCGI }
6 ? 'no_plan'
7 : (skip_all => 'No HTTP::Request::AsCGI')
8);
9
10use HTTP::Request::Common qw(GET POST);
11
12my $app = StreamTest->new;
13
14ok run_request( $app, GET 'http://localhost/' )->is_success;
15is run_request( $app, GET 'http://localhost/' )->content, "foo";
16
1a0ea82a 17sub run_request {
18 my ( $app, $request ) = @_;
19 my $c = HTTP::Request::AsCGI->new( $request )->setup;
20 $app->run;
21 $c->restore;
22 return $c->response;
23}
24
25{
26
27 package StreamTest;
28 use Web::Simple;
29
30 sub dispatch_request {
31
32 sub (GET) {
33 [
34 sub {
35 my $respond = shift;
36 my $writer = $respond->( [ 200, [ "Content-type" => "text/plain" ] ] );
37 $writer->write( 'f' );
38 $writer->write( 'o' );
39 $writer->write( 'o' );
40 }
41 ];
42 },;
43 }
44}