Skip to content

Commit a86bb47

Browse files
committed
Added test checks and optional find-ls.gz file input
1 parent dbec4ab commit a86bb47

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

bin/author.pl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@
5151
};
5252

5353
# args
54-
my ( $pauseid, $whois_file );
54+
my ( $findls_file, $pauseid, $whois_file );
5555
GetOptions(
56-
"pauseid=s" => \$pauseid,
57-
"whois_file=s" => \$whois_file,
56+
"findls_file=s" => \$findls_file,
57+
"pauseid=s" => \$pauseid,
58+
"whois_file=s" => \$whois_file,
5859
);
5960

6061
# setup
@@ -198,7 +199,7 @@ ($id)
198199
return undef
199200
unless $dir->is_dir;
200201

201-
my $cpan_file_map = cpan_file_map();
202+
my $cpan_file_map = cpan_file_map( $findls_file );
202203
my $author_cpan_files = $cpan_file_map->{$id}
203204
or return undef;
204205

bin/backpan.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
use MetaCPAN::Ingest qw< cpan_file_map >;
1010

1111
# args
12-
my ( $distribution, $files_only, $undo );
12+
my ( $distribution, $files_only, $findls_file, $undo );
1313
GetOptions(
1414
"distribution=s" => \$distribution,
1515
"files_only" => \$files_only,
16+
"findls_file=s" => \$findls_file,
1617
"undo" => \$undo,
1718
);
1819

1920
# setup
20-
my $cpan_file_map = cpan_file_map();
21+
my $cpan_file_map = cpan_file_map( $findls_file );
2122
my $es_release = MetaCPAN::ES->new( index => "release" );
2223
my $es_file = MetaCPAN::ES->new( index => "file" );
2324

lib/MetaCPAN/ES.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ sub new ( $class, %args ) {
3737
}, $class;
3838
}
3939

40+
sub test ( $self ) {
41+
return !!(
42+
ref($self) eq __PACKAGE__
43+
and ref($self->{es})
44+
and ref($self->{es}) =~ /^Search::Elasticsearch/
45+
);
46+
}
47+
4048
sub index ( $self, %args ) {
4149
$self->{es}->index(
4250
index => $self->{index},

lib/MetaCPAN/Ingest.pm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ sub read_url ( $url ) {
248248
return $resp->decoded_content;
249249
}
250250

251-
sub cpan_file_map () {
252-
my $cpan = cpan_dir();
253-
254-
my $ls = $cpan->child(qw< indices find-ls.gz >);
255-
if ( !-e $ls ) {
256-
warn "File $ls does not exist";
257-
return {};
251+
sub cpan_file_map ( $ls = undef ) {
252+
if (!$ls) {
253+
my $cpan = cpan_dir();
254+
$ls = $cpan->child(qw< indices find-ls.gz >);
255+
if ( !-e $ls ) {
256+
die "File $ls does not exist";
257+
}
258258
}
259259

260260
log_info {"Reading $ls"};

lib/MetaCPAN/Mapper.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ sub new ( $class, %args ) {
3535
}, $class;
3636
}
3737

38+
sub test ( $self ) {
39+
return !!(
40+
ref($self) eq __PACKAGE__
41+
and ref($self->{es})
42+
and ref($self->{es}) =~ /^Search::Elasticsearch/
43+
);
44+
}
45+
3846
sub index_exists ( $self, $index ) {
3947
$self->{es}->indices->exists( index => $index );
4048
}

t/00_setup.t

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,28 @@ use MetaCPAN::ES;
88
use MetaCPAN::Mapper;
99
use MetaCPAN::Ingest qw< home >;
1010

11-
my $es = MetaCPAN::ES->new();
11+
my $es = MetaCPAN::ES->new();
12+
ok( $es->test, 'es is valid' );
13+
1214
my $mapper = MetaCPAN::Mapper->new();
15+
ok( $mapper->test, 'mapper is valid' );
1316

1417
my $home = home();
1518
my $d_bin = $home->child('bin');
1619
my $d_test = $home->child('test_data');
1720
my $d_fakecpan = $d_test->child('fakecpan');
1821
my $d_authors = $d_fakecpan->child('authors');
1922
my $d_modules = $d_fakecpan->child('modules');
23+
my $d_indices = $d_fakecpan->child('indices');
2024

2125
# === Files
2226

23-
my @files = qw<
24-
00whois.xml
25-
02packages.details.txt.gz
26-
06perms.txt
27-
>;
28-
2927
subtest 'Check Files' => sub {
3028
ok( $d_authors->child('00whois.xml'), "Found 00whois.xml" );
3129
ok( $d_modules->child('02packages.details.txt.gz'),
3230
"Found 02packages.details.txt.gz" );
3331
ok( $d_modules->child('06perms.txt'), "Found 06perms.txt" );
32+
ok( $d_indices->child('find-ls.gz'), "Found find-ls.gz" );
3433
};
3534

3635
my @packages = qw<
@@ -73,9 +72,10 @@ subtest 'Check Index' => sub {
7372
subtest 'Author Indexing' => sub {
7473
my $author_script = $d_bin->child('author.pl');
7574
my $whois_file = $d_authors->child('00whois.xml');
75+
my $findls_file = $d_indices->child('find-ls.gz');
7676

7777
# run the author indexing script
78-
`perl $author_script -whois_file $whois_file`;
78+
`perl $author_script -whois_file $whois_file -findls_file $findls_file`;
7979

8080
my $es_author = MetaCPAN::ES->new( index => 'author' );
8181
ok( $es_author->exists( index => 'author', id => 'OALDERS' ),

0 commit comments

Comments
 (0)