mirror of
https://github.com/inspec/inspec
synced 2024-11-25 22:20:27 +00:00
YAML reporter test fix (#6563)
* Fix for yaml reporter data, not matching empty values with spaces Signed-off-by: Nikita Mathur <nikita.mathur@chef.io> * Additional comment to document affecting fields Signed-off-by: Nikita Mathur <nikita.mathur@chef.io> --------- Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
parent
39e91eb0b3
commit
0ca221af5b
2 changed files with 13 additions and 49 deletions
38
test/fixtures/reporters/yaml_output_ruby3plus
vendored
38
test/fixtures/reporters/yaml_output_ruby3plus
vendored
|
@ -1,38 +0,0 @@
|
|||
---
|
||||
:platform:
|
||||
:name: fedora
|
||||
:release: '28'
|
||||
:target_id: ''
|
||||
:profiles:
|
||||
- :name: tests from t.rb
|
||||
:sha256: 9260af15d2b7568443df4d9d2556f773f425f92491c97eb1d201c535c7a9f5e0
|
||||
:title: tests from t.rb
|
||||
:supports: []
|
||||
:attributes: []
|
||||
:groups:
|
||||
- :id: t.rb
|
||||
:controls:
|
||||
- "(generated from t.rb:1 0aa70d93be7b0cf41b97a1363bb5e8b8)"
|
||||
:controls:
|
||||
- :id: "(generated from t.rb:1 0aa70d93be7b0cf41b97a1363bb5e8b8)"
|
||||
:title:
|
||||
:desc:
|
||||
:descriptions: []
|
||||
:impact: 0.5
|
||||
:refs: []
|
||||
:tags: {}
|
||||
:code: ''
|
||||
:source_location:
|
||||
:line: 89
|
||||
:ref: "/home/frezbo/git/work/ruby/inspec/lib/inspec/control_eval_context.rb"
|
||||
:waiver_data: {}
|
||||
:results:
|
||||
- :status: passed
|
||||
:code_desc: File /tmp should exist
|
||||
:run_time: 0.001313935
|
||||
:start_time: '2018-05-31T16:22:19+05:30'
|
||||
:resource_params: ''
|
||||
:resource_id: ''
|
||||
:statistics:
|
||||
:duration: 0.002678506
|
||||
:version: 2.1.83
|
|
@ -2,25 +2,27 @@ require "helper"
|
|||
require "inspec/reporters"
|
||||
|
||||
describe Inspec::Reporters::Yaml do
|
||||
RUBY3_PLUS = Gem.ruby_version >= Gem::Version.new("3.0")
|
||||
|
||||
let(:report) do
|
||||
data = YAML.load_file("test/fixtures/reporters/run_data.yml")
|
||||
Inspec::Reporters::Yaml.new({ run_data: data })
|
||||
end
|
||||
|
||||
# Match yaml reporter data
|
||||
# Strip leading white spaces from empty scalar values for testing
|
||||
# In Ruby, depending on its version, empty values are generated with or without leading spaces
|
||||
# This was affecting the title: and desc: fields
|
||||
def strip_white_spaces_from_empty_values(output)
|
||||
output.gsub(/:\s*\n/, ":\n")
|
||||
end
|
||||
|
||||
describe "#render" do
|
||||
it "confirm render output" do
|
||||
if ( windows? || darwin? ) && RUBY3_PLUS
|
||||
# On Ruby 3+, empty scalar values are generated without a trailing space
|
||||
# this affects the title: and desc: fields
|
||||
output = File.read("test/fixtures/reporters/yaml_output_ruby3plus")
|
||||
else
|
||||
output = File.read("test/fixtures/reporters/yaml_output")
|
||||
end
|
||||
|
||||
output = File.read("test/fixtures/reporters/yaml_output")
|
||||
report.render
|
||||
_(report.rendered_output).must_equal output
|
||||
stripped_rendered_output = strip_white_spaces_from_empty_values(report.rendered_output)
|
||||
stripped_output = strip_white_spaces_from_empty_values(output)
|
||||
# Match successful parsing of YAML reporter data
|
||||
_(stripped_rendered_output).must_equal stripped_output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue