CPAN-Common-Index

 view release on metacpan or  search on metacpan

t/mirror.t  view on Meta::CPAN

use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use Test::FailWarnings;
use Test::Deep '!blessed';
use Test::Fatal;

use Cwd qw/getcwd/;
use File::Temp;
use File::Spec::Functions qw/catfile/;

use lib 't/lib';
use CommonTests;

my $cwd         = getcwd;
my $test_mirror = "file:///$cwd/t/CPAN";
my $mailrc      = "01mailrc.txt";
my $packages    = "02packages.details.txt";

sub new_mirror_index {
    my $cache = File::Temp->newdir;
    my $index = new_ok(
        'CPAN::Common::Index::Mirror' => [ { cache => $cache, mirror => $test_mirror } ],
        "new with cache and mirror"
    );
    is $index->cache, $cache, "the cache constructor attribute is respected";
    $index;
}

require_ok("CPAN::Common::Index::Mirror");

subtest "constructor tests" => sub {
    # no arguments, all defaults
    new_ok(
        'CPAN::Common::Index::Mirror' => [],
        "new with no args"
    );

    # cache specified
    new_ok(
        'CPAN::Common::Index::Mirror' => [ { cache => File::Temp->newdir } ],
        "new with cache"
    );

    # mirror specified
    new_ok(
        'CPAN::Common::Index::Mirror' => [ { mirror => $test_mirror } ],
        "new with mirror"
    );

    # both specified
    new_mirror_index;

};

subtest 'refresh and unpack index files' => sub {
    my $index = new_mirror_index;

    my @file = ( $mailrc, $packages );
    push @file, "$mailrc.gz", "$packages.gz"
      if $CPAN::Common::Index::Mirror::HAS_IO_UNCOMPRESS_GUNZIP;

    for my $file (@file) {
        ok( !-e catfile( $index->cache, $file ), "$file not there" );
    }
    ok( $index->refresh_index, "refreshed index" );



( run in 1.074 second using v1.01-cache-2.11-cpan-54e63673c56 )