App-Prove-Plugin-Elasticsearch
view release on metacpan or search on metacpan
lib/App/Prove/Elasticsearch/Planner/Default.pm view on Meta::CPAN
$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
App::Prove::Elasticsearch::Planner::Default - Index, create and retrieve test plans for use later
=head1 VERSION
version 0.001
=head1 SUBCLASSING
The most useful reason to subclass the planner is to tell the system where to find named tests stored in a plan.
For a variety of good reasons, we do not store paths to tests in plans.
You are expected to alter find_test_paths() to suit your needs if the default behavior (search t/) is insufficient.
=head1 VARIABLES
=head2 index (STRING)
( run in 0.910 second using v1.01-cache-2.11-cpan-6aa56a78535 )