App-Prove-Plugin-Elasticsearch
view release on metacpan or search on metacpan
lib/App/Prove/Elasticsearch/Planner/Default.pm view on Meta::CPAN
@{$plan->{tests}}
);
}
sub add_plan_to_index {
my ($plan) = @_;
if ($plan->{noop}) {
print "Nothing to do!\n";
return 0;
}
return _update_plan($plan) if $plan->{update};
die "check_index not run, ES object not defined!" unless $e;
my $idx = App::Prove::Elasticsearch::Utils::get_last_index($e, $index);
$idx++;
$e->index(
index => $index,
id => $idx,
type => 'testplan',
body => $plan,
);
my $doc_exists =
$e->exists(index => $index, type => 'testplan', id => $idx);
my $pn = $plan->{'name'} // '';
if (!defined($doc_exists) || !int($doc_exists)) {
print "Failed to Index $pn, could find no record with ID $idx\n";
return 1;
}
print "Successfully Indexed plan $pn with result ID $idx\n";
return 0;
}
sub _update_plan {
my ($plan) = @_;
#handle adding new tests, then subtract
my @tests_merged =
(@{$plan->{tests}}, @{$plan->{update}->{addition}->{tests}});
@tests_merged = grep {
my $subj = $_;
!grep { $_ eq $subj } @{$plan->{update}->{subtraction}->{tests}}
} @tests_merged;
my $res = $e->update(
index => $index,
id => $plan->{id},
type => 'testplan',
body => {
doc => {
tests => \@tests_merged,
},
}
);
print "Updated tests in plan #$plan->{id}\n" if $res->{result} eq 'updated';
if (!grep { $res->{result} eq $_ } qw{updated noop}) {
print
"Something went wrong associating cases to document $plan->{id}!\n$res->{result}\n";
return 1;
}
print "Successfully Updated plan #$plan->{id}\n";
return 0;
}
sub make_plan {
my (%options) = @_;
die "check_index not run, ES object not defined!" unless $e;
my %out = %options;
$out{pairwise} = $out{pairwise} ? "true" : "false";
delete $out{show};
delete $out{prompt};
delete $out{allplatforms};
delete $out{exts};
delete $out{recurse};
delete $out{name} unless $out{name};
$out{noop} = 1 unless scalar(@{$out{tests}});
return \%out;
}
sub make_plan_update {
my ($existing, %out) = @_;
die "check_index not run, ES object not defined!" unless $e;
#TODO be sure to do the right thing w pairwise testing (dole out tests appropriately)
my $adds = {};
my $subs = {};
foreach my $okey (@{$out{tests}}) {
push(@{$adds->{tests}}, $okey)
if !grep { $_ eq $okey } @{$existing->{tests}};
}
foreach my $ekey (@{$existing->{tests}}) {
push(@{$subs->{tests}}, $ekey) if !grep { $_ eq $ekey } @{$out{tests}};
}
if (!scalar(keys(%$adds)) && !scalar(keys(%$subs))) {
$existing->{noop} = 1;
return $existing;
}
$existing->{update} = {addition => $adds, subtraction => $subs};
return $existing;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
lib/App/Prove/Elasticsearch/Planner/Default.pm view on Meta::CPAN
=head2 check_index($conf)
Constructs a new Search::Elasticsearch object using the provided configuration file data, and stores it for use by other functions.
It then checks the index, and returns false or the object depending on the index status.
Creates the index if it does not exist.
=head1 METHODS
All methods below die if the ES handle hasn't been defined by check_index.
=head2 find_test_paths(@tests)
Resolves the paths to your tests. By default this is the t/ directory under your current directory.
See SUBCLASSING for more information.
Returns ARRAY
=head2 get_plan
Get the plan most closely matching the description from Elasticsearch.
=head2 get_plans(%options)
Get all the plans matching the version/platforms passed.
Input hash specification:
=over 4
=item B<version> - Required. Version of the software to be tested.
=item B<name> - Optional. Name of the test plan used (if any).
=item B<platforms> - Optional. ARRAYREF of platform names to be tested upon. Must match all provided platforms.
=back
=head2 get_plans_needing_work(%options)
Ask which of the plans in ES fits the provided specification.
Input hash specification:
=over 4
=item B<searcher> - Required. App::Prove::Elasticsearch::Searcher::* object.
=item All other items should be the same as in get_plans.
=back
=head2 get_plan_status(plan)
Gets the status of the tests to be run in the provided plan, regardless of if the plan even exists.
=head2 add_plan_to_index($plan)
Add or update a test plan.
Dies if the plan cannot be added/updated.
Returns 1 in the event of failure.
=head2 make_plan(%plan)
Build a test plan ready to be indexed, and return it.
Takes a hash describing the plan to be created and then mangles it to fit in openstack.
=head2 make_plan_update($existing_plan,%plan)
Build an update statement to modify an indexed plan. The existing plan and a hash describing the modifications to the plan are required.
=head1 AUTHOR
George S. Baugh <teodesian@cpan.org>
=head1 SOURCE
The development version is on github at L<http://https://github.com/teodesian/App-Prove-Elasticsearch>
and may be cloned from L<git://https://github.com/teodesian/App-Prove-Elasticsearch.git>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by George S. Baugh.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 2.336 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )