App-Fetchware
view release on metacpan or search on metacpan
t/App-FetchwareX-HTMLPageSync.t view on Meta::CPAN
# Test for extracting out links.
html_treebuilder_callback sub {
my $h = shift;
#parse out archive name.
my $link = $h->as_text();
if ($link =~ /\.(tar\.(gz|bz2|xz)|(tgz|tbz2|txz))$/) {
# If its an archive return true indicating we should keep this
# HTML::Element.
return 'True';
} else {
return undef; # return false indicating do not keep this one.
}
};
my $html_urls = lookup();
cmp_deeply(
$html_urls,
array_each(
re(qr/\.(tar\.(gz|bz2|xz)|(tgz|tbz2|txz))$/)
),
'checked lookup()s return value for acceptable values again.'
);
download_links_callback sub {
my @download_urls = @_;
my @filtered_urls;
for my $link (@download_urls) {
# Strip off HTML::Element crap.
$link = $link->attr('href');
# Keep links that are absolute.
# And make change relative links to absolute.
if ($link !~ m!^(ftp|http|file)://!) {
push @filtered_urls, config('html_page_url') . '/' . $link;
}
}
# Return the filtered urls not the provided unfiltered @download_urls.
return @filtered_urls;
};
my $abs_urls = lookup();
cmp_deeply(
$abs_urls,
array_each(
re(qr!^(ftp|http|file)://!)
),
'checked lookup()s return value for acceptable values yet again.'
);
};
# Created here so it can be shared with install()'s subtest.
my $download_file_paths;
subtest 'test HTMLPageSync download()' => sub {
skip_all_unless_release_testing();
# FETCHWARE_HTTP_DOWNLOAD_URL is manually updated will break whenever a new
# version of Apache 2.2 comes out.
# download() wants an array ref.
$download_file_paths = download($temp_dir,
[ $ENV{FETCHWARE_HTTP_DOWNLOAD_URL} ]);
note("DFP");
note explain $download_file_paths;
ok(@$download_file_paths == 1,
'checked download() correct number of files');
is($download_file_paths->[0],
file($ENV{FETCHWARE_HTTP_DOWNLOAD_URL})->basename(),
'checked download() success.');
ok(-e $download_file_paths->[0],
'checked download()ed file existence');
};
subtest 'test HTMLPageSync verify()' => sub {
is(verify('dummy', 'args'), undef, 'checked verify() success.');
};
subtest 'test HTMLPageSync unarchive()' => sub {
is(unarchive(), undef, 'checked unarchive() success.');
};
subtest 'test HTMLPageSync build()' => sub {
is(verify('dummy arg'), undef, 'checked build() success.');
};
subtest 'test HTMLPageSync install()' => sub {
skip_all_unless_release_testing();
ok(install($download_file_paths),
'checked install() success');
# install() needs an array reference.
eval_ok(sub { install([ "file-that-doesn-t-exist-$$" ])},
qr/App-FetchwareX-HTMLPageSync: run-time error. Fetchware failed to copy the file \[/,
'checked install exception');
};
subtest 'test HTMLPageSync uninstall()' => sub {
skip_all_unless_release_testing();
# Will delete destination_directory, but the destination_directory is a
# tempdir(), so it will be delete anyway.
# Just ignore the warning File::Temp prints, because I deleted its tempdir()
# instead of it doing it itself.
ok(uninstall(cwd()),
'checked uninstall() success');
ok(! -e $dest_dir,
'checked uninstall() tempdir removal');
# Test uninstall()s exceptions.
( run in 1.031 second using v1.01-cache-2.11-cpan-39bf76dae61 )