blib/lib/App/Prove/Elasticsearch/Searcher/ByName.pm

filter: Statementstmt 96.2% 77 / 80 Branchbran 71.4% 10 / 14 Conditioncond 88.8% 8 / 9 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 92.6% 113 / 122 CC 15 SCAR 17.2
CC
15
Cov
92%
filter
10.3
get_test_replay
5.0
_has_results
2.0
CRAP 5.6
« blib/lib/App/Prove/Elasticsearch/Parser.pm ↑ Summary blib/lib/App/Prove/Elasticsearch/Queue/Default.pm »
1 # ABSTRACT: Find out whether results exist for cases
2 # PODNAME: App::Prove::Elasticsearch::Searcher::ByName
3  
4 package App::Prove::Elasticsearch::Searcher::ByName;
5 3 $App::Prove::Elasticsearch::Searcher::ByName::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 Search::Elasticsearch();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Basename();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Cwd();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use List::Util 1.45 qw{uniq};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use App::Prove::Elasticsearch::Utils();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16 1 my ($class, $conf, $indexer) = @_;
17  
18 1 my $v = App::Prove::Elasticsearch::Utils::require_versioner($conf);
19 1 my $p = App::Prove::Elasticsearch::Utils::require_platformer($conf);
20  
21 1 return bless(
22 {
23 handle => Search::Elasticsearch->new(
24 nodes => "$conf->{'server.host'}:$conf->{'server.port'}",
25 request_timeout => 30
26 ),
27 index => $indexer->index,
28 versioner => $v,
29 platformer => $p,
30 },
31 $class
32 );
33  
34 }
35  
36 4 ▶sub filter {
Subroutine filter: called CC=10 SCAR=23.3
Pod documented
37 4 my ($self, @tests) = @_;
38  
39 4 ▶ return @tests unless $self->_has_results();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_results 0 4 4
40  
41 4 my $platz = &{\&{$self->{platformer} . "::get_platforms"}}();
42  
43 4 my @tests_filtered;
44 4 foreach my $test (@tests) {
45 4 $test = Cwd::abs_path($test);
46 4 my $tname = File::Basename::basename($test);
47 4 my $tversion = &{\&{$self->{versioner} . "::get_version"}}($test);
48 my %q = (
49 index => $self->{index},
50 4 body => {
51 query => {
52 bool => {
53 must => [
54 {
55 match => {
56 name => $tname,
57 }
58 },
59 {
60 match => {
61 version => $tversion,
62 }
63 },
64 ],
65 },
66 },
67 size => 1
68 },
69 );
70  
71 4 foreach my $plat (@$platz) {
72 push(
73 2 @{$q{body}{query}{bool}{must}},
74 {match => {platform => $plat}}
75 );
76 }
77  
78 4 my $docs = $self->{handle}->search(%q);
79  
80 #OK, check if this document we got back *actually* matched
81 4 ▶ if (!scalar(@{$docs->{hits}->{hits}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$docs->{"hits"}{"hits"};}) 0 4 4
82 0 push(@tests_filtered, $test);
83 0 next;
84 }
85 4 my $match = $docs->{hits}->{hits}->[0]->{_source};
86  
87 my @plats_match = (
88 (ref($match->{platform}) eq 'ARRAY')
89 0 ? @{$match->{platform}}
90 : ($match->{platform})
91 4 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
ref $match->{'platform'} eq 'ARRAY' ? : 0 4 4
92  
93 4 my $name_correct = $match->{name} eq $tname;
94 4 my $version_correct = $match->{version} eq $tversion;
95 4 my $plats_size_ok = scalar(@plats_match) == scalar(@$platz);
96 4 my $plats_are_same =
97 scalar(@plats_match) ==
98 scalar(uniq((@plats_match, @$platz)))
99 ; #XXX THIS IS WRONG, WHAT IF WE HAVE NO PLATZ
100 4 ▶ my $plats_correct = $plats_size_ok && $plats_are_same;
Condition66%2/3
$plats_size_ok && $plats_are_same
!ll&&!rl&&r
202
MC/DC50%1/2
$plats_size_ok && $plats_are_same
$plats_size_ok $plats_are_same
Truth table66%2/3
A && B
A= $plats_size_okB= $plats_are_same
ABresult
0X0
100
111
101  
102 4 ▶ if ($name_correct && $version_correct && $plats_correct) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name_correct and $version_correct and $plats_correct) 1 3 4
Condition100%6/6
$name_correct and $version_correct and $plats_correct
!ll&&!rl&&r
211
$name_correct and $version_correct
!ll&&!rl&&r
112
MC/DC100%3/3
$name_correct and $version_correct and $plats_correct
$name_correct $version_correct $plats_correct
Truth table100%4/4
A and B and C
A= $name_correctB= $version_correctC= $plats_correct
ABCresult
0XX0
10X0
1100
1111
103 1 print
104 "# Not going to execute $test, it already has results in elasticsearch for this version and platform\n";
105 1 next;
106 }
107  
108 3 push(@tests_filtered, $test);
109 }
110 4 return @tests_filtered;
111 }
112  
113 2 ▶sub get_test_replay {
Subroutine get_test_replay: called CC=5 SCAR=16.1
Pod documented
114 2 my ($self, $tversion, $platz, @tests) = @_;
115  
116 2 ▶ return @tests unless $self->_has_results();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_results 0 2 2
117  
118 2 my @tests_filtered;
119 2 foreach my $test (@tests) {
120 my %q = (
121 index => $self->{index},
122 4 body => {
123 query => {
124 query_string => {
125 query => qq{name: "$test" AND version: "$tversion"},
126 },
127 },
128 size => 1
129 },
130 );
131  
132 4 foreach my $plat (@$platz) {
133 2 $q{body}{query}{query_string}{query} .= qq{ AND platform: "$plat"};
134 }
135  
136 4 my $docs = $self->{handle}->search(%q);
137  
138 #OK, check if this document we got back *actually* matched
139 4 ▶ if (!scalar(@{$docs->{hits}->{hits}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$docs->{"hits"}{"hits"};}) 2 2 4
140 2 push(
141 @tests_filtered,
142 {name => $test, status => 'UNTESTED', body => ''}
143 );
144 2 next;
145 }
146 2 push(@tests_filtered, $docs->{hits}->{hits}->[0]->{_source});
147 }
148 2 return @tests_filtered;
149 }
150  
151 2 ▶sub _has_results {
Subroutine _has_results: called CC=2 SCAR=6.9
152 2 my ($self) = @_;
153  
154 my $res = $self->{handle}->search(
155 index => $self->{index},
156 2 body => {
157 query => {match_all => {}},
158 sort => {id => {order => "desc"}},
159 size => 1
160 }
161 );
162  
163 2 my $hits = $res->{hits}->{hits};
164 2 ▶ return 0 unless scalar(@$hits);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$hits 1 1 2
165  
166 1 return $res->{hits}->{total};
167 }
168  
169 3 1;
170  
171 __END__
« blib/lib/App/Prove/Elasticsearch/Parser.pm ↑ Summary blib/lib/App/Prove/Elasticsearch/Queue/Default.pm »