« blib/lib/App/Prove/Elasticsearch/Queue/Rabbit.pm
↑ Summary
blib/lib/App/Prove/Elasticsearch/Indexer.pm »
| 1 | # ABSTRACT: Index, create and retrieve test plans for use later | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: App::Prove::Elasticsearch::Planner::Default | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package App::Prove::Elasticsearch::Planner::Default; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | $App::Prove::Elasticsearch::Planner::Default::VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use App::Prove::Elasticsearch::Utils(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Search::Elasticsearch(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use File::Basename(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Cwd(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use List::Util 1.45 qw{uniq}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | our $index = 'testplans'; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | our $e; # for caching | |||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | our $last_id; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | our $max_query_size = 1000; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | sub check_index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_index: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | my ($conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | my $port = $conf->{'server.port'} ? ':' . $conf->{'server.port'} : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | die "server must be specified" unless $conf->{'server.host'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | die("port must be specified") unless $port; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my $serveraddress = "$conf->{'server.host'}$port"; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | $e //= Search::Elasticsearch->new( | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$App::Prove::Elasticsearch::Planner::Default::e //= "Search::Elasticsearch"->new("nodes", $serveraddress, "request_timeout", 30)
MC/DC0%0/2
$App::Prove::Elasticsearch::Planner::Default::e //= "Search::Elasticsearch"->new("nodes", $serveraddress, "request_timeout", 30)
$App::Prove::Elasticsearch::Planner::Default::e
"Search::Elasticsearch"->new("nodes", $serveraddress, "request_timeout", 30)
Truth table66%2/3
A //= B
A= $App::Prove::Elasticsearch::Planner::Default::eB= "Search::Elasticsearch"->new("nodes", $serveraddress, "request_timeout", 30)
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | nodes => $serveraddress, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | request_timeout => 30 | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | #XXX for debugging | ||||||||||||||||||||||||||||||||||||||||||
| 36 | #$e->indices->delete( index => $index ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | if (!$e->indices->exists(index => $index)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $e->indices->create( | |||||||||||||||||||||||||||||||||||||||||
| 40 | index => $index, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | body => { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | index => { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | number_of_shards => "3", | ||||||||||||||||||||||||||||||||||||||||||
| 44 | number_of_replicas => "2", | ||||||||||||||||||||||||||||||||||||||||||
| 45 | similarity => {default => {type => "classic"}} | ||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | analysis => { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | analyzer => { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | default => { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | type => "custom", | ||||||||||||||||||||||||||||||||||||||||||
| 51 | tokenizer => "whitespace", | ||||||||||||||||||||||||||||||||||||||||||
| 52 | filter => [ | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 'lowercase', 'std_english_stop', 'custom_stop' | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | filter => { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | std_english_stop => { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | type => "stop", | ||||||||||||||||||||||||||||||||||||||||||
| 60 | stopwords => "_english_" | ||||||||||||||||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | custom_stop => { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | type => "stop", | ||||||||||||||||||||||||||||||||||||||||||
| 64 | stopwords => [ "test", "ok", "not" ] | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | mappings => { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | testplan => { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | properties => { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | id => {type => "integer"}, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | created => { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | type => "date", | ||||||||||||||||||||||||||||||||||||||||||
| 74 | format => "yyyy-MM-dd HH:mm:ss" | ||||||||||||||||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | creator => { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | type => "text", | ||||||||||||||||||||||||||||||||||||||||||
| 78 | analyzer => "default", | ||||||||||||||||||||||||||||||||||||||||||
| 79 | fielddata => "true", | ||||||||||||||||||||||||||||||||||||||||||
| 80 | term_vector => "yes", | ||||||||||||||||||||||||||||||||||||||||||
| 81 | similarity => "classic", | ||||||||||||||||||||||||||||||||||||||||||
| 82 | fields => {keyword => {type => "keyword"}} | ||||||||||||||||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | version => { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | type => "text", | ||||||||||||||||||||||||||||||||||||||||||
| 86 | analyzer => "default", | ||||||||||||||||||||||||||||||||||||||||||
| 87 | fielddata => "true", | ||||||||||||||||||||||||||||||||||||||||||
| 88 | term_vector => "yes", | ||||||||||||||||||||||||||||||||||||||||||
| 89 | similarity => "classic", | ||||||||||||||||||||||||||||||||||||||||||
| 90 | fields => {keyword => {type => "keyword"}} | ||||||||||||||||||||||||||||||||||||||||||
| 91 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | platforms => { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | type => "text", | ||||||||||||||||||||||||||||||||||||||||||
| 94 | analyzer => "default", | ||||||||||||||||||||||||||||||||||||||||||
| 95 | fielddata => "true", | ||||||||||||||||||||||||||||||||||||||||||
| 96 | term_vector => "yes", | ||||||||||||||||||||||||||||||||||||||||||
| 97 | similarity => "classic", | ||||||||||||||||||||||||||||||||||||||||||
| 98 | fields => {keyword => {type => "keyword"}} | ||||||||||||||||||||||||||||||||||||||||||
| 99 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | tests => { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | type => "text", | ||||||||||||||||||||||||||||||||||||||||||
| 102 | analyzer => "default", | ||||||||||||||||||||||||||||||||||||||||||
| 103 | fielddata => "true", | ||||||||||||||||||||||||||||||||||||||||||
| 104 | term_vector => "yes", | ||||||||||||||||||||||||||||||||||||||||||
| 105 | similarity => "classic", | ||||||||||||||||||||||||||||||||||||||||||
| 106 | fields => {keyword => {type => "keyword"}} | ||||||||||||||||||||||||||||||||||||||||||
| 107 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | pairwise => {type => "boolean"}, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | name => { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | type => "text", | ||||||||||||||||||||||||||||||||||||||||||
| 111 | analyzer => "default", | ||||||||||||||||||||||||||||||||||||||||||
| 112 | fielddata => "true", | ||||||||||||||||||||||||||||||||||||||||||
| 113 | term_vector => "yes", | ||||||||||||||||||||||||||||||||||||||||||
| 114 | similarity => "classic", | ||||||||||||||||||||||||||||||||||||||||||
| 115 | fields => {keyword => {type => "keyword"}} | ||||||||||||||||||||||||||||||||||||||||||
| 116 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub find_test_paths { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_test_paths: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my (@tests) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return map { "t/$_" } @tests; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | ▶ | sub get_plan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_plan: called CC=17 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | my (%options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | die "A version must be passed." unless $options{version}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | my %q = ( | ||||||||||||||||||||||||||||||||||||||||||
| 138 | index => $index, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | body => { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | query => { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | bool => { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | must => [ | ||||||||||||||||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | match => { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | version => $options{version}, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | ], | |||||||||||||||||||||||||||||||||||||||||
| 149 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | size => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 152 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | push(@{$q{body}{query}{bool}{must}}, {match => {name => $options{name}}}) | |||||||||||||||||||||||||||||||||||||||||
| 156 | 8 | ▶ | if $options{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | foreach my $plat (@{$options{platforms}}) { | |||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | push(@{$q{body}{query}{bool}{must}}, {match => {platforms => $plat}}); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | my $docs = $e->search(%q); | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | return 0 | ||||||||||||||||||||||||||||||||||||||||||
| 165 | unless ref $docs eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 166 | && ref $docs->{hits} eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 8 | ▶ | && ref $docs->{hits}->{hits} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $docs eq "HASH" and ref $docs->{"hits"} eq "HASH" and ref $docs->{"hits"}{"hits"} eq "ARRAY"
ref $docs eq "HASH" and ref $docs->{"hits"} eq "HASH"
MC/DC33%1/3
ref $docs eq "HASH" and ref $docs->{"hits"} eq "HASH" and ref $docs->{"hits"}{"hits"} eq "ARRAY"
ref $docs eq "HASH"
ref $docs->{"hits"} eq "HASH"
ref $docs->{"hits"}{"hits"} eq "ARRAY"
Truth table50%2/4
A and B and C
A= ref $docs eq "HASH"B= ref $docs->{"hits"} eq "HASH"C= ref $docs->{"hits"}{"hits"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 7 | ▶ | return 0 unless scalar(@{$docs->{hits}->{hits}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | my $match = $docs->{hits}->{hits}->[0]->{_source}; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | my @plats_match = ( | ||||||||||||||||||||||||||||||||||||||||||
| 172 | (ref($match->{platforms}) eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ? @{$match->{platforms}} | |||||||||||||||||||||||||||||||||||||||||
| 174 | : ($match->{platforms}) | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | my $name_correct = | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | ▶ | !$options{name} || ($match->{name} // '') eq ($options{name} // ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition71%5/7
!$options{'name'} || ($match->{'name'} // '') eq ($options{'name'} // '')
$match->{"name"} // ""
$options{"name"} // ""
MC/DC0%0/2
!$options{'name'} || ($match->{'name'} // '') eq ($options{'name'} // '')
!$options{'name'}
$match->{"name"}
MC/DC0%0/1
$options{"name"} // ""
$options{"name"}
Truth table66%2/3
not(A) || B
A= !$options{'name'}B= $match->{"name"}
Truth table50%1/2
A
A= $options{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | my $version_correct = $match->{version} eq $options{version}; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 6 | my $plats_size_ok = scalar(@plats_match) == scalar(@{$options{platforms}}); | |||||||||||||||||||||||||||||||||||||||||
| 181 | my $plats_are_same = | ||||||||||||||||||||||||||||||||||||||||||
| 182 | scalar(@plats_match) == | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 6 | scalar(uniq((@plats_match, @{$options{platforms}}))); | |||||||||||||||||||||||||||||||||||||||||
| 184 | my $plats_correct = | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | ▶ | !scalar(@{$options{platforms}}) || ($plats_size_ok && $plats_are_same); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
!scalar(@{$options{'platforms'};}) || $plats_size_ok && $plats_are_same
$plats_size_ok and $plats_are_same
MC/DC100%3/3
!scalar(@{$options{'platforms'};}) || $plats_size_ok && $plats_are_same
!scalar(@{$options{'platforms'};})
$plats_size_ok
$plats_are_same
Truth table100%4/4
not(A) || B and C
A= !scalar(@{$options{'platforms'};})B= $plats_size_okC= $plats_are_same
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | $match->{id} = $docs->{hits}->{hits}->[0]->{_id}; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 6 | ▶ | return $match if ($name_correct && $version_correct && $plats_correct); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$name_correct and $version_correct and $plats_correct
$name_correct and $version_correct
MC/DC66%2/3
$name_correct and $version_correct and $plats_correct
$name_correct
$version_correct
$plats_correct
Truth table75%3/4
A and B and C
A= $name_correctB= $version_correctC= $plats_correct
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub get_plans { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_plans: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my (%options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | die "A version must be passed." unless $options{version}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my %q = ( | |||||||||||||||||||||||||||||||||||||||||
| 199 | index => $index, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | body => { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | query => { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | query_string => { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | query => qq{version: "$options{version}"}, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 206 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | $q{body}{query}{query_string}{query} .= qq{ AND name: "$options{name}" } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if $options{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | foreach my $plat (@{$options{platforms}}) { | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $q{body}{query}{query_string}{query} .= qq{ AND platforms: "$plat" }; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return App::Prove::Elasticsearch::Utils::do_paginated_query( | |||||||||||||||||||||||||||||||||||||||||
| 216 | $e, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | $max_query_size, %q | ||||||||||||||||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub get_plans_needing_work { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_plans_needing_work: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my (%options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | die "Can't find plans needing work without case autodiscover configured!" | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | unless $options{searcher}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my @plans; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $docs = get_plans(%options); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | return () unless ref $docs eq 'ARRAY' && scalar(@$docs); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $docs eq "ARRAY" and scalar @$docs
MC/DC0%0/1
ref $docs eq "ARRAY" and scalar @$docs
ref $docs eq "ARRAY"
Truth table0%0/2
A
A= ref $docs eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | foreach my $doc (@$docs) { | |||||||||||||||||||||||||||||||||||||||||
| 232 | next | ||||||||||||||||||||||||||||||||||||||||||
| 233 | unless ref $doc->{_source}->{tests} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | && scalar(@{$doc->{_source}->{tests}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $doc->{"_source"}{"tests"} eq "ARRAY" and scalar @{$doc->{"_source"}{"tests"};}
MC/DC0%0/1
ref $doc->{"_source"}{"tests"} eq "ARRAY" and scalar @{$doc->{"_source"}{"tests"};}
ref $doc->{"_source"}{"tests"} eq "ARRAY"
Truth table0%0/2
A
A= ref $doc->{"_source"}{"tests"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | my @tests = $options{searcher} | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ->filter(find_test_paths(@{$doc->{_source}->{tests}})); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $doc->{_source}->{tests} = \@tests; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | push(@plans, $doc->{_source}) if @tests; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | return \@plans; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | sub get_plan_status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_plan_status: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | my ($plan, $searcher) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | die "Can't discover plan status without case autodiscover configured!" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | unless $searcher; | ||||||||||||||||||||||||||||||||||||||||||
| 248 | return $searcher->get_test_replay( | ||||||||||||||||||||||||||||||||||||||||||
| 249 | $plan->{version}, $plan->{platforms}, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | @{$plan->{tests}} | |||||||||||||||||||||||||||||||||||||||||
| 251 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 5 | ▶ | sub add_plan_to_index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_plan_to_index: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 5 | my ($plan) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | ▶ | if ($plan->{noop}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | print "Nothing to do!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | ▶ | return _update_plan($plan) if $plan->{update}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | ▶ | die "check_index not run, ES object not defined!" unless $e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | my $idx = App::Prove::Elasticsearch::Utils::get_last_index($e, $index); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | $idx++; | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | $e->index( | |||||||||||||||||||||||||||||||||||||||||
| 269 | index => $index, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | id => $idx, | ||||||||||||||||||||||||||||||||||||||||||
| 271 | type => 'testplan', | ||||||||||||||||||||||||||||||||||||||||||
| 272 | body => $plan, | ||||||||||||||||||||||||||||||||||||||||||
| 273 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | my $doc_exists = | |||||||||||||||||||||||||||||||||||||||||
| 276 | $e->exists(index => $index, type => 'testplan', id => $idx); | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | my $pn = $plan->{'name'} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plan->{"name"} // ""
MC/DC0%0/1
$plan->{"name"} // ""
$plan->{"name"}
Truth table50%1/2
A
A= $plan->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | if (!defined($doc_exists) || !int($doc_exists)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $doc_exists and int $doc_exists
MC/DC50%1/2
defined $doc_exists and int $doc_exists
defined $doc_exists
int $doc_exists
Truth table66%2/3
A and B
A= defined $doc_existsB= int $doc_exists
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | print "Failed to Index $pn, could find no record with ID $idx\n"; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | print "Successfully Indexed plan $pn with result ID $idx\n"; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | ▶ | sub _update_plan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_plan: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | my ($plan) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | #handle adding new tests, then subtract | ||||||||||||||||||||||||||||||||||||||||||
| 292 | my @tests_merged = | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | (@{$plan->{tests}}, @{$plan->{update}->{addition}->{tests}}); | |||||||||||||||||||||||||||||||||||||||||
| 294 | @tests_merged = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | my $subj = $_; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 6 | !grep { $_ eq $subj } @{$plan->{update}->{subtraction}->{tests}} | |||||||||||||||||||||||||||||||||||||||||
| 297 | } @tests_merged; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | my $res = $e->update( | ||||||||||||||||||||||||||||||||||||||||||
| 300 | index => $index, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | id => $plan->{id}, | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | type => 'testplan', | |||||||||||||||||||||||||||||||||||||||||
| 303 | body => { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | doc => { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | tests => \@tests_merged, | ||||||||||||||||||||||||||||||||||||||||||
| 306 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | ▶ | print "Updated tests in plan #$plan->{id}\n" if $res->{result} eq 'updated'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | ▶ | if (!grep { $res->{result} eq $_ } qw{updated noop}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | ||||||||||||||||||||||||||||||||||||||||||
| 313 | "Something went wrong associating cases to document $plan->{id}!\n$res->{result}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | print "Successfully Updated plan #$plan->{id}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 3 | ▶ | sub make_plan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_plan: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 3 | my (%options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | die "check_index not run, ES object not defined!" unless $e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | my %out = %options; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | ▶ | $out{pairwise} = $out{pairwise} ? "true" : "false"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | delete $out{show}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 2 | delete $out{prompt}; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 2 | delete $out{allplatforms}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 2 | delete $out{exts}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | delete $out{recurse}; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | delete $out{name} unless $out{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | $out{noop} = 1 unless scalar(@{$out{tests}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | return \%out; | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 3 | ▶ | sub make_plan_update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_plan_update: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 3 | my ($existing, %out) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | ▶ | die "check_index not run, ES object not defined!" unless $e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | #TODO be sure to do the right thing w pairwise testing (dole out tests appropriately) | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | my $adds = {}; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | my $subs = {}; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | foreach my $okey (@{$out{tests}}) { | |||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | push(@{$adds->{tests}}, $okey) | |||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | ▶ | if !grep { $_ eq $okey } @{$existing->{tests}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | foreach my $ekey (@{$existing->{tests}}) { | |||||||||||||||||||||||||||||||||||||||||
| 351 | 2 | ▶ | push(@{$subs->{tests}}, $ekey) if !grep { $_ eq $ekey } @{$out{tests}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 2 | ▶ | if (!scalar(keys(%$adds)) && !scalar(keys(%$subs))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar keys %$adds or scalar keys %$subs
MC/DC50%1/2
scalar keys %$adds or scalar keys %$subs
scalar keys %$adds
scalar keys %$subs
Truth table66%2/3
A or B
A= scalar keys %$addsB= scalar keys %$subs
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | $existing->{noop} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | return $existing; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | $existing->{update} = {addition => $adds, subtraction => $subs}; | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | return $existing; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | __END__ | ||||||||||||||||||||||||||||||||||||||||||