mirror of
https://github.com/inspec/inspec
synced 2024-12-28 05:53:14 +00:00
a1129f9efc
In https://github.com/inspec/inspec/issues/4936 the issue was reported that naming an input the same as a control caused an unexpected failure. In that particular case, the naming was a result of a pre-waivers workaround which is no longer necessary, but ultimately a breakage of that name clash is an unexpected occurrance. Due to how inputs are named and registered, `__apply_waivers` thinks that an object is a waiver that is not a waiver and tries to process it. On the micro level, it breaks when trying to pass a variable to a string as if it were a Hash. It is imperative that we preserve 100% of the current featureset, pass our tests, and fix this edge case along with new test coverage for the failure. This PR updates the code to do a slightly more elegant and small ‘waiver check’ to stop the namespace clash from breaking our code. Signed-off-by: Nick Schwaderer <nschwaderer@chef.io>
82 lines
2.5 KiB
Ruby
82 lines
2.5 KiB
Ruby
require "functional/helper"
|
|
require "rexml/document"
|
|
|
|
describe "inspec exec with junit formatter" do
|
|
include FunctionalHelper
|
|
|
|
parallelize_me!
|
|
|
|
it "can execute a simple file with the junit formatter" do
|
|
out = inspec("exec " + example_control + " --reporter junit --no-create-lockfile")
|
|
|
|
# TODO: rexml is about as slow as you can go. Use nokogiri
|
|
doc = REXML::Document.new(out.stdout)
|
|
_(doc.has_elements?).must_equal true
|
|
|
|
_(out.stderr).must_equal ""
|
|
|
|
skip_windows!
|
|
assert_exit_code 0, out
|
|
end
|
|
|
|
it "can execute the profile with the junit formatter" do
|
|
out = inspec("exec " + complete_profile + " --reporter junit --no-create-lockfile")
|
|
|
|
# TODO: _never_ use rexml. Anything else is guaranteed faster
|
|
doc = REXML::Document.new(out.stdout)
|
|
_(doc.has_elements?).must_equal true
|
|
|
|
_(out.stderr).must_equal ""
|
|
|
|
assert_exit_code 0, out
|
|
end
|
|
|
|
describe "execute a profile with junit formatting" do
|
|
let(:doc) { REXML::Document.new(inspec("exec " + example_profile + " --reporter junit --no-create-lockfile").stdout) }
|
|
|
|
describe "the document" do
|
|
it "has only one testsuite" do
|
|
_(doc.elements.to_a("//testsuite").length).must_equal 1
|
|
end
|
|
end
|
|
describe "the test suite" do
|
|
let(:suite) { doc.elements.to_a("//testsuites/testsuite").first }
|
|
|
|
it "must have 4 testcase children" do
|
|
_(suite.elements.to_a("//testcase").length).must_equal 4
|
|
end
|
|
|
|
it "has the tests attribute with 4 total tests" do
|
|
_(suite.attribute("tests").value).must_equal "4"
|
|
end
|
|
|
|
it "has the failures attribute with 0 total tests" do
|
|
skip_windows!
|
|
_(suite.attribute("failed").value).must_equal "0"
|
|
end
|
|
|
|
it 'has 2 elements named "File / should be directory"' do
|
|
_(REXML::XPath.match(suite, "//testcase[@name='File / is expected to be directory']").length).must_equal 3
|
|
end
|
|
|
|
describe 'the testcase named "example_config Can\'t find file ..."' do
|
|
let(:example_yml_tests) { REXML::XPath.match(suite, "//testcase[@classname='profile.example-1.0' and @name='example_config']") }
|
|
let(:first_example_test) { example_yml_tests.first }
|
|
|
|
it "should be unique" do
|
|
skip
|
|
_(example_yml_tests.length).must_equal 1
|
|
end
|
|
|
|
it "should be skipped" do
|
|
skip
|
|
if is_windows?
|
|
_(first_example_test.elements.to_a("//skipped").length).must_equal 2
|
|
else
|
|
_(first_example_test.elements.to_a("//skipped").length).must_equal 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|