App-Fetchware
view release on metacpan or search on metacpan
t/App-Fetchware-Util.t view on Meta::CPAN
read_dropprivs_pipe
create_tempdir
original_cwd
cleanup_tempdir
);
# sort them to make the testing their equality very easy.
my @sorted_util_tag = sort @{$App::Fetchware::Util::EXPORT_TAGS{UTIL}};
@expected_util_exports = sort @expected_util_exports;
is_deeply(\@sorted_util_tag, \@expected_util_exports,
'checked for correct UTIL @EXPORT_TAG');
};
subtest 'test ftp_download_dirlist()' => sub {
skip_all_unless_release_testing();
# Test its success.
# Note link below may change. If it does just find a another anonymous ftp
# mirror.
ok(ftp_download_dirlist($ENV{FETCHWARE_FTP_LOOKUP_URL}),
'check ftp_download_dirlist() success');
eval_ok(sub {ftp_download_dirlist('ftp://doesntexist.ever')},
qr/App-Fetchware: run-time error\. fetchware failed to connect to the ftp server at
domain \[doesntexist\.ever\]\. The system error was \[Name or service not known|Net::FTP: Bad hostname 'doesntexist\.ever'\]\.
See man App::Fetchware\./,
'checked determine_download_url() connect failure');
##HOWTOTEST## eval_ok(sub #{ftp_download_dirlist('whatftpserverdoesntsupportanonymous&ispublic?');},
##HOWTOTEST## <<EOS, 'checked ftp_download_dirlist() anonymous loginfailure');
##HOWTOTEST##App-Fetchware: run-time error. fetchware failed to log in to the ftp server at
##HOWTOTEST##domain [$site]. The ftp error was [@{[$ftp->message]}]. See man App::Fetchware.
##HOWTOTEST##EOS
$ENV{FETCHWARE_FTP_LOOKUP_URL} =~ m!^(ftp://[-a-z,A-Z,0-9,\.]+)(/.*)?!;
my $site = $1;
eval_ok(sub {ftp_download_dirlist( "$site/doesntexist.ever")},
qr/App-Fetchware: run-time error. fetchware failed to get a long directory listing/,
'check ftp_download_dirlist() Net::FTP->dir($path) failure');
};
subtest 'test http_download_dirlist()' => sub {
skip_all_unless_release_testing();
# Test success.
ok(http_download_dirlist($ENV{FETCHWARE_HTTP_LOOKUP_URL}),
'checked http_download_dirlist() success');
eval_ok(sub {http_download_dirlist('http://meanttofail.fake/gonna/fail');},
qr/.*?HTTP::Tiny failed to download.*?/,
'checked http_download_dirlist() download failure');
##HOWTOTEST## eval_ok(sub {http_download_dirlist('whatshouldthisbe??????');,
##HOWTOTEST## <<EOS, 'checked http_download_dirlist() empty content failure');
##HOWTOTEST##App-Fetchware: run-time error. The lookup_url you provided downloaded nothing.
##HOWTOTEST##HTTP status code [$response->{status} $response->{reason}]
##HOWTOTEST##HTTP headers [@{[Data::Dumper::Dumper($response)]}].
##HOWTOTEST##See man App::Fetchware.
##HOWTOTEST##EOS
};
subtest 'test file_download_dirlist()' => sub {
# Test file_download_dirlist()'s Exceptions.
eval_ok(sub {file_download_dirlist('/akdjf983hfo3e4gghj-doesnotexist')},
qr/App-Fetchware-Util: The directory that fetchware is trying to use to determine/,
'checked file_download_dirlist() does not exist exception.');
my $temp_dir = tempdir("fetchware-test-$$-XXXXXXXXX",
CLEANUP => 1, TMPDIR => 1);
eval_ok(sub {file_download_dirlist($temp_dir)},
qr/Fetchware-Util: The directory that fetchware is trying to use to determine/,
'checked file_download_dirlist() empty directory exception.');
# Get a dirlisting for fetchware's testing directory, because it *has* to
# exist.
my $test_path = rel2abs('t');
my $dirlist = file_download_dirlist("file://$test_path");
note explain $dirlist;
# Check if known files are in the t directory. Regexes are used in case
# files are changed or added, so I don't have to constantly update a silly
# listing of all the files in the t directory.
ok( grep m!App-Fetchware-!, @$dirlist,
'checked file_download_dirlist() for App-Fetchware tests.');
ok( grep m!bin-fetchware-!, @$dirlist,
'checked file_download_dirlist() for bin-fetchware tests.');
};
subtest 'test no_mirror_download_dirlist' => sub {
skip_all_unless_release_testing();
my $url = 'invalidscheme://fake.url';
eval_ok(sub {no_mirror_download_dirlist($url)}, <<EOS, 'checked no_mirror_download_dirlist() invalid url scheme');
App-Fetchware: run-time syntax error: the url parameter your provided in
your call to download_dirlist() [invalidscheme://fake.url] does not have a supported URL scheme (the
http:// or ftp:// part). The only supported download types, schemes, are FTP and
HTTP. See perldoc App::Fetchware.
EOS
ok(no_mirror_download_dirlist($ENV{FETCHWARE_HTTP_LOOKUP_URL}),
'check no_mirror_download_dirlist() ftp success');
ok(no_mirror_download_dirlist($ENV{FETCHWARE_HTTP_LOOKUP_URL}),
'check no_mirror_download_dirlist() http success');
# No cleanup code needed ftp doesn't download files, and http uses
# HTTP::Tiny, which returns a scalar ref. None of these are files written to
# the filesystem, so nothing needs cleaning up.
};
subtest 'test download_dirlist' => sub {
skip_all_unless_release_testing();
( run in 1.036 second using v1.01-cache-2.11-cpan-39bf76dae61 )