~ubuntu-branches/ubuntu/wily/libhijk-perl/wily-proposed

« back to all changes in this revision

Viewing changes to t/live-head-request.t

  • Committer: Package Import Robot
  • Author(s): Robin Sheat, Robin Sheat, gregor herrmann
  • Date: 2015-02-13 10:50:34 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20150213105034-xawlya18ln1fsc15
Tags: 0.19-1
[ Robin Sheat ]
* New upstream version, 0.19

[ gregor herrmann ]
* Update copyright years.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
use FindBin;
 
6
 
 
7
use Hijk;
 
8
 
 
9
use Test::More;
 
10
 
 
11
unless ($ENV{TEST_LIVE}) {
 
12
    plan skip_all => "Enable live testing by setting env: TEST_LIVE=1";
 
13
}
 
14
 
 
15
my $pid = fork;
 
16
die "Fail to fork then start a plack server" unless defined $pid;
 
17
 
 
18
if ($pid == 0) {
 
19
    require Plack::Runner;
 
20
    my $runner = Plack::Runner->new;
 
21
    $runner->parse_options("--port", "5002", "$FindBin::Bin/bin/head-request.psgi");
 
22
    $runner->run;
 
23
    exit;
 
24
}
 
25
 
 
26
sleep 5; # hopfully this is enough to launch that psgi.
 
27
 
 
28
my %args = (
 
29
    timeout => 1,
 
30
    host    => "localhost",
 
31
    port    => "5002",
 
32
    method  => "HEAD",
 
33
);
 
34
 
 
35
subtest "expect HEAD response with a Content-Length" => sub {
 
36
    my $res = Hijk::request({%args, query_string => "gimme_content_length=1"});
 
37
    ok !exists $res->{error}, '$res->{error} should not exist because this request should have been successful';
 
38
    cmp_ok $res->{head}->{"Content-Length"}, "==", 11, "Got a Content-Length";
 
39
    cmp_ok $res->{body}, "eq", "", "Got no body even though we had a Content-Length";
 
40
};
 
41
 
 
42
subtest "expect HEAD response without a Content-Length" => sub {
 
43
    my $res = Hijk::request({%args, query_string => "gimme_content_length="});
 
44
    ok !exists $res->{error}, '$res->{error} should not exist because this request should have been successful';
 
45
    TODO: {
 
46
        local $TODO = "I can't figure out how to get plackup(1) not to implicitly add Content-Length";
 
47
        ok !exists $res->{head}->{"Content-Length"}, "We should get no Content-Length";
 
48
    }
 
49
    cmp_ok $res->{body}, "eq", "", "Got no body wit the HEAD response, also have no Content-Length";
 
50
};
 
51
 
 
52
END { kill INT => $pid if $pid }
 
53
 
 
54
done_testing;