line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# The script tests Arch::LiteWeb. |
4
|
|
|
|
|
|
|
# Usage: env DEBUG=1 USE_NETWORK=1 tests/liteweb-1 |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
934
|
use FindBin; |
|
1
|
|
|
|
|
1532
|
|
|
1
|
|
|
|
|
56
|
|
7
|
1
|
|
|
1
|
|
1071
|
use lib "$FindBin::Bin/../perllib"; |
|
1
|
|
|
|
|
755
|
|
|
1
|
|
|
|
|
8
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1255
|
use Test::More tests => 29; |
|
1
|
|
|
|
|
23705
|
|
|
1
|
|
|
|
|
10
|
|
10
|
1
|
|
|
1
|
|
8
|
use_ok("Arch::LiteWeb"); |
|
1
|
|
|
|
|
915
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
843
|
my $web = Arch::LiteWeb->new; |
13
|
1
|
|
33
|
|
|
21
|
ok($web && $web->isa('Arch::LiteWeb'), "create web object"); |
14
|
|
|
|
|
|
|
|
15
|
1
|
50
|
|
|
|
8
|
SKIP: { |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
442
|
skip("network tests by default", 27) unless $ENV{USE_NETWORK}; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
0
|
my $content = eval { $web->get("invalid-url"); }; |
|
0
|
|
|
|
|
0
|
|
20
|
0
|
|
|
|
|
0
|
ok($@, "invalid-url causes die"); |
21
|
0
|
|
|
|
|
0
|
ok(!defined $content, "invalid-url results in undef"); |
22
|
0
|
|
|
|
|
0
|
ok(!defined $web->error, "invalid-url results in no error set"); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
$content = $web->get("http://unexisting.domain/something"); |
25
|
0
|
|
|
|
|
0
|
ok(!defined $content, "unexisting.domain results in undef"); |
26
|
0
|
|
|
|
|
0
|
ok($web->error, "unexisting.domain results in error set"); |
27
|
0
|
|
|
|
|
0
|
ok($web->network_error, "unexisting.domain results in network error set"); |
28
|
0
|
|
|
|
|
0
|
ok(!$web->response_code, "unexisting.domain results in no response code set"); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
$content = $web->get($url = "http://localhost:2/something"); |
31
|
0
|
|
|
|
|
0
|
is($web->request_url, $url, "localhost:1 url is parsed as expected"); |
32
|
0
|
|
|
|
|
0
|
ok(!defined $content, "localhost:1 results in undef"); |
33
|
0
|
|
|
|
|
0
|
ok($web->network_error, "localhost:1 results in network error set"); |
34
|
0
|
|
|
|
|
0
|
ok(!$web->response_headers, "localhost:1 results in no response headers set"); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
my $start_url = "http://google.com/robots.txt"; |
37
|
0
|
|
|
|
|
0
|
my $first_url = "http://google.com:80/robots.txt"; |
38
|
0
|
|
|
|
|
0
|
my $redir_url = "http://www.google.com/robots.txt"; |
39
|
0
|
|
|
|
|
0
|
my $final_url = "http://www.google.com:80/robots.txt"; |
40
|
0
|
|
|
|
|
0
|
$content = $web->get($start_url, noredirect => 1); |
41
|
0
|
|
|
|
|
0
|
is($web->request_url, $first_url, "resulted url is the expected one"); |
42
|
0
|
0
|
|
|
|
0
|
skip("- seems like you have no network", 15) if $web->network_error; |
43
|
0
|
|
0
|
|
|
0
|
ok($content && $content =~ /
|
44
|
0
|
|
|
|
|
0
|
is($web->response_code, 302, "google.com responds with code 302"); |
45
|
0
|
|
|
|
|
0
|
is($web->response_codestr, "Found", "google.com responds with code Found"); |
46
|
0
|
|
0
|
|
|
0
|
my $headers = $web->response_headers || {}; |
47
|
0
|
|
|
|
|
0
|
is($headers->{content_type}, "text/html", "google.com responds text/html"); |
48
|
0
|
|
|
|
|
0
|
ok($headers->{content_length}, "google.com returns Content-Length header"); |
49
|
0
|
|
|
|
|
0
|
is($headers->{location}, $redir_url, "google.com returns Location header"); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$content = $web->get($start_url); |
52
|
0
|
|
|
|
|
0
|
is($web->request_url, $final_url, "redirected url is the expected one"); |
53
|
0
|
|
|
|
|
0
|
ok(!$web->error, "google.com responds with no error set"); |
54
|
0
|
|
0
|
|
|
0
|
$headers = $web->response_headers || {}; |
55
|
0
|
|
|
|
|
0
|
is($headers->{content_type}, "text/plain", "google.com responds text/plain"); |
56
|
0
|
|
|
|
|
0
|
is($web->response_code, 200, "google.com responds with code 200"); |
57
|
0
|
|
|
|
|
0
|
is($web->response_codestr, "OK", "google.com responds with code OK"); |
58
|
0
|
|
|
|
|
0
|
ok(!$headers->{location}, "google.com returns no Location header"); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
my $host = "archzoom.sourcecontrol.net"; |
61
|
0
|
|
|
|
|
0
|
$content = $web->get("http://$host:80/robots.txt"); |
62
|
0
|
|
|
|
|
0
|
is($content, "User-agent: *\nDisallow: /\n\n", "$host: got expected robots.txt"); |
63
|
0
|
|
0
|
|
|
0
|
$headers = $web->response_headers || {}; |
64
|
0
|
|
|
|
|
0
|
my ($content_type) = split(';', $headers->{content_type}); |
65
|
0
|
|
|
|
|
0
|
is($web->request_url, "http://$host:80/robots.txt", "$host: expected url"); |
66
|
0
|
|
|
|
|
0
|
is($content_type, "text/plain", "$host: got expected Content-Type"); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |