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