|
| 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 @test_mode = ( mode => 'test' ); |
| 12 | + |
| 13 | +my $es = MetaCPAN::ES->new(@test_mode); |
| 14 | +my $mapper = MetaCPAN::Mapper->new(@test_mode); |
| 15 | + |
| 16 | +my $home = home(); |
| 17 | +my $d_bin = $home->child('bin'); |
| 18 | +my $d_test = $home->child('test_data'); |
| 19 | +my $d_fakecpan = $d_test->child('fakecpan'); |
| 20 | +my $d_authors = $d_fakecpan->child('authors'); |
| 21 | +my $d_modules = $d_fakecpan->child('modules'); |
| 22 | + |
| 23 | +# === Files |
| 24 | + |
| 25 | +my @files = qw< |
| 26 | + 00whois.xml |
| 27 | + 02packages.details.txt.gz |
| 28 | + 06perms.txt |
| 29 | +>; |
| 30 | + |
| 31 | +subtest 'Check Files' => sub { |
| 32 | + ok( $d_authors->child('00whois.xml'), "Found 00whois.xml" ); |
| 33 | + ok( $d_modules->child('02packages.details.txt.gz'), "Found 02packages.details.txt.gz" ); |
| 34 | + ok( $d_modules->child('06perms.txt'), "Found 06perms.txt" ); |
| 35 | +}; |
| 36 | + |
| 37 | +my @packages = qw< |
| 38 | + id/O/OA/OALDERS/HTML-Parser-3.83.tar.gz |
| 39 | +>; |
| 40 | + |
| 41 | +subtest 'Check Packages' => sub { |
| 42 | + ok( $d_authors->child('id/O/OA/OALDERS/HTML-Parser-3.83.tar.gz'), "Found HTML-Parser-3.83.tar.gz" ); |
| 43 | +}; |
| 44 | + |
| 45 | +# === Mapping |
| 46 | + |
| 47 | +my @indices = qw< |
| 48 | + author |
| 49 | + contributor |
| 50 | + cover |
| 51 | + cve |
| 52 | + distribution |
| 53 | + favorite |
| 54 | + file |
| 55 | + mirror |
| 56 | + package |
| 57 | + permission |
| 58 | + release |
| 59 | +>; |
| 60 | + |
| 61 | +for my $i ( @indices ) { |
| 62 | + $mapper->index_create(index => $i, add_mapping => 1, delete_first => 1); |
| 63 | +} |
| 64 | + |
| 65 | +subtest 'Check Index' => sub { |
| 66 | + for my $i ( @indices ) { |
| 67 | + ok( $mapper->index_exists($i), "Index '$i' exists" ); |
| 68 | + } |
| 69 | +}; |
| 70 | + |
| 71 | +# === Index |
| 72 | + |
| 73 | +subtest 'Author Indexing' => sub { |
| 74 | + my $author_script = $d_bin->child('author.pl'); |
| 75 | + my $whois_file = $d_authors->child('00whois.xml'); |
| 76 | + # run the author indexing script in test mode |
| 77 | + `perl $author_script -whois_file $whois_file --mode test`; |
| 78 | + |
| 79 | + my $es_author = MetaCPAN::ES->new( index => 'author', @test_mode ); |
| 80 | + ok( $es_author->exists( index => 'author', id => 'OALDERS' ), "Found author OALDERS" ); |
| 81 | +}; |
| 82 | + |
| 83 | +subtest 'Package Indexing' => sub { |
| 84 | + my $package_script = $d_bin->child('package.pl'); |
| 85 | + my $package_file = $d_modules->child('02packages.details.txt.gz'); |
| 86 | + # run the package indexing script in test mode |
| 87 | + `perl $package_script -package_file $package_file --mode test`; |
| 88 | + |
| 89 | + my $es_package = MetaCPAN::ES->new( index => 'package', @test_mode ); |
| 90 | + ok( $es_package->exists( index => 'package', id => 'LWP' ), "Found package LWP" ); |
| 91 | +}; |
| 92 | + |
| 93 | +subtest 'Permissions Indexing' => sub { |
| 94 | + my $perms_script = $d_bin->child('permission.pl'); |
| 95 | + my $perms_file = $d_modules->child('06perms.txt'); |
| 96 | + # run the permission indexing script in test mode |
| 97 | + `perl $perms_script -perms_file $perms_file --mode test`; |
| 98 | + |
| 99 | + my $es_permission = MetaCPAN::ES->new( index => 'permission', @test_mode ); |
| 100 | + ok( $es_permission->exists( index => 'permission', id => 'LWP' ), "Found permissions for LWP" ); |
| 101 | +}; |
| 102 | + |
| 103 | +subtest 'Release Indexing' => sub { |
| 104 | + my $release_script = $d_bin->child('release.pl'); |
| 105 | + my $release_file = $d_authors->child('id/O/OA/OALDERS/HTML-Parser-3.83.tar.gz'); |
| 106 | + # run the release indexing script in test mode for a tarball |
| 107 | + `perl $release_script -mode test $release_file`; |
| 108 | + |
| 109 | + my $es_file = MetaCPAN::ES->new( index => 'file', @test_mode ); |
| 110 | + my $file_search_total = $es_file->search(body => { |
| 111 | + query => { match => { release => 'HTML-Parser-3.83' } }, |
| 112 | + })->{hits}{total}; |
| 113 | + ok( $file_search_total > 0, "Found files for HTML-Parser-3.83" ); |
| 114 | + |
| 115 | + my $es_release = MetaCPAN::ES->new( index => 'release', @test_mode ); |
| 116 | + my $release_search_total = $es_release->search(body => { |
| 117 | + query => { match => { name => 'HTML-Parser-3.83' } }, |
| 118 | + })->{hits}{total}; |
| 119 | + |
| 120 | + ok( $release_search_total == 1, "Found release entries for HTML-Parser-3.83" ); |
| 121 | +}; |
| 122 | + |
| 123 | +subtest 'Cover Indexing' => sub { |
| 124 | + my $cover_script = $d_bin->child('cover.pl'); |
| 125 | + my $cover_file = $d_test->child('cpancover_dev.json'); |
| 126 | + # run the cover indexing script in test mode |
| 127 | + `perl $cover_script -json $cover_file -mode test`; |
| 128 | + |
| 129 | + my $es_cover = MetaCPAN::ES->new( index => 'cover', @test_mode ); |
| 130 | + ok( $es_cover->exists( index => 'cover', id => 'HTML-Parser-3.83' ), "Found cover data for HTML-Parser-3.83" ); |
| 131 | +}; |
| 132 | + |
| 133 | +# TODO: |
| 134 | +# contributor |
| 135 | +# cve |
| 136 | +# favorite |
| 137 | + |
| 138 | +# check test data directory |
| 139 | +# - check all distros for test are there |
| 140 | +# - check all other data sources are there to test all indices |
| 141 | +# set ES object with (elasticsearch_test) |
| 142 | +# - check object's config |
| 143 | + |
| 144 | +# $server->set_latest; |
| 145 | +# $server->set_first; |
| 146 | +# $server->prepare_user_test_data; |
| 147 | + |
| 148 | + |
| 149 | +done_testing; |
0 commit comments