AnyEvent-HTTP-Message
view release on metacpan or search on metacpan
t/response.t view on Meta::CPAN
use strict;
use warnings;
use Test::More 0.88;
use lib 't/lib';
use AEHTTP_Tests;
my $mod = 'AnyEvent::HTTP::Response';
eval "require $mod" or die $@;
# parse_args error
foreach my $args ( [1], [1,2,3] ){
is eval { $mod->parse_args(@$args) }, undef, 'wrong number of args';
like $@, qr/expects two arguments/, 'error message';
}
# not much to test here, just order of args
{
my $body = "black\nparade";
my %pseudo = (
Pseudo => 'Header',
Status => 200,
Reason => 'Who Cares',
HTTPVersion => 1.1,
);
my %headers = (
%pseudo,
'x-interjection' => '3 cheers!'
);
my $res = new_ok($mod, [$body, { %headers }]);
is $res->body, $body, 'body in/out';
is $res->content, $body, 'content alias';
is_deeply $res->headers, { 'x-interjection' => '3 cheers!' }, 'headers in/out';
is_deeply $res->pseudo_headers, { %pseudo }, 'pseudo headers';
my @interjections = qw( X_Interjection X-INTERJECTION );
is $res->header( $_ ), '3 cheers!', 'single header'
for @interjections;
is_deeply [ $res->args ], [ $body, { %headers } ], 'arg list';
test_http_message $res, sub {
my $msg = shift;
ok $msg->is_success, '200 OK';
is $msg->message, 'Who Cares', 'nobody cares';
is $msg->header( $_ ), '3 cheers!', 'header via HTTP::Headers'
for @interjections;
is $msg->protocol, 'HTTP/1.1', 'HTTPVersion => protocol';
is $msg->content, "black\nparade", 'reponse body content';
};
}
# args via hashref
{
my $body = 'the end';
my %headers = (
res_is => 'less useful than req'
);
my %pseudo = (
Silly => 'wabbit',
Status => 413,
HTTPVersion => '1.0',
Reason => 'Your Request is Stupid',
( run in 0.963 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )