]> Dogcows Code - chaz/p5-HTTP-AnyUA/blob - t/23-content-coderef.t
change an instance of "and" to "&&"
[chaz/p5-HTTP-AnyUA] / t / 23-content-coderef.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 # using Starman because we need a server that can handle chunked requests
13 my $server = start_server('t/app.psgi', type => 'Starman');
14
15 plan tests => scalar user_agents;
16
17 test_all_user_agents {
18 plan tests => 10;
19
20 my $ua = shift;
21 my $any_ua = HTTP::AnyUA->new(ua => $ua, response_is_future => 1);
22
23 if ($ua->isa('Mojo::UserAgent')) {
24 # disable keep-alive to avoid Mojo::Reactor::EV warnings
25 $ua->max_connections(0);
26 }
27
28 my $chunk = 0;
29 my @chunk = ('some ', 'document');
30 my $code = sub { return $chunk[$chunk++] };
31
32 my $path = '/create-document';
33 my $url = $server->url . $path;
34 my $future = $any_ua->post($url, {
35 headers => {'content-type' => 'text/plain'},
36 content => $code,
37 });
38
39 $future->on_ready(sub {
40 my $self = shift;
41 my $resp = $self->is_done ? $self->get : $self->failure;
42 my $env = $server->read_env;
43
44 note explain 'RESPONSE: ', $resp;
45 note explain 'ENV: ', $env;
46
47 SKIP: {
48 skip 'unexpected env', 3 if ref($env) ne 'HASH';
49 is($env->{REQUEST_METHOD}, 'POST', 'correct method sent');
50 is($env->{REQUEST_URI}, $path, 'correct url sent');
51 is($env->{content}, 'some document', 'correct body sent');
52 }
53
54 is_response_content($resp, 'created document');
55 is_response_reason($resp, 'Created');
56 is_response_status($resp, 201);
57 is_response_success($resp, 1);
58 is_response_url($resp, $url);
59 is_response_header($resp, 'content-type', 'text/plain');
60 response_protocol_ok($resp);
61 });
62
63 return $future;
64 };
65
This page took 0.030617 seconds and 4 git commands to generate.