mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
Added functional test for FilterTable::ExceptionCatcher
Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
parent
45e9288e90
commit
0a62a6ac3b
3 changed files with 66 additions and 0 deletions
5
test/fixtures/profiles/filter_table/controls/filter-table-exception-catcher.rb
vendored
Normal file
5
test/fixtures/profiles/filter_table/controls/filter-table-exception-catcher.rb
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
control 'exception_catcher_test' do
|
||||||
|
describe dummy([{'name' => 'foo'}]) do
|
||||||
|
its('valid?') { should eq '' }
|
||||||
|
end
|
||||||
|
end
|
50
test/fixtures/profiles/filter_table/libraries/dummy.rb
vendored
Normal file
50
test/fixtures/profiles/filter_table/libraries/dummy.rb
vendored
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
module Dummy
|
||||||
|
class Test
|
||||||
|
attr_reader :filter_data
|
||||||
|
|
||||||
|
def initialize(data)
|
||||||
|
@filter_data = data
|
||||||
|
end
|
||||||
|
|
||||||
|
filter = FilterTable.create
|
||||||
|
filter.register_column(:names, field: 'name')
|
||||||
|
filter.register_column(
|
||||||
|
:tags,
|
||||||
|
field: :tags,
|
||||||
|
# ref: https://github.com/inspec/inspec/blob/master/docs/dev/filtertable-usage.md#lazy-loading
|
||||||
|
lazy: lambda do |row, _criterion, _table|
|
||||||
|
tags = row['tags']
|
||||||
|
if tags.nil?
|
||||||
|
raise(Inspec::Exceptions::ResourceFailed, '`tags` for resource is missing')
|
||||||
|
end
|
||||||
|
|
||||||
|
row[:tags] = tags
|
||||||
|
end
|
||||||
|
)
|
||||||
|
filter.install_filter_methods_on_resource(self, :filter_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class DummyTest < Inspec.resource(1)
|
||||||
|
name 'dummy'
|
||||||
|
|
||||||
|
attr_reader :data
|
||||||
|
|
||||||
|
def initialize(data)
|
||||||
|
@data = data
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid?
|
||||||
|
tags
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def tags
|
||||||
|
r_data.tags[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
def r_data
|
||||||
|
Dummy::Test.new(data)
|
||||||
|
end
|
||||||
|
end
|
|
@ -123,4 +123,15 @@ describe "filtertable functional tests" do
|
||||||
expect_clean_run(controls)
|
expect_clean_run(controls)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "if control fails" do
|
||||||
|
it "should show the exact error message" do
|
||||||
|
controls = ["exception_catcher_test"]
|
||||||
|
cmd = "exec " + ft_profile_path + " --controls " + controls.join(" ") + " --no-sudo"
|
||||||
|
run_result = run_result_for_controls(controls)
|
||||||
|
outcome_hash = failed_control_test_outcomes(run_result)
|
||||||
|
_(outcome_hash["exception_catcher_test"]).must_include "`tags` for resource is missing"
|
||||||
|
assert_exit_code 100, run_result
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue