use Test::Needs
[catagits/Web-Simple.git] / t / stream_test.t
CommitLineData
1a0ea82a 1use strict;
2use warnings FATAL => 'all';
3
d9948314 4use Test::More;
5use Test::Needs 'HTTP::Request::AsCGI';
1a0ea82a 6use HTTP::Request::Common qw(GET POST);
7
8my $app = StreamTest->new;
9
10ok run_request( $app, GET 'http://localhost/' )->is_success;
11is run_request( $app, GET 'http://localhost/' )->content, "foo";
12
1a0ea82a 13sub 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}
d9948314 41
42done_testing;