File Coverage

blib/lib/Plack/App/Proxy/Test.pm
Criterion Covered Total %
statement 39 43 90.7
branch 3 6 50.0
condition 1 2 50.0
subroutine 12 13 92.3
pod 1 1 100.0
total 56 65 86.1


line stmt bran cond sub pod time code
1             package Plack::App::Proxy::Test;
2 7     7   73193 use strict;
  7         16  
  7         272  
3 7     7   75 use warnings;
  7         14  
  7         205  
4 7     7   37 use Carp;
  7         12  
  7         522  
5 7     7   6133 use Plack::Loader;
  7         31091  
  7         230  
6 7     7   7085 use Plack::Test;
  7         4459  
  7         363  
7 7     7   2076 use Test::More;
  7         42105  
  7         89  
8 7     7   10887 use Test::TCP;
  7         438863  
  7         560  
9 7     7   12003 use LWP::UserAgent;
  7         255152  
  7         1752  
10 7     7   409 use base Exporter::;
  7         15  
  7         4914  
11             our @EXPORT = qw(test_proxy);
12              
13             BEGIN {
14             # disable HTTP proxy when testing since we are connecting to localhost
15 7     7   2621 delete $ENV{http_proxy};
16             }
17              
18             our @BACKENDS = qw/LWP AnyEvent::HTTP/;
19              
20             sub test_proxy {
21 29     29 1 4899752 my %args = @_;
22              
23 29         101 local $Plack::Test::Impl = 'Server';
24              
25 29 50       199 my $client = delete $args{client} or croak "client test code needed";
26 29 50       137 my $app = delete $args{app} or croak "app needed";
27 29 50       215 my $proxy = delete $args{proxy} or croak "proxy needed";
28 29   50     390 my $host = delete $args{host} || '127.0.0.1';
29              
30 29         100 for my $backend (@BACKENDS) {
31              
32 58         6373266 local $ENV{PLACK_PROXY_BACKEND} = $backend;
33              
34             test_tcp(
35             client => sub {
36 58     58   3113630 my $port = shift;
37 58         1538 test_psgi(
38             app => $proxy->( $host, $port ),
39             client => $client,
40             host => $host,
41             # disable the auto redirection of LWP::UA
42             ua => LWP::UserAgent->new( max_redirect => 0 ),
43             );
44             },
45             server => sub {
46 0     0     my $port = shift;
47              
48             # Use an ordinary server.
49 0           local $ENV{PLACK_SERVER} = 'Standalone';
50              
51 0           my $server = Plack::Loader->auto(port => $port, host => $host);
52 0           $server->run($app);
53             },
54 58         1083 );
55             }
56             }
57              
58             1;
59              
60             __END__