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