Skip to content

Commit

Permalink
(MODULES-6686) Fix puppet_agent_spec tests for Windows
Browse files Browse the repository at this point in the history
Previously many tests in classes/puppet_agent_spec.rb were not running on
Windows due to a bug in rspec-puppet-facts.  However in v1.9.0 of the gem it
now adds better windows support, but the puppet_agent_spec.rb began running
tests for Windows which then failed.  This commit modifies the test fixtures and
logic to only test things which make sense on Windows.

Also voxpupuli/rspec-puppet-facts#68 meant that the
order of the testing had to be determinstic, ensuring that Windows platforms
were tested last.
  • Loading branch information
glennsarti committed Feb 26, 2018
1 parent 6ac106c commit f7766ef
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def global_facts(facts, os)
{
:is_pe => true,
}
elsif os =~ /windows/
{
:puppet_agent_appdata => 'C:\\ProgramData',
:puppet_confdir => 'C:\\ProgramData\\Puppetlabs\\puppet\\etc',
:mco_confdir => 'C:\\ProgramData\\Puppetlabs\\mcollective\\etc',
:env_temp_variable => 'C:/tmp',
:puppet_agent_pid => 42,
}
else
{}
end).merge({:servername => 'master.example.vm'})
Expand Down Expand Up @@ -72,7 +80,14 @@ def global_facts(facts, os)
end

context 'supported operating systems' do
on_supported_os.each do |os, facts|
# Due to https://github.com/mcanevet/rspec-puppet-facts/issues/68
# Need to ensure that Windows tests are set last, otherwise puppet tries
# to load windows providers on non-windows platforms in error.
os_list = on_supported_os.select { |os, _x| !(os =~ /windows/) }
windows_list = on_supported_os.select{ |os, _x| os =~ /windows/ }
os_list.merge!(windows_list)

os_list.each do |os, facts|
context "on #{os}" do
let(:facts) do
global_facts(facts, os)
Expand Down Expand Up @@ -118,9 +133,9 @@ def global_facts(facts, os)
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppet_agent::install').with_install_options(['OPTION1=value1','OPTION2=value2']) }

# Note this should fail on Windows, but it doesn't get tested due to https://github.com/mcanevet/rspec-puppet-facts/issues/42
# Windows is not seen as a supported OS when `on_supported_os` is used :-(
it { is_expected.to contain_package('puppet-agent').with_install_options(['OPTION1=value1','OPTION2=value2']) }
unless facts[:osfamily] == 'windows'
it { is_expected.to contain_package('puppet-agent').with_install_options(['OPTION1=value1','OPTION2=value2']) }
end
end
end

Expand Down Expand Up @@ -150,22 +165,27 @@ def global_facts(facts, os)
it { is_expected.to contain_package('puppet-agent').with_ensure(deb_package_version) }
elsif facts[:osfamily] == 'Solaris' && (facts[:operatingsystemmajrelease] == '10' || Puppet.version < '4.0.0')
it { is_expected.to contain_package('puppet-agent').with_ensure('present') }
elsif facts[:osfamily] == 'windows'
# Windows does not contain any Package resources
else
it { is_expected.to contain_package('puppet-agent').with_ensure(package_version) }
end

if Puppet.version < "4.0.0" || (os !~ /sles/ && os !~ /solaris/)
if Puppet.version < "4.0.0" || (os !~ /sles/ && os !~ /solaris/ && os !~ /windows/)
it { is_expected.to contain_class('puppet_agent::service').that_requires('Class[puppet_agent::install]') }
end

if params[:service_names].nil? &&
!(facts[:osfamily] == 'Solaris' && facts[:operatingsystemmajrelease] == '11') &&
(Puppet.version < "4.0.0" || os !~ /sles/)
it { is_expected.to contain_service('puppet') }
it { is_expected.to contain_service('mcollective') }
else
it { is_expected.to_not contain_service('puppet') }
it { is_expected.to_not contain_service('mcollective') }
# Windows platform does not use Service resources
unless facts[:osfamily] == 'windows'
if params[:service_names].nil? &&
!(facts[:osfamily] == 'Solaris' && facts[:operatingsystemmajrelease] == '11') &&
(Puppet.version < "4.0.0" || os !~ /sles/)
it { is_expected.to contain_service('puppet') }
it { is_expected.to contain_service('mcollective') }
else
it { is_expected.to_not contain_service('puppet') }
it { is_expected.to_not contain_service('mcollective') }
end
end
end
end
Expand Down

0 comments on commit f7766ef

Please sign in to comment.