4cc0c4e0b68d5ad2e83f0bc08775083e68da23c7
[catagits/Web-Simple.git] / t / env.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 {
11   use Web::Simple 'EnvTest';
12   package EnvTest;
13   dispatch {
14     sub (GET) {
15       my $env = @_[PSGI_ENV];
16       [ 200,
17         [ "Content-type" => "text/plain" ],
18         [ 'foo' ]
19       ]
20     },
21   }
22 }
23
24 use HTTP::Request::Common qw(GET POST);
25
26 my $app = EnvTest->new;
27
28 sub run_request {
29   my $request = shift;
30   my $c = HTTP::Request::AsCGI->new($request)->setup;
31   $app->run;
32   $c->restore;
33   return $c->response;
34 }
35
36 ok run_request(GET 'http://localhost/')->is_success;