initial commit
[chaz/p5-HTTP-AnyUA] / t / 10-get.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 => 14;
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 $future = $any_ua->get($url, {
25 headers => {
26 'x-test-custom' => 'whatever',
27 'x-test-multi' => [qw(foo bar baz)],
28 },
29 });
30
31 $future->on_ready(sub {
32 my $self = shift;
33 my $resp = $self->is_done ? $self->get : $self->failure;
34 my $env = $server->read_env;
35
36 note explain 'RESPONSE: ', $resp;
37 note explain 'ENV: ', $env;
38
39 SKIP: {
40 skip 'unexpected env', 5 if ref($env) ne 'HASH';
41 is($env->{REQUEST_METHOD}, 'GET', 'correct method sent');
42 is($env->{REQUEST_URI}, $path, 'correct url sent');
43 is($env->{content}, '', 'no body sent');
44 is($env->{HTTP_X_TEST_CUSTOM}, 'whatever', 'custom header sent');
45 like($env->{HTTP_X_TEST_MULTI}, qr/foo,\s*bar,\s*baz/, 'multi-value header sent');
46 }
47
48 is_response_content($resp, 'this is a document');
49 is_response_reason($resp, 'OK');
50 is_response_status($resp, 200);
51 is_response_success($resp, 1);
52 is_response_url($resp, $url);
53 is_response_header($resp, 'content-type', 'text/plain');
54 is_response_header($resp, 'content-length', 18);
55 is_response_header($resp, 'x-foo', 'bar');
56 response_protocol_ok($resp);
57 });
58
59 return $future;
60 };
61
62 # test:
63 # X custom headers
64 # X repeat headers (arrayref value)
65 # X stream request
66 # X stream response
67 # X redirect log
68 # X internal errors
69 # X all methods: get, post, put, head, delete, custom
70 # X basic auth in URL
71
This page took 0.034755 seconds and 4 git commands to generate.