Make license touching for functional and int testing portable to windows

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-04-11 15:30:30 -04:00
parent 8915ad049f
commit c6940be8d4

View file

@ -8,6 +8,7 @@ require 'passgen'
require 'train'
require_relative 'tasks/maintainers'
require_relative 'tasks/spdx'
require 'fileutils'
Bundler::GemHelper.install_tasks name: 'inspec'
@ -71,21 +72,21 @@ namespace :test do
end
task :accept_license do
sh 'mkdir -p $HOME/.chef/accepted_licenses'
FileUtils.mkdir_p(File.join(Dir.home, '.chef', 'accepted_licenses')
# If the user has not accepted the license, touch the acceptance
# file, but also touch a marker that it is only for testing.
unless File.exist?(File.join(Dir.home, '.chef', 'accepted_licenses', 'inspec'))
puts "\n\nTemporarily accepting Chef user license for the duration of testing...\n"
sh 'touch $HOME/.chef/accepted_licenses/inspec'
sh 'touch $HOME/.chef/accepted_licenses/inspec.for_testing'
FileUtils.touch(File.join(Dir.home, '.chef', 'accepted_licenses', 'inspec')
FileUtils.touch(File.join(Dir.home, '.chef', 'accepted_licenses', 'inspec.for_testing')
end
# Regardless of what happens, when this process exits, check for cleanup.
at_exit do
if File.exist?(File.join(Dir.home, '.chef', 'accepted_licenses', 'inspec.for_testing'))
puts "\n\nRemoving temporary Chef user license acceptance file that was placed for test duration.\n"
sh 'rm -f $HOME/.chef/accepted_licenses/inspec'
sh 'rm -f $HOME/.chef/accepted_licenses/inspec.for_testing'
FileUtils.rm_f(File.join(Dir.home, '.chef', 'accepted_licenses', 'inspec')
FileUtils.rm_f(File.join(Dir.home, '.chef', 'accepted_licenses', 'inspec.for_testing')
end
end
end