1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
use strict;
use Test::More;
use LWP::UserAgent;
use LWP::Protocol::PSGI;
use LWP::Simple;
my $psgi_app = sub {
my $env = shift;
return [
200,
[
"Content-Type", "text/plain",
"X-Foo" => "bar",
],
[ "query=$env->{QUERY_STRING}" ],
];
};
LWP::Protocol::PSGI->register($psgi_app);
my $ua = LWP::UserAgent->new;
sub verify {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $res = $ua->get("http://www.google.com/search?q=bar");
is $res->content, "query=q=bar";
is $res->header('X-Foo'), "bar";
my $body = get "http://www.google.com/?q=x";
is $body, "query=q=x";
}
subtest "when registered" => sub {
verify;
};
LWP::Protocol::PSGI->unregister;
subtest "when unregistered" => sub {
SKIP: {
skip "needs internet access", 3 unless $ENV{AUTHOR_TESTING};
my $res = $ua->get("http://www.google.com/search?q=bar");
isnt $res->content, "query=q=bar";
isnt $res->header('X-Foo'), "bar";
my $body = get "http://www.google.com/?q=x";
isnt $body, "query=q=x";
}
};
LWP::Protocol::PSGI->register($psgi_app);
subtest "when reregistered" => sub {
verify;
};
done_testing;
|