mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
Profile to test the FilterTable::ExceptionCatcher issue
Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
parent
8a77b740db
commit
805cf46848
4 changed files with 74 additions and 0 deletions
3
test/fixtures/profiles/filter-table-test/README.md
vendored
Normal file
3
test/fixtures/profiles/filter-table-test/README.md
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Example InSpec Profile
|
||||
|
||||
This example shows the implementation of an InSpec profile.
|
11
test/fixtures/profiles/filter-table-test/controls/example.rb
vendored
Normal file
11
test/fixtures/profiles/filter-table-test/controls/example.rb
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
describe dummy([{'name' => 'foo'}]).valid? do
|
||||
it { should eq '' }
|
||||
end
|
||||
|
||||
describe dummy([{'name' => 'foo'}]) do
|
||||
its('valid?') { should eq '' }
|
||||
end
|
||||
|
||||
describe dummy([{'name' => 'foo'}]) do
|
||||
it { should be_valid }
|
||||
end
|
10
test/fixtures/profiles/filter-table-test/inspec.yml
vendored
Normal file
10
test/fixtures/profiles/filter-table-test/inspec.yml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
name: filter-table-test
|
||||
title: InSpec Profile
|
||||
maintainer: The Authors
|
||||
copyright: The Authors
|
||||
copyright_email: you@example.com
|
||||
license: Apache-2.0
|
||||
summary: An InSpec Compliance Profile
|
||||
version: 0.1.0
|
||||
supports:
|
||||
platform: os
|
50
test/fixtures/profiles/filter-table-test/libraries/dummy.rb
vendored
Normal file
50
test/fixtures/profiles/filter-table-test/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::ResourceSkipped, '`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
|
Loading…
Add table
Reference in a new issue