@@ -50,49 +50,46 @@ def output_summary
50
50
puts @summary [ :status ] . to_json if @json_counts
51
51
end
52
52
53
- # rubocop:disable Metrics/AbcSize
54
- # rubocop:disable Metrics/PerceivedComplexity
55
- # rubocop:disable Metrics/CyclomaticComplexity
56
53
def results_meet_threshold?
57
54
raise 'Please provide threshold as a yaml file or inline yaml' unless @threshold_provided
58
55
59
56
compliance = true
60
57
failure = [ ]
61
- max = @threshold [ 'compliance.max' ]
62
- min = @threshold [ 'compliance.min' ]
63
- if max != -1 and @summary [ :compliance ] > max
64
- compliance = false
65
- failure << expected_to_string ( '' , 'compliance' , 'max' , max , @summary [ :compliance ] )
66
- end
67
- if min != -1 and @summary [ :compliance ] < min
68
- compliance = false
69
- failure << expected_to_string ( '' , 'compliance' , 'min' , min , @summary [ :compliance ] )
70
- end
71
- status = @summary [ :status ]
58
+ failure << check_max_compliance ( @threshold [ 'compliance.max' ] , @summary [ :compliance ] , '' , 'compliance' )
59
+ failure << check_min_compliance ( @threshold [ 'compliance.min' ] , @summary [ :compliance ] , '' , 'compliance' )
60
+
72
61
BUCKETS . each do |bucket |
73
62
TALLYS . each do |tally |
74
- max = @threshold [ "#{ bucket } .#{ tally } .max" ]
75
- min = @threshold [ "#{ bucket } .#{ tally } .min" ]
76
- if max != -1 and status [ bucket ] [ tally ] > max
77
- compliance = false
78
- failure << expected_to_string ( bucket , tally , 'max' , max , status [ bucket ] [ tally ] )
79
- end
80
- if min != -1 and status [ bucket ] [ tally ] < min
81
- compliance = false
82
- failure << expected_to_string ( bucket , tally , 'min' , min , status [ bucket ] [ tally ] )
83
- end
63
+ failure << check_min_compliance ( @threshold [ "#{ bucket } .#{ tally } .min" ] , @summary [ :status ] [ bucket ] [ tally ] , bucket , tally )
64
+ failure << check_max_compliance ( @threshold [ "#{ bucket } .#{ tally } .max" ] , @summary [ :status ] [ bucket ] [ tally ] , bucket , tally )
84
65
end
85
66
end
86
- puts failure . join ( "\n " ) unless compliance
87
- puts "Overall compliance threshold of #{ @threshold [ 'compliance.min' ] } \% met. Current compliance at #{ @summary [ :compliance ] } \% " if compliance
67
+
68
+ failure . reject! ( &:nil? )
69
+ compliance = false if failure . length . positive?
70
+ output ( compliance , failure )
88
71
compliance
89
72
end
90
- # rubocop:enable Metrics/AbcSize
91
- # rubocop:enable Metrics/PerceivedComplexity
92
- # rubocop:enable Metrics/CyclomaticComplexity
93
73
94
74
private
95
75
76
+ def check_min_compliance ( min , data , bucket , tally )
77
+ expected_to_string ( bucket , tally , 'min' , min , data ) if min != -1 and data < min
78
+ end
79
+
80
+ def check_max_compliance ( max , data , bucket , tally )
81
+ expected_to_string ( bucket , tally , 'max' , max , data ) if max != -1 and data > max
82
+ end
83
+
84
+ def output ( passed_threshold , what_failed )
85
+ if passed_threshold
86
+ puts "Overall compliance threshold of #{ @threshold [ 'compliance.min' ] } \% met. Current compliance at #{ @summary [ :compliance ] } \% "
87
+ else
88
+ puts 'Compliance threshold was not met: '
89
+ puts what_failed . join ( "\n " )
90
+ end
91
+ end
92
+
96
93
def expected_to_string ( bucket , tally , maxmin , value , got )
97
94
return "Expected #{ bucket } .#{ tally } .#{ maxmin } :#{ value } got:#{ got } " unless bucket . empty? || bucket . nil?
98
95
0 commit comments