Add test for query and minimum_should_match for consistency

This commit is contained in:
Brad Lhotsky 2021-08-31 17:41:12 -07:00
parent 5257a66d11
commit cc2d07e3e2
1 changed files with 56 additions and 0 deletions

56
t/01-query.t Normal file
View File

@ -0,0 +1,56 @@
#!perl
#
use strict;
use warnings;
use App::ElasticSearch::Utilities::Query;
use CLI::Helpers qw(:output);
use Data::Dumper;
use Test::More;
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
my $q = App::ElasticSearch::Utilities::Query->new();
# Add a single boolean
$q->add_bool( must => { term => { foo => 'bar' } } );
my $expected = {
'bool' => {
'must' => [
{
'term' => {
'foo' => 'bar'
}
}
]
}
};
check_query('simple must');
# Add a second parameter
$q->add_bool( must => { term => { bar => 'baz' } } );
push @{ $expected->{bool}{must} }, { term => { bar => 'baz' } };
check_query('second must parameter');
my $should = [
{ term => { a => 'b' } },
{ term => { c => 'd' } }
];
$q->add_bool( should => $_ ) for @{ $should };
$expected->{bool}{should} = $should;
check_query('should parameters');
# Set minimum should match
$q->minimum_should_match(1);
$expected->{bool}{minimum_should_match} = 1;
check_query('minimum_should_match');
done_testing();
sub check_query {
my ($name) = @_;
is_deeply( $q->query, $expected, $name)
or diag( Dumper $q->query );
}