-
Notifications
You must be signed in to change notification settings - Fork 9
/
getstore.t
44 lines (32 loc) · 1003 Bytes
/
getstore.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use v6;
use Test;
use LWP::Simple;
plan 15;
if %*ENV<NO_NETWORK_TESTING> {
diag "NO_NETWORK_TESTING was set";
skip-rest("NO_NETWORK_TESTING was set");
exit;
}
# test getstore under http
getstore-tests('http://www.w3c.org', rx/Web/);
try require IO::Socket::SSL;
if $! {
skip-rest("IO::Socket::SSL not available");
exit 0;
}
getstore-tests('https://www.opera.com', rx/Opera \s+ browser/);
# Note: http://www.opera.com redirects to https
getstore-tests('http://www.opera.com', rx/Opera \s+ browser/);
sub getstore-tests($url, $rx) {
my $fname = $*SPEC.catdir($*TMPDIR, "./tmp-getstore-$*PID");
try unlink $fname;
ok(
LWP::Simple.getstore($url, $fname),
'getstore() returned success'
);
my $fh = open($fname);
ok($fh, 'Opened file handle written by getstore()');
ok $fh.slurp-rest ~~ $rx, 'Found pattern in downloaded file';
ok($fh.close, 'Close the temporary file');
ok(unlink($fname), 'Delete the temporary file');
}