summaryrefslogtreecommitdiff
path: root/t/update_mirror.t
blob: 7bd5a579e0d5435c5bff83c3b99a6d639fdc8fcb (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use Test::More;
use File::Spec::Functions;
use strict;
use warnings;

use lib 't/lib';

BEGIN {
  plan skip_all => "HTTP::Server::Simple required to test update_mirror"
   if not eval "use CPANServer; 1";
  plan skip_all => "Net::EmptyPort required to test update_mirror"
   if not eval "use Net::EmptyPort; 1";
  plan tests => 8;
}

use CPAN::Mini::Inject;
use File::Path;

rmtree( [ catdir( 't', 'mirror' ) ], 0, 1 );

my $port = Net::EmptyPort::empty_port;
my $server = CPANServer->new( $port );
my $pid    = $server->background;
ok( $pid, 'HTTP Server started' );
sleep 1;

$SIG{__DIE__} = sub { kill( 9, $pid ) };

my $mcpi = CPAN::Mini::Inject->new;
$mcpi->parsecfg( 't/.mcpani/config' );
$mcpi->{config}{remote} =~ s/:\d{5}\b/:$port/;

mkdir( catdir( 't', 'mirror' ) );

$mcpi->update_mirror(
  remote => "http://localhost:$port",
  local  => catdir( 't', 'mirror' )
);

kill( 9, $pid );

ok( -e catfile( qw(t mirror authors 01mailrc.txt.gz) ),
  'Mirrored 01mailrc.txt.gz' );
ok( -e catfile( qw(t mirror modules 02packages.details.txt.gz) ),
  'Mirrored 02packages.details.txt.gz' );
ok( -e catfile( qw(t mirror modules 03modlist.data.gz) ),
  'Mirrored 03modlist.data.gz' );

ok( -e catfile( qw(t mirror authors id R RJ RJBS CHECKSUMS) ),
  'RJBS CHECKSUMS' );
ok(
  -e catfile(
    qw(t mirror authors id R RJ RJBS CPAN-Mini-2.1828.tar.gz) ),
  'CPAN::Mini'
);
ok( -e catfile( qw(t mirror authors id S SS SSORICHE CHECKSUMS) ),
  'SSORICHE CHECKSUMS' );
ok(
  -e catfile(
    qw(t mirror authors id S SS SSORICHE CPAN-Mini-Inject-1.01.tar.gz)
  ),
  'CPAN::Mini::Inject'
);
sleep 1; # allow locks to expire
rmtree( [ catdir( 't', 'mirror' ) ], 0, 1 );