From 61e7844e2e2b05669400492039e8c3cb2013f057 Mon Sep 17 00:00:00 2001 From: Garrett Rowell Date: Fri, 4 Oct 2024 10:54:38 -0600 Subject: [PATCH] update install_spec test --- spec/classes/install_spec.rb | 81 +++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index 65b04311..9c8ebcd9 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -13,11 +13,15 @@ end context 'contains install.pp' do - ['c:\local_folder', 'C:\\ProgramData\\chocolatey'].each do |param_value| - context "choco_install_location => #{param_value}" do - let(:params) { { choco_install_location: param_value } } + let(:exec_environment) { catalogue.resource('exec', 'install_chocolatey_official').send(:parameters)[:environment] } - it { is_expected.to contain_exec('install_chocolatey_official').with_creates("#{param_value}\\bin\\choco.exe") } + ['c:\local_folder', 'C:\\ProgramData\\chocolatey', 'C:\Program Files\chocolatey'].each do |choco_install_path| + context "choco_install_location => #{choco_install_path}" do + let(:params) { { choco_install_location: choco_install_path } } + + it { is_expected.to contain_exec('install_chocolatey_official').with_creates("#{choco_install_path}\\bin\\choco.exe") } + it { expect(exec_environment).to include("ChocolateyInstall=#{choco_install_path}") } + it { is_expected.to contain_registry_value('ChocolateyInstall environment value').with_data(choco_install_path) } end end @@ -32,27 +36,72 @@ context 'use_7zip => false' do let(:params) { { use_7zip: false } } - it { - expect(subject).not_to contain_file('C:\Temp\7za.exe') - } + it { expect(exec_environment).to include('chocolateyUseWindowsCompression=true') } end context 'use_7zip => true' do + let(:params) { { use_7zip: true } } + context 'seven_zip_download_url default' do - let(:params) { { use_7zip: true } } + it { expect(exec_environment).to include('chocolateyUseWindowsCompression=false') } + end - it { is_expected.to contain_file('C:\Temp\7za.exe').with_source('https://chocolatey.org/7za.exe') } + ['https://packages.organization.net/7za.exe'].each do |seven_zip_url| + context "seven_zip_download_url => '#{seven_zip_url}'" do + let(:params) do + super().merge({ seven_zip_download_url: seven_zip_url }) + end + + it { is_expected.to contain_exec('install_chocolatey_official').with_command(%r{.*Request-File -Url #{seven_zip_url}.*}) } + end end + end + + ['http://proxy.megacorp.com:3128'].each do |proxy_url| + context "install_proxy => '#{proxy_url}'" do + let(:params) { { install_proxy: proxy_url } } + + it { expect(exec_environment).to include("chocolateyProxyLocation=#{proxy_url}") } + + context 'install_proxy_user => \'Bob\'' do + let(:params) do + super().merge({ install_proxy_user: 'Bob' }) + end + + it { expect(exec_environment).to include('chocolateyProxyUser=Bob') } + end - context "seven_zip_download_url => 'https://packages.organization.net/7za.exe'" do - let(:params) do - { - use_7zip: true, - seven_zip_download_url: 'https://packages.organization.net/7za.exe' - } + context 'install_proxy_password => \'SomeP@$$\'' do + let(:params) do + super().merge({ install_proxy_password: sensitive('SomeP@$$') }) + end + + it { expect(exec_environment).to include('chocolateyProxyPassword=SomeP@$$') } + end + + context 'install_proxy_ignore => true' do + let(:params) do + super().merge({ install_ignore_proxy: true }) + end + + it { expect(exec_environment).to include('chocolateyIgnoreProxy=true') } end + end + end + + ['https://internalurl/to/chocolatey.nupkg'].each do |param_value| + context "download_url => '#{param_value}'" do + let(:params) { { chocolatey_download_url: param_value } } + + it { expect(exec_environment).to include("chocolateyDownloadUrl=#{param_value}") } + end + end + + ['C:/temp'].each do |param_value| + context "install_tempdir => '#{param_value}'" do + let(:params) { { install_tempdir: param_value } } - it { is_expected.to contain_file('C:\Temp\7za.exe').with_source('https://packages.organization.net/7za.exe') } + it { expect(exec_environment).to include("TEMP=#{param_value}") } end end end