App-cpan2arch
view release on metacpan or search on metacpan
t/02-online.t view on Meta::CPAN
note
number
number_gt
pass
skip_all
subtest
todo
>;
skip_all('Set RELEASE_TESTING=1 to run online tests')
unless $ENV{RELEASE_TESTING};
use lib 't/lib';
use TestData qw< expected_data test_diff >;
use App::cpan2arch;
use Capture::Tiny 0.50 qw< capture capture_stderr >;
use Path::Tiny 0.150;
my $has_cache_mods = do {
try {
require Mojo::UserAgent::Cached;
Mojo::UserAgent::Cached->VERSION('1.25');
require CHI;
CHI->VERSION('0.61');
}
catch ($e) {
undef;
}
};
my $expected = expected_data();
# Defaults
my %DEFS = (
class => 'App::cpan2arch',
ver => $App::cpan2arch::VERSION,
);
# Unit test methods not covered in offline tests:
# get_metadata()
# merge_prereqs()
# check_packages()
#
# NOTE:
# Some errors can only be reproduced realistically when there are internet
# connection issues or when MetaCPAN/Arch APIs have issues.
#
# Mocks are out of scope for this test, which only covers the real APIs.
subtest 'Unit test' => sub {
#skip_all;
# Tests need to set a proper C2A environment + temporary cache.
my sub get_env_cache ( $t, $path )
{
my $temp = Path::Tiny->tempdir;
my $cache_path = $temp->child($path)->stringify;
my $cache_key =
$path eq 'mcpan_cache' ? 'cache_mcpan_path'
: $path eq 'arch_cache' ? 'cache_arch_path'
: ();
my %env = (
user_agent => "$DEFS{class}/$DEFS{ver}",
$cache_key => $cache_path,
cache_expiration => '1d',
cache_ignore => $t =~ /\Ano_cache/ ? true : false,
#debug => true,
);
return ( \%env, $cache_path );
}
subtest 'Metadata' => sub {
#skip_all;
subtest 'Get metadata' => sub {
#skip_all;
my $MOD = 'File::KDBX';
my $DIST = 'File-KDBX';
my $VER = $expected->{$DIST}{version};
my $BOGUS_END = 'https://bogus/';
my %TESTS_META = (
'normal_mod' => $MOD,
'normal_dist' => $DIST,
'no_cache_mod' => $MOD,
'no_cache_dist' => $DIST,
'bogus_mod' => 'Bogus::Module',
'bogus_dist' => 'Bogus-Dist',
'bogus_mod_end' => $MOD,
'bogus_rel_end' => $DIST,
);
foreach my ( $t, $name ) (%TESTS_META) {
next if $t =~ /\Ano_cache/ && !$has_cache_mods;
subtest "$t ($name)" => sub {
my $c2a = App::cpan2arch->new;
my $cache_path;
if ($has_cache_mods) {
( my $env, $cache_path ) = get_env_cache( $t, 'mcpan_cache' );
$c2a->set_env( $env->%* );
}
my @argv = $name;
push @argv, $VER if $t eq 'normal_dist' || $t eq 'no_cache_dist';
$c2a->_process_opts( \@argv );
# Error
if ( $t =~ /\Abogus_/ ) {
my %endpoints = $c2a->endpoints;
if ( $t eq 'bogus_mod_end' ) {
$endpoints{module} = $BOGUS_END;
$c2a->set_endpoints(%endpoints);
}
( run in 2.193 seconds using v1.01-cache-2.11-cpan-600a1bdf6e4 )