Functional test for event log

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-05-15 18:01:17 -04:00
parent 4eb815fdd7
commit 4b1ee722b4
3 changed files with 41 additions and 0 deletions

View file

@ -133,6 +133,16 @@ describe 'input plugins' do
end
end
describe 'when examining the event log' do
it 'should include the expected events' do
controls = 'event_log'
cmd = "exec #{profile} --controls #{controls}"
run_result = run_inspec_process(cmd, json: true, env: env)
run_result.must_have_all_controls_passing
run_result.stderr.must_be_empty
end
end
describe 'when listing available inputs' do
it 'should list available inputs' do
controls = 'list_inputs'

View file

@ -25,6 +25,7 @@ module InspecPlugins::InputTestFixture
'test_collide_plugin_higher' => 'collide_plugin_higher',
'test_collide_inline_higher' => 'wrong',
'test_not_mentioned_inline' => 'anything',
'test_event_log' => 'setting_in_plugin',
}
}
end

View file

@ -16,6 +16,36 @@ control 'collide_inline_higher' do
end
end
control 'event_log' do
# This attribute is set here here in the DSL and in the plugin
# An attribute with this history should have 3 events - a create, a DSL set, and a plugin fetch.
attribute('test_event_log', value: 'setting_in_dsl')
# Fetch the attribute object from the registry
input_obj = Inspec::InputRegistry.find_or_register_input('test_event_log', 'input-test-fixture')
describe input_obj.events.count do
it { should eq 3 }
end
create_evt = input_obj.events.detect { |e| e.action == :create }
describe create_evt do
it { should_not be_nil }
end
dsl_set_evt = input_obj.events.detect { |e| e.action == :set && e.provider == :inline_control_code }
describe dsl_set_evt do
it { should_not be_nil }
its('file') { should include 'plugin_controls.rb' }
end
plugin_fetch_evt = input_obj.events.detect { |e| e.action == :fetch && e.provider == :'inspec-input-test-fixture' }
describe plugin_fetch_evt do
it { should_not be_nil }
end
end
control 'list_inputs' do
inputs = Inspec::InputRegistry.list_potential_input_names_for_profile('input-test-fixture')