2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/reporters"
|
2018-08-03 14:07:01 +00:00
|
|
|
|
2018-08-15 00:07:59 +00:00
|
|
|
describe Inspec::Reporters::JsonAutomate do
|
2018-08-03 14:07:01 +00:00
|
|
|
let(:path) { File.expand_path(File.dirname(__FILE__)) }
|
|
|
|
let(:report) do
|
2019-06-11 22:24:35 +00:00
|
|
|
data = JSON.parse(File.read(path + "/../mock/reporters/run_data_wrapper.json"), symbolize_names: true)
|
2018-08-15 00:07:59 +00:00
|
|
|
Inspec::Reporters::JsonAutomate.new({ run_data: data })
|
2018-08-03 14:07:01 +00:00
|
|
|
end
|
2018-09-18 18:20:48 +00:00
|
|
|
let(:profiles) { report.send(:profiles) }
|
2018-08-03 14:07:01 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#render" do
|
|
|
|
it "confirms render output" do
|
|
|
|
output = File.read(path + "/../mock/reporters/json_merged_output")
|
2018-08-03 14:07:01 +00:00
|
|
|
report.render
|
|
|
|
report.rendered_output.must_equal output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#report_merged" do
|
|
|
|
it "outputs the correct report_merged" do
|
|
|
|
output = File.read(path + "/../mock/reporters/json_merged_output")
|
2018-08-03 14:07:01 +00:00
|
|
|
output = JSON.parse(output, symbolize_names: true)
|
2018-09-18 18:20:48 +00:00
|
|
|
report.report.must_equal output
|
2018-08-03 14:07:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#find_master_parent" do
|
|
|
|
it "finds the parent" do
|
2018-08-03 14:07:01 +00:00
|
|
|
report.instance_variable_set(:@profiles, profiles)
|
|
|
|
parent = report.send(:find_master_parent, profiles[1])
|
2019-06-11 22:24:35 +00:00
|
|
|
parent[:name].must_equal "wrapper-override"
|
2018-08-03 14:07:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#merge_controls" do
|
|
|
|
it "merges profile controls" do
|
2018-08-03 14:07:01 +00:00
|
|
|
parent = profiles[0]
|
|
|
|
child = profiles[1]
|
2019-06-11 22:24:35 +00:00
|
|
|
parent[:controls].select { |c| c[:id] == "pro1-con4" }.first[:code].must_equal ""
|
2018-08-03 14:07:01 +00:00
|
|
|
report.send(:merge_controls, parent, child)
|
|
|
|
assert = "control 'pro1-con4' do\n impact 1\n title 'Profile 1 - Control 3 - useless'\n desc 'Profile 1 - Control 3 description'\n only_if do\n 1.eql?(0)\n end\n describe file('/tmp5') do\n it { should exist }\n end\nend\n"
|
2019-06-11 22:24:35 +00:00
|
|
|
parent[:controls].select { |c| c[:id] == "pro1-con4" }.first[:code].must_equal assert
|
2018-08-03 14:07:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#merge_depends" do
|
|
|
|
it "merges profile depends" do
|
2018-08-03 14:07:01 +00:00
|
|
|
parent = profiles[0]
|
|
|
|
child = profiles[1]
|
2019-06-11 22:24:35 +00:00
|
|
|
child[:depends] = [{ name: "myprofile2", url: "https://test/myprofile2-1.0.0.tar.gz" }]
|
|
|
|
assert = [{ name: "myprofile1z", url: "https://s3-eu-west-1.amazonaws.com/apop-bucket/profiles/myprofile1-1.0.0.tar.gz" }]
|
2018-08-03 14:07:01 +00:00
|
|
|
parent[:depends].must_equal assert
|
|
|
|
report.send(:merge_depends, parent, child)
|
|
|
|
assert = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ name: "myprofile1z", url: "https://s3-eu-west-1.amazonaws.com/apop-bucket/profiles/myprofile1-1.0.0.tar.gz" },
|
|
|
|
{ name: "myprofile2", url: "https://test/myprofile2-1.0.0.tar.gz" },
|
2018-08-03 14:07:01 +00:00
|
|
|
]
|
|
|
|
parent[:depends].must_equal assert
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|