|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use lib 't/lib'; |
| 4 | + |
| 5 | +use Test::More 0.96; |
| 6 | + |
| 7 | +use MetaCPAN::ES; |
| 8 | +use MetaCPAN::Mapper; |
| 9 | +use MetaCPAN::Ingest qw< home >; |
| 10 | + |
| 11 | +my $es = MetaCPAN::ES->new( mode => 'test' ); |
| 12 | +my $mapper = MetaCPAN::Mapper->new( mode => 'test' ); |
| 13 | + |
| 14 | +my $home = home(); |
| 15 | + |
| 16 | +my $test_dir = $home->child('test_data/fakecpan/') |
| 17 | + or die "Missing test data directory.\n"; |
| 18 | + |
| 19 | +my $bin = $home->child('bin'); |
| 20 | + |
| 21 | +my $authors = $test_dir->child('authors'); |
| 22 | +my $modules = $test_dir->child('modules'); |
| 23 | + |
| 24 | +# === Files |
| 25 | + |
| 26 | +my @files = qw< |
| 27 | + 00whois.xml |
| 28 | + 02packages.details.txt |
| 29 | + 06perms.txt |
| 30 | +>; |
| 31 | + |
| 32 | +subtest 'Check Files' => sub { |
| 33 | + ok( $authors->child('00whois.xml'), "Found 00whois.xml" ); |
| 34 | + ok( $modules->child('02packages.details.txt'), "Found 02packages.details.txt" ); |
| 35 | + ok( $modules->child('06perms.txt'), "Found 06perms.txt" ); |
| 36 | +}; |
| 37 | + |
| 38 | +my @packages = qw< |
| 39 | + id/O/OA/OALDERS/HTML-Parser-3.83.tar.gz |
| 40 | +>; |
| 41 | + |
| 42 | +subtest 'Check Packages' => sub { |
| 43 | + ok( $authors->child('id/O/OA/OALDERS/HTML-Parser-3.83.tar.gz'), "Found HTML-Parser-3.83.tar.gz" ); |
| 44 | +}; |
| 45 | + |
| 46 | +# === Mapping |
| 47 | + |
| 48 | +my @indices = qw< |
| 49 | + author |
| 50 | + contributor |
| 51 | + cover |
| 52 | + cve |
| 53 | + distribution |
| 54 | + favorite |
| 55 | + file |
| 56 | + mirror |
| 57 | + package |
| 58 | + permission |
| 59 | + release |
| 60 | +>; |
| 61 | + |
| 62 | +for my $i ( @indices ) { |
| 63 | + $mapper->index_delete($i, 'skip_exists'); |
| 64 | + $mapper->index_create($i); |
| 65 | +} |
| 66 | + |
| 67 | +subtest 'Check Mappings' => sub { |
| 68 | + for my $i ( @indices ) { |
| 69 | + ok( $mapper->index_exists($i), "Index '$i' exists" ); |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | +# === Index |
| 74 | + |
| 75 | +# run the author indexing script in test mode |
| 76 | +my $author_script = $bin->child('author.pl'); |
| 77 | +my $whois_file = $authors->child('00whois.xml'); |
| 78 | +`perl $author_script -whois_file $whois_file --mode test`; |
| 79 | + |
| 80 | +subtest 'Author Indexing' => sub { |
| 81 | + my $es_author = MetaCPAN::ES->new( index => 'author', mode => 'test' ); |
| 82 | + ok( $es_author->exists( index => 'author', id => 'OALDERS' ), "Found author OALDERS" ); |
| 83 | +}; |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +# check test data directory |
| 89 | +# - check all distros for test are there |
| 90 | +# - check all other data sources are there to test all indices |
| 91 | +# set ES object with (elasticsearch_test) |
| 92 | +# - check object's config |
| 93 | + |
| 94 | +# $server->set_latest; |
| 95 | +# $server->set_first; |
| 96 | +# $server->prepare_user_test_data; |
| 97 | + |
| 98 | + |
| 99 | +done_testing; |
0 commit comments