add another variable handling example test

Signed-off-by: Alex Pop <apop@chef.io>
This commit is contained in:
Alex Pop 2017-02-03 08:27:51 +00:00
parent f7444ed372
commit 83e44f9d2a

View file

@ -216,7 +216,7 @@ end
end
end
describe 'Inspec::Variable' do
describe 'Inspec::Variable, take #1' do
it 'constructs a control with variable to instantiate a resource only once' do
control = Inspec::Control.new
variable = Inspec::Value.new([['command','which grep']])
@ -258,4 +258,38 @@ end
end
end
describe 'Inspec::Variable, take #2' do
it 'constructs a control with variable, loop and var reference' do
control = Inspec::Control.new
command_value = /^\/usr\/bin\/chrony/
pid_filter = '>'
pid_value = 0
loopy = Inspec::EachLoop.new
loopy.qualifier = [['processes', command_value]]
loopy.qualifier.push(["where { pid #{pid_filter} #{pid_value} }.entries"])
obj = loopy.add_test
variable = Inspec::Value.new([['passwd.where { user == "_chrony" }.uids.first']])
variable_id = variable.name_variable.to_s
obj.variables.push(variable)
obj.qualifier = [['user(entry.user)'], ['uid']]
obj.matcher = "cmp #{variable_id}"
control.add_test(obj)
control.id = 'variable.control.id'
control.impact = 0.1
control.to_ruby.must_equal '
control "variable.control.id" do
impact 0.1
a = passwd.where { user == "_chrony" }.uids.first
describe user(entry.user) do
its("uid") { should cmp a }
end
end
'.strip
end
end
end