File: 51-call_psgi.t

package info (click to toggle)
libtest-lwp-useragent-perl 0.036-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 428 kB
  • sloc: perl: 530; makefile: 10
file content (31 lines) | stat: -rw-r--r-- 906 bytes parent folder | download | duplicates (4)
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
# generated from examples/call_psgi.t
use strict;
use warnings;

use Test::More 0.88;
use Test::Needs 'HTTP::Message::PSGI';
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
use Test::LWP::UserAgent;
use HTTP::Request::Common;

my $useragent = Test::LWP::UserAgent->new;
$useragent->register_psgi('example.com' => sub {
        my $env = shift;
        # logic here...
        [ '200', [ 'Content-Type' => 'text/plain' ], [ 'some body' ] ],
    }
);

# <something which calls the code being tested...>
my $response = $useragent->request(POST('http://example.com/success:3000', [ a => 1 ]));

my $last_request = $useragent->last_http_request_sent;
is($last_request->uri, 'http://example.com/success:3000', 'URI');
is($last_request->content, 'a=1', 'POST content');

# <now test that your code responded to the 200 response properly...>
is($response->code, '200', 'response code is correct');


done_testing;