From bbfadb8ab469df665c94c3f6e6c79f5d444198b1 Mon Sep 17 00:00:00 2001 From: Alex Pop Date: Mon, 2 Mar 2020 20:33:28 +0000 Subject: [PATCH] Update tests to pass travs Signed-off-by: Alex Pop --- spec/unit/recipes/default_spec.rb | 2 +- .../test_helper/recipes/force_inspec_core.rb | 20 +++++++++++-------- .../test_helper/recipes/install_inspec.rb | 20 +++++++++++-------- .../recipes/setup_waiver_fixture.rb | 15 ++++---------- test/integration/inspec-attributes/default.rb | 2 +- test/integration/waivers/default.rb | 8 ++++---- .../recipes/bootstrap_localhost.rb | 6 +++--- .../recipes/configure_services.rb | 2 +- .../recipes/converge_localhost.rb | 4 ++-- 9 files changed, 40 insertions(+), 39 deletions(-) diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index 116739fb..648bb01d 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -22,7 +22,7 @@ describe 'audit::default' do context 'When all attributes are default, on an unspecified platform' do let(:chef_run) do - runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '14.04') + runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '18.04') runner.converge(described_recipe) end diff --git a/test/cookbooks/test_helper/recipes/force_inspec_core.rb b/test/cookbooks/test_helper/recipes/force_inspec_core.rb index 33c7c477..f406ff95 100644 --- a/test/cookbooks/test_helper/recipes/force_inspec_core.rb +++ b/test/cookbooks/test_helper/recipes/force_inspec_core.rb @@ -1,16 +1,20 @@ chef_gem 'inspec-core' do - action :nothing -end.run_action(:remove) + compile_time true + action :remove +end chef_gem 'inspec-core-bin' do - action :nothing -end.run_action(:remove) + compile_time true + action :remove +end chef_gem 'inspec' do - action :nothing -end.run_action(:remove) + compile_time true + action :remove +end chef_gem 'inspec-core' do + compile_time true version '4.3.2' - action :nothing -end.run_action(:install) + action :install +end diff --git a/test/cookbooks/test_helper/recipes/install_inspec.rb b/test/cookbooks/test_helper/recipes/install_inspec.rb index 121d270b..22cb8b14 100644 --- a/test/cookbooks/test_helper/recipes/install_inspec.rb +++ b/test/cookbooks/test_helper/recipes/install_inspec.rb @@ -1,16 +1,20 @@ chef_gem 'inspec-core' do - action :nothing -end.run_action(:remove) + compile_time true + action :remove +end chef_gem 'inspec-core-bin' do - action :nothing -end.run_action(:remove) + compile_time true + action :remove +end chef_gem 'inspec' do - action :nothing -end.run_action(:remove) + compile_time true + action :remove +end chef_gem 'inspec' do + compile_time true version '1.19.1' - action :nothing -end.run_action(:install) + action :install +end diff --git a/test/cookbooks/test_helper/recipes/setup_waiver_fixture.rb b/test/cookbooks/test_helper/recipes/setup_waiver_fixture.rb index 3753e662..d6260a59 100644 --- a/test/cookbooks/test_helper/recipes/setup_waiver_fixture.rb +++ b/test/cookbooks/test_helper/recipes/setup_waiver_fixture.rb @@ -1,19 +1,12 @@ -[ - "controls", - "waivers", -].each do |subdir| - directory "#{node["audit"]["profiles"]["waiver-test-profile"]["path"]}/#{subdir}" do +%w(controls waivers).each do |subdir| + directory "#{node['audit']['profiles']['waiver-test-profile']['path']}/#{subdir}" do recursive true end end -[ - "inspec.yml", - "controls/waiver-check.rb", - "waivers/waivers.yaml", -].each do |file| - cookbook_file "#{node["audit"]["profiles"]["waiver-test-profile"]["path"]}/#{file}" do +%w(inspec.yml controls/waiver-check.rb waivers/waivers.yaml).each do |file| + cookbook_file "#{node['audit']['profiles']['waiver-test-profile']['path']}/#{file}" do source "waivers-fixture/#{file}" end end diff --git a/test/integration/inspec-attributes/default.rb b/test/integration/inspec-attributes/default.rb index 4de7a343..0d004974 100644 --- a/test/integration/inspec-attributes/default.rb +++ b/test/integration/inspec-attributes/default.rb @@ -9,7 +9,7 @@ results << r end end -attribute_control = results.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test should exist' } +attribute_control = results.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test is expected to exist' } attribute_control = {} if attribute_control.nil? describe 'attribute control' do diff --git a/test/integration/waivers/default.rb b/test/integration/waivers/default.rb index ecf73f5f..c9117c6a 100644 --- a/test/integration/waivers/default.rb +++ b/test/integration/waivers/default.rb @@ -5,14 +5,14 @@ # The test fixture has two controls - the first should pass, # the second should be a skip with a waiver justification -control "the unwaivered control" do +control 'the unwaivered control' do describe controls[0]['results'][0]['status'] do - it { should cmp "passed" } + it { should cmp 'passed' } end end -control "the waivered control" do +control 'the waivered control' do describe controls[1]['results'][0]['status'] do - it { should cmp "skipped" } + it { should cmp 'skipped' } end end diff --git a/test/kitchen-automate/recipes/bootstrap_localhost.rb b/test/kitchen-automate/recipes/bootstrap_localhost.rb index af0feeee..141509dd 100644 --- a/test/kitchen-automate/recipes/bootstrap_localhost.rb +++ b/test/kitchen-automate/recipes/bootstrap_localhost.rb @@ -24,8 +24,8 @@ end # Ensure the node is in the expected state -raise 'Cannot find /tmp/kitchen/client.pem' unless File.exist?('/tmp/kitchen/client.pem') -raise 'Cannot find /home/ec2-user/.ssh/authorized_keys' unless File.exist?('/home/ec2-user/.ssh/authorized_keys') +raise 'Cannot find /tmp/kitchen/client.pem' unless ::File.exist?('/tmp/kitchen/client.pem') +raise 'Cannot find /home/ec2-user/.ssh/authorized_keys' unless ::File.exist?('/home/ec2-user/.ssh/authorized_keys') # Add a public key to be used for SSH bootstrapping execute 'Add SSH public key to be used by self bootstrapping' do @@ -49,5 +49,5 @@ EOH live_stream true action :run - not_if { File.exist?('/etc/chef/client.pem') } + not_if { ::File.exist?('/etc/chef/client.pem') } end diff --git a/test/kitchen-automate/recipes/configure_services.rb b/test/kitchen-automate/recipes/configure_services.rb index 9d904bda..178b465b 100644 --- a/test/kitchen-automate/recipes/configure_services.rb +++ b/test/kitchen-automate/recipes/configure_services.rb @@ -33,5 +33,5 @@ touch /etc/opscode/chef-server-reconfigured.txt EOH action :run - not_if { File.exist?('/etc/opscode/chef-server-reconfigured.txt') } + not_if { ::File.exist?('/etc/opscode/chef-server-reconfigured.txt') } end diff --git a/test/kitchen-automate/recipes/converge_localhost.rb b/test/kitchen-automate/recipes/converge_localhost.rb index 33f96bfe..39c24445 100644 --- a/test/kitchen-automate/recipes/converge_localhost.rb +++ b/test/kitchen-automate/recipes/converge_localhost.rb @@ -42,7 +42,7 @@ EOH live_stream true action :run - only_if { File.exist?('/etc/chef/client.pem') } + only_if { ::File.exist?('/etc/chef/client.pem') } end # Create the attributes file to test the 'chef-visibility' collector @@ -91,5 +91,5 @@ EOH live_stream true action :run - only_if { File.exist?('/etc/chef/client.pem') } + only_if { ::File.exist?('/etc/chef/client.pem') } end