2016-11-21 13:04:49 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: John Kerry
|
|
|
|
|
|
|
|
require 'functional/helper'
|
2017-04-03 18:15:40 +00:00
|
|
|
require 'rexml/document'
|
2016-11-21 13:04:49 +00:00
|
|
|
|
|
|
|
describe 'inspec exec with junit formatter' do
|
|
|
|
include FunctionalHelper
|
|
|
|
|
|
|
|
it 'can execute a simple file with the junit formatter' do
|
2018-02-08 09:06:58 +00:00
|
|
|
out = inspec('exec ' + example_control + ' --reporter junit --no-create-lockfile')
|
2016-11-21 13:04:49 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
2017-04-03 18:15:40 +00:00
|
|
|
doc = REXML::Document.new(out.stdout)
|
|
|
|
doc.has_elements?.must_equal true
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can execute the profile with the junit formatter' do
|
2018-02-08 09:06:58 +00:00
|
|
|
out = inspec('exec ' + example_profile + ' --reporter junit --no-create-lockfile')
|
2016-11-21 13:04:49 +00:00
|
|
|
out.stderr.must_equal ''
|
2018-02-14 16:54:20 +00:00
|
|
|
out.exit_status.must_equal 101
|
2017-04-03 18:15:40 +00:00
|
|
|
doc = REXML::Document.new(out.stdout)
|
|
|
|
doc.has_elements?.must_equal true
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'execute a profile with junit formatting' do
|
2018-02-08 09:06:58 +00:00
|
|
|
let(:doc) { REXML::Document.new(inspec('exec ' + example_profile + ' --reporter junit --no-create-lockfile').stdout) }
|
2016-11-21 13:04:49 +00:00
|
|
|
|
|
|
|
describe 'the document' do
|
|
|
|
it 'has only one testsuite' do
|
2017-04-03 18:15:40 +00:00
|
|
|
doc.elements.to_a("//testsuite").length.must_equal 1
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
2016-11-22 19:43:19 +00:00
|
|
|
it 'must have 5 testcase children' do
|
2017-04-03 18:15:40 +00:00
|
|
|
suite.elements.to_a("//testcase").length.must_equal 5
|
2016-11-22 19:43:19 +00:00
|
|
|
end
|
|
|
|
|
2016-11-21 13:04:49 +00:00
|
|
|
it 'has the tests attribute with 5 total tests' do
|
2017-04-03 18:15:40 +00:00
|
|
|
suite.attribute('tests').value.must_equal "5"
|
2016-11-21 13:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the failures attribute with 0 total tests' do
|
2017-04-03 18:15:40 +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
|
2017-04-03 18:15:40 +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
|
|
|
|
|
|
|
|
describe 'the testcase named "gordon_config Can\'t find file ..."' do
|
2017-11-14 03:41:37 +00:00
|
|
|
let(:gordon_yml_tests) { REXML::XPath.match(suite, "//testcase[@classname='profile.gordon-1.0' and @name='gordon_config']") }
|
2016-11-22 19:43:19 +00:00
|
|
|
let(:first_gordon_test) {gordon_yml_tests.first}
|
|
|
|
|
|
|
|
it 'should be unique' do
|
|
|
|
gordon_yml_tests.length.must_equal 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be skipped' do
|
2017-04-03 18:15:40 +00:00
|
|
|
first_gordon_test.elements.to_a('//skipped').length.must_equal 1
|
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
|