Class: CemAcpt::Scan::Result
- Inherits:
-
Object
- Object
- CemAcpt::Scan::Result
- Defined in:
- lib/cem_acpt/scan/result.rb
Overview
Normalized scan result. Wraps the JSON payload returned by the on-node scan daemon and exposes the bits the runner needs: the score the daemon reported (scanner-native pass-rate, 0-100), the pass/fail decision against the configured threshold, and a status code compatible with TestRunner::TestResults so the existing result-aggregation plumbing doesn’t have to grow a new branch.
Status semantics: 200 if ‘score >= threshold`, 1 otherwise. This makes Result look-alike enough to Goss::Api::ActionResponse for the runner’s ‘process_test_results` loop to treat it uniformly.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#scanner ⇒ Object
readonly
Returns the value of attribute scanner.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#test_case ⇒ Object
readonly
Returns the value of attribute test_case.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
-
#fail? ⇒ Boolean
(also: #error?)
True if the score did not meet the threshold.
-
#initialize(test_case:, scanner:, profile:, threshold:, body:) ⇒ Result
constructor
A new instance of Result.
-
#pass? ⇒ Boolean
(also: #success?)
True if the score met the threshold.
-
#status ⇒ Integer
(also: #http_status)
Conforms to the contract TestRunner::Runner#process_test_results uses to decide the run’s exit code.
-
#to_h ⇒ Hash
The full normalized result, suitable for ‘to_json`.
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(test_case:, scanner:, profile:, threshold:, body:) ⇒ Result
Returns a new instance of Result.
27 28 29 30 31 32 33 34 |
# File 'lib/cem_acpt/scan/result.rb', line 27 def initialize(test_case:, scanner:, profile:, threshold:, body:) @test_case = test_case @scanner = scanner.to_sym @profile = profile @threshold = threshold.to_f @body = body || {} @score = (@body['score'] || @body[:score] || 0.0).to_f end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
18 19 20 |
# File 'lib/cem_acpt/scan/result.rb', line 18 def body @body end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
18 19 20 |
# File 'lib/cem_acpt/scan/result.rb', line 18 def profile @profile end |
#scanner ⇒ Object (readonly)
Returns the value of attribute scanner.
18 19 20 |
# File 'lib/cem_acpt/scan/result.rb', line 18 def scanner @scanner end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
18 19 20 |
# File 'lib/cem_acpt/scan/result.rb', line 18 def score @score end |
#test_case ⇒ Object (readonly)
Returns the value of attribute test_case.
18 19 20 |
# File 'lib/cem_acpt/scan/result.rb', line 18 def test_case @test_case end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
18 19 20 |
# File 'lib/cem_acpt/scan/result.rb', line 18 def threshold @threshold end |
Instance Method Details
#fail? ⇒ Boolean Also known as: error?
Returns true if the score did not meet the threshold.
43 44 45 |
# File 'lib/cem_acpt/scan/result.rb', line 43 def fail? !pass? end |
#pass? ⇒ Boolean Also known as: success?
Returns true if the score met the threshold.
37 38 39 |
# File 'lib/cem_acpt/scan/result.rb', line 37 def pass? @score >= @threshold end |
#status ⇒ Integer Also known as: http_status
Conforms to the contract TestRunner::Runner#process_test_results uses to decide the run’s exit code.
51 52 53 |
# File 'lib/cem_acpt/scan/result.rb', line 51 def status pass? ? 200 : 1 end |
#to_h ⇒ Hash
Returns The full normalized result, suitable for ‘to_json`.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cem_acpt/scan/result.rb', line 57 def to_h { test_case: @test_case, scanner: @scanner, profile: @profile, score: @score, threshold: @threshold, passed_count: counts(:passed_count), failed_count: counts(:failed_count), not_applicable_count: counts(:not_applicable_count), error_count: counts(:error_count), rules: @body['rules'] || @body[:rules] || [], pass: pass?, } end |
#to_json(*args) ⇒ Object
73 74 75 |
# File 'lib/cem_acpt/scan/result.rb', line 73 def to_json(*args) to_h.to_json(*args) end |
#to_s ⇒ Object Also known as: inspect
77 78 79 |
# File 'lib/cem_acpt/scan/result.rb', line 77 def to_s "<#{self.class.name} test_case=#{@test_case} scanner=#{@scanner} score=#{@score} threshold=#{@threshold} pass=#{pass?}>" end |