Skip to content

Commit

Permalink
Update tests for Inspec 2.0 json changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Quick <jquick@chef.io>
  • Loading branch information
jquick committed Apr 19, 2018
1 parent 60ecc89 commit 137314a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end

group :integration do
gem 'test-kitchen', '~> 1.16'
gem 'kitchen-dokken'
gem 'kitchen-dokken', '= 2.6.0'
gem 'kitchen-ec2', '~> 1.2'
gem 'kitchen-inspec', '~> 0.18'
end
Expand Down
12 changes: 9 additions & 3 deletions test/integration/chef-node-disabled/default.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# get most recent json-file output
json_file = command('ls -t /opt/kitchen/cache/cookbooks/audit/inspec-*.json').stdout.lines.first.chomp
controls = json(json_file).controls
controls = json(json_file).profiles.first['controls']
results = []
controls.each do |c|
c['results'].each do |r|
results << r
end
end

# the controls that read from chef_node should fail because the chef_node data should not be present
cpu_key_control = controls.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = results.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = {} if cpu_key_control.nil?

describe 'cpu_key control' do
Expand All @@ -12,7 +18,7 @@
end
end

chef_environment_control = controls.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = results.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = {} if chef_environment_control.nil?

describe 'chef_environment control' do
Expand Down
12 changes: 9 additions & 3 deletions test/integration/chef-node-enabled/default.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# get most recent json-file output
json_file = command('ls -t /opt/kitchen/cache/cookbooks/audit/inspec-*.json').stdout.lines.first.chomp
controls = json(json_file).controls
controls = json(json_file).profiles.first['controls']
results = []
controls.each do |c|
c['results'].each do |r|
results << r
end
end

# Test ability to read in Chef node attributes when the chef_node attribute is enabled
cpu_key_control = controls.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = results.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = {} if cpu_key_control.nil?

describe 'cpu_key control' do
Expand All @@ -12,7 +18,7 @@
end
end

chef_environment_control = controls.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = results.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = {} if chef_environment_control.nil?

describe 'chef_environment control' do
Expand Down
12 changes: 9 additions & 3 deletions test/integration/inspec-attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# get most recent json-file output
json_file = command('ls -t /opt/kitchen/cache/cookbooks/audit/inspec-*.json').stdout.lines.first.chomp

# Ensure the control we expect is present and passed
controls = json(json_file).controls
attribute_control = controls.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test should exist'}
# ensure the control we expect is present and passed
controls = json(json_file).profiles.first['controls']
results = []
controls.each do |c|
c['results'].each do |r|
results << r
end
end
attribute_control = results.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test should exist'}
attribute_control = {} if attribute_control.nil?

describe 'attribute control' do
Expand Down

0 comments on commit 137314a

Please sign in to comment.