]> Dogcows Code - chaz/p5-HTTP-AnyUA/blob - t/20-data_callback.t
change an instance of "and" to "&&"
[chaz/p5-HTTP-AnyUA] / t / 20-data_callback.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 => 13;
18
19 my $ua = shift;
20 my $any_ua = HTTP::AnyUA->new($ua, response_is_future => 1);
21
22 my $path = '/get-document';
23 my $url = $server->url . $path;
24 my $body = '';
25 my $future = $any_ua->get($url, {
26 data_callback => sub { my ($part, $resp) = @_; $body .= $part; },
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}, 'GET', 'correct method sent');
40 is($env->{REQUEST_URI}, $path, 'correct url sent');
41 is($env->{content}, '', 'no body sent');
42 }
43
44 is($body, 'this is a document', 'streamed response content matches');
45 ok($resp && !$resp->{content}, 'content in response structure is empty');
46
47 is_response_reason($resp, 'OK');
48 is_response_status($resp, 200);
49 is_response_success($resp, 1);
50 is_response_url($resp, $url);
51 is_response_header($resp, 'content-type', 'text/plain');
52 is_response_header($resp, 'content-length', 18);
53 is_response_header($resp, 'x-foo', 'bar');
54 response_protocol_ok($resp);
55 });
56
57 return $future;
58 };
59
This page took 0.033329 seconds and 4 git commands to generate.