File: guardless.t

package info (click to toggle)
liblwp-protocol-psgi-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: perl: 131; makefile: 2; sh: 1
file content (59 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (2)
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;