@@ -6,21 +6,24 @@ use version;
66
77use HTTP::Request::Common qw( GET ) ;
88use List::Util ();
9+ use MetaCPAN::ESConfig qw( es_doc_path ) ;
910use MetaCPAN::Types::TypeTiny qw( ArrayRef HashRef Str ) ;
1011use Test::More;
1112
12- with( ' MetaCPAN::Tests::Model ' );
13+ with qw( MetaCPAN::Tests::Query ) ;
1314
1415sub _build_type {' release' }
1516
1617sub _build_search {
1718 my ($self ) = @_ ;
18- return [
19- get => {
20- author => $self -> author,
21- name => $self -> name,
22- }
23- ];
19+ return {
20+ bool => {
21+ must => [
22+ { term => { author => $self -> author } },
23+ { term => { name => $self -> name } },
24+ ]
25+ },
26+ };
2427}
2528
2629around BUILDARGS => sub {
@@ -35,8 +38,9 @@ around BUILDARGS => sub {
3538 @$attr {qw( distribution version ) } = ( $1 , $2 );
3639 }
3740
38- # We handle this one specially.
41+ # We handle these specially.
3942 delete $attr -> {_expect }{tests };
43+ delete $attr -> {_expect }{modules };
4044
4145 return $attr ;
4246};
@@ -92,7 +96,7 @@ sub file_content {
9296
9397sub file_by_path {
9498 my ( $self , $path ) = @_ ;
95- my $file = List::Util::first { $_ -> path eq $path } @{ $self -> files };
99+ my $file = List::Util::first { $_ -> { path } eq $path } @{ $self -> files };
96100 ok $file , " found file '$path '" ;
97101 return $file ;
98102}
@@ -117,17 +121,22 @@ sub filter_files {
117121 if $add_filters && ref ($add_filters ) ne ' ARRAY' ;
118122
119123 my $release = $self -> data;
120- return [
121- $self -> model-> doc(' file' )-> query( {
122- bool => {
123- must => [
124- { term => { ' author' => $release -> author } },
125- { term => { ' release' => $release -> name } },
126- @{ $add_filters || [] },
127- ],
128- }
129- } )-> size(100)-> all
130- ];
124+ my $res = $self -> es-> search(
125+ es_doc_path(' file' ),
126+ body => {
127+ query => {
128+ bool => {
129+ must => [
130+ { term => { ' author' => $release -> {author } } },
131+ { term => { ' release' => $release -> {name } } },
132+ @{ $add_filters || [] },
133+ ],
134+ },
135+ },
136+ size => 100,
137+ },
138+ );
139+ return [ map $_ -> {_source }, @{ $res -> {hits }{hits } } ];
131140}
132141
133142has modules => (
@@ -177,7 +186,7 @@ has tests => (
177186
178187sub has_tests_ok {
179188 my ($self ) = @_ ;
180- my $tests = $self -> data-> tests;
189+ my $tests = $self -> data-> { tests } ;
181190
182191 # Don't test the actual numbers since we copy this out of the real
183192 # database as a live test case.
@@ -198,15 +207,15 @@ test 'release attributes' => sub {
198207 my ($self ) = @_ ;
199208
200209 foreach my $attr (@attrs ) {
201- is $self -> data-> $attr , $self -> $attr , " release $attr " ;
210+ is $self -> data-> { $attr } , $self -> $attr , " release $attr " ;
202211 }
203212
204213 if ( $self -> expects_tests ) {
205214 if ( $self -> tests eq ' 1' ) {
206215 $self -> has_tests_ok;
207216 }
208217 else {
209- is_deeply $self -> data-> tests, $self -> tests, ' test results' ;
218+ is_deeply $self -> data-> { tests } , $self -> tests, ' test results' ;
210219 }
211220 }
212221};
@@ -218,11 +227,13 @@ test 'modules in Packages-1.103' => sub {
218227 unless scalar keys %{ $self -> modules };
219228
220229 my %module_files
221- = map { ( $_ -> path => $_ -> module ) } @{ $self -> module_files };
230+ = map { ( $_ -> { path } => $_ -> { module } ) } @{ $self -> module_files };
222231
223232 foreach my $path ( sort keys %{ $self -> modules } ) {
224233 my $desc = " File '$path ' has expected modules" ;
225234 if ( my $got = delete $module_files {$path } ) {
235+ my $got = [ map +{%$_ }, @$got ];
236+ $_ -> {associated_pod } //= undef for @$got ;
226237
227238 # We may need to sort modules by name, I'm not sure if order is reliable.
228239 is_deeply $got , $self -> modules-> {$path }, $desc
0 commit comments