-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-html.t
40 lines (27 loc) · 834 Bytes
/
01-html.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
#!perl
use 5.006;
use strict;
use warnings;
use Test::More;
use Test::Mock::HTTP::Tiny;
use JSON::PP;
use WWW::Crawl;
plan tests => 4;
$/ = undef;
open my $fh, '<', 't/mock_html.dat' or BAIL_OUT("Can't open datafile");
my $replay = <$fh>;
close $fh;
$replay = eval { decode_json($replay) };
ok ( !$@, 'Parsed JSON' ) or BAIL_OUT($@);
is ( ref($replay), 'ARRAY', '$replay is an ARRAY ' );
BAIL_OUT("Nothing to replay") unless $replay;
Test::Mock::HTTP::Tiny->set_mocked_data( $replay );
my $crawl = WWW::Crawl->new(
'timestamp' => 'a',
'nolinks' => 1,
);
my @links = $crawl->crawl('https://www.www-crawl.test/', \&link);
cmp_ok ( scalar @links, '==', 8, 'Correct link count');
sub link {
cmp_ok ($_[0], 'eq', 'https://www.www-crawl.test/', 'Correct callback link');
}