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