]> Dogcows Code - chaz/p5-HTTP-AnyUA/blob - t/11-post.t
add Dockerfile for testing
[chaz/p5-HTTP-AnyUA] / t / 11-post.t
1 #!perl
2
3 use warnings;
4 use strict;
5
6 use lib 't/lib';
7
8 use HTTP::AnyUA;
9 use Test::More;
10 use Util qw(:server :test :ua);
11
12 my $server = start_server('t/app.psgi');
13
14 plan tests => scalar user_agents;
15
16 test_all_user_agents {
17 plan tests => 10;
18
19 my $ua = shift;
20 my $any_ua = HTTP::AnyUA->new(ua => $ua, response_is_future => 1);
21
22 my $path = '/create-document';
23 my $url = $server->url . $path;
24 my $future = $any_ua->post($url, {
25 headers => {'content-type' => 'text/plain'},
26 content => 'some document',
27 });
28
29 $future->on_ready(sub {
30 my $self = shift;
31 my $resp = $self->is_done ? $self->get : $self->failure;
32 my $env = $server->read_env;
33
34 note explain 'RESPONSE: ', $resp;
35 note explain 'ENV: ', $env;
36
37 SKIP: {
38 skip 'unexpected env', 3 if ref($env) ne 'HASH';
39 is($env->{REQUEST_METHOD}, 'POST', 'correct method sent');
40 is($env->{REQUEST_URI}, $path, 'correct url sent');
41 is($env->{content}, 'some document', 'correct body sent');
42 }
43
44 is_response_content($resp, 'created document');
45 is_response_reason($resp, 'Created');
46 is_response_status($resp, 201);
47 is_response_success($resp, 1);
48 is_response_url($resp, $url);
49 is_response_header($resp, 'content-type', 'text/plain');
50 response_protocol_ok($resp);
51 });
52
53 return $future;
54 };
55
This page took 0.03846 seconds and 5 git commands to generate.