2019-06-11 22:24:35 +00:00
|
|
|
require "functional/helper"
|
|
|
|
require "rexml/document"
|
2016-11-21 13:04:49 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "inspec exec with junit formatter" do
|
2016-11-21 13:04:49 +00:00
|
|
|
include FunctionalHelper
|
|
|
|
|
2019-09-17 00:40:51 +00:00
|
|
|
parallelize_me!
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can execute a simple file with the junit formatter" do
|
|
|
|
out = inspec("exec " + example_control + " --reporter junit --no-create-lockfile")
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-17 00:40:51 +00:00
|
|
|
# TODO: rexml is about as slow as you can go. Use nokogiri
|
2017-04-03 18:15:40 +00:00
|
|
|
doc = REXML::Document.new(out.stdout)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(doc.has_elements?).must_equal true
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-07-25 01:59:01 +00:00
|
|
|
skip_windows!
|
2019-07-23 01:44:43 +00:00
|
|
|
assert_exit_code 0, out
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can execute the profile with the junit formatter" do
|
|
|
|
out = inspec("exec " + example_profile + " --reporter junit --no-create-lockfile")
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
# TODO: _never_ use rexml. Anything else is guaranteed faster
|
2017-04-03 18:15:40 +00:00
|
|
|
doc = REXML::Document.new(out.stdout)
|
2019-09-30 22:31:55 +00:00
|
|
|
_(doc.has_elements?).must_equal true
|
2019-07-23 01:44:43 +00:00
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
_(out.stderr).must_equal ""
|
2019-07-23 01:44:43 +00:00
|
|
|
|
|
|
|
assert_exit_code 101, out
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "execute a profile with junit formatting" do
|
|
|
|
let(:doc) { REXML::Document.new(inspec("exec " + example_profile + " --reporter junit --no-create-lockfile").stdout) }
|
2016-11-21 13:04:49 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "the document" do
|
|
|
|
it "has only one testsuite" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(doc.elements.to_a("//testsuite").length).must_equal 1
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "the test suite" do
|
2017-04-03 18:15:40 +00:00
|
|
|
let(:suite) { doc.elements.to_a("//testsuites/testsuite").first }
|
2016-11-21 13:04:49 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "must have 5 testcase children" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(suite.elements.to_a("//testcase").length).must_equal 5
|
2016-11-22 19:43:19 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has the tests attribute with 5 total tests" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(suite.attribute("tests").value).must_equal "5"
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "has the failures attribute with 0 total tests" do
|
2019-07-25 01:59:01 +00:00
|
|
|
skip_windows!
|
2019-09-30 22:31:55 +00:00
|
|
|
_(suite.attribute("failed").value).must_equal "0"
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
2016-11-22 19:43:19 +00:00
|
|
|
|
|
|
|
it 'has 2 elements named "File /tmp should be directory"' do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(REXML::XPath.match(suite, "//testcase[@name='File /tmp should be directory']").length).must_equal 2
|
2016-11-22 19:43:19 +00:00
|
|
|
end
|
|
|
|
|
2019-10-09 07:08:28 +00:00
|
|
|
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 }
|
2016-11-22 19:43:19 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "should be unique" do
|
2019-10-09 07:08:28 +00:00
|
|
|
_(example_yml_tests.length).must_equal 1
|
2016-11-22 19:43:19 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "should be skipped" do
|
2018-11-08 17:00:14 +00:00
|
|
|
if is_windows?
|
2019-10-09 07:08:28 +00:00
|
|
|
_(first_example_test.elements.to_a("//skipped").length).must_equal 2
|
2018-11-08 17:00:14 +00:00
|
|
|
else
|
2019-10-09 07:08:28 +00:00
|
|
|
_(first_example_test.elements.to_a("//skipped").length).must_equal 1
|
2018-11-08 17:00:14 +00:00
|
|
|
end
|
2016-11-22 19:43:19 +00:00
|
|
|
end
|
|
|
|
end
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
2016-11-22 19:43:19 +00:00
|
|
|
end
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|