diff --git a/spec/classes/puppet_config_spec.rb b/spec/classes/puppet_config_spec.rb index 3594e2b..b929e3c 100644 --- a/spec/classes/puppet_config_spec.rb +++ b/spec/classes/puppet_config_spec.rb @@ -1,194 +1,192 @@ require 'spec_helper' describe 'puppet' do on_os_under_test.each do |os, facts| context "on #{os}" do - newline = facts[:osfamily] == 'windows' ? "\r\n" : "\n" - case facts[:osfamily] when 'FreeBSD' dir_owner = 'puppet' dir_group = 'puppet' confdir = '/usr/local/etc/puppet' logdir = '/var/log/puppet' rundir = '/var/run/puppet' ssldir = '/var/puppet/ssl' vardir = '/var/puppet' when 'windows' dir_owner = nil dir_group = nil confdir = 'C:/ProgramData/PuppetLabs/puppet/etc' logdir = 'C:/ProgramData/PuppetLabs/puppet/var/log' rundir = 'C:/ProgramData/PuppetLabs/puppet/var/run' ssldir = 'C:/ProgramData/PuppetLabs/puppet/etc/ssl' vardir = 'C:/ProgramData/PuppetLabs/puppet/var' else dir_owner = 'root' dir_group = nil confdir = '/etc/puppetlabs/puppet' logdir = '/var/log/puppetlabs/puppet' rundir = '/var/run/puppetlabs' ssldir = '/etc/puppetlabs/puppet/ssl' vardir = '/opt/puppetlabs/puppet/cache' end let :facts do facts.merge(domain: 'example.org') end let :params do {} end describe 'with default parameters' do it { is_expected.to contain_file(confdir).with_owner(dir_owner).with_group(dir_group) } it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{/puppet/v3/}) } - it { is_expected.not_to contain_file("#{confdir}/auth.conf").with_content(%r{^path /certificate_revocation_list/ca#{newline}method find#{newline}}) } + it { is_expected.not_to contain_file("#{confdir}/auth.conf").with_content(%r{^path /certificate_revocation_list/ca\nmethod find$}) } it { is_expected.not_to contain_puppet__config__main('default_manifest') } it { is_expected.not_to contain_file('/etc/puppet/manifests/default_manifest.pp') } it { is_expected.not_to contain_puppet__config__main('reports') } it { is_expected.to contain_puppet__config__main('vardir').with_value(vardir) } it { is_expected.to contain_puppet__config__main('logdir').with_value(logdir) } it { is_expected.to contain_puppet__config__main('rundir').with_value(rundir) } it { is_expected.to contain_puppet__config__main('ssldir').with_value(ssldir) } it { is_expected.to contain_puppet__config__main('privatekeydir').with_value('$ssldir/private_keys { group = service }') } it { is_expected.to contain_puppet__config__main('hostprivkey').with_value('$privatekeydir/$certname.pem { mode = 640 }') } it { is_expected.to contain_puppet__config__main('show_diff').with_value('false') } it { is_expected.to contain_puppet__config__main('server').with_value(facts[:fqdn]) } end describe 'with allow_any_crl_auth' do let :params do super().merge(allow_any_crl_auth: true) end - it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /puppet-ca/v1/certificate_revocation_list/ca#{newline}auth any#{newline}}) } + it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /puppet-ca/v1/certificate_revocation_list/ca\nauth any$}) } end describe 'with auth_allowed' do let :params do super().merge(auth_allowed: ['$1', 'puppetproxy']) end - it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(/^allow \$1, puppetproxy#{newline}/) } + it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(/^allow \$1, puppetproxy$/) } end describe "when dns_alt_names => ['foo','bar']" do let :params do super().merge(dns_alt_names: %w[foo bar]) end it { is_expected.to contain_puppet__config__main('dns_alt_names').with_value(%w[foo bar]) } end describe "when syslogfacility => 'local6'" do let :params do super().merge(syslogfacility: 'local6') end it { is_expected.to contain_puppet__config__main('syslogfacility').with_value('local6') } end describe "when module_repository => 'https://myforgeapi.example.com'" do let :params do super().merge(module_repository: 'https://myforgeapi.example.com') end it { is_expected.to contain_puppet__config__main('module_repository').with_value('https://myforgeapi.example.com') } end describe 'when use_srv_records => true' do let :params do super().merge(use_srv_records: true) end context 'domain fact is defined' do it { is_expected.to contain_puppet__config__main('use_srv_records').with_value('true') } it { is_expected.to contain_puppet__config__main('srv_domain').with_value('example.org') } it { is_expected.to contain_puppet__config__main('pluginsource').with_value('puppet:///plugins') } it { is_expected.to contain_puppet__config__main('pluginfactsource').with_value('puppet:///pluginfacts') } it { is_expected.not_to contain_puppet__config__main('server') } end context 'domain fact is unset' do let(:facts) { facts.merge(domain: nil) } it { is_expected.to raise_error(Puppet::Error, /\$::domain fact found to be undefined and \$srv_domain is undefined/) } end context 'is overriden via param' do let :params do super().merge(srv_domain: 'special.example.com') end it { is_expected.to contain_puppet__config__main('use_srv_records').with_value(true) } it { is_expected.to contain_puppet__config__main('srv_domain').with_value('special.example.com') } end end context 'puppetmaster' do describe "when puppetmaster => 'mymaster.example.com'" do let :params do super().merge(puppetmaster: 'mymaster.example.com') end it { is_expected.to contain_puppet__config__main('server').with_value('mymaster.example.com') } end describe 'puppetmaster parameter overrides global puppetmaster' do let :params do super().merge(puppetmaster: 'mymaster.example.com') end let :facts do facts.merge(puppetmaster: 'global.example.com') end it { is_expected.to contain_puppet__config__main('server').with_value('mymaster.example.com') } end describe 'global puppetmaster overrides fqdn' do let :facts do facts.merge(puppetmaster: 'global.example.com') end it { is_expected.to contain_puppet__config__main('server').with_value('global.example.com') } end context 'when listen' do let :params do super().merge(listen: true) end describe 'puppetmaster default value is used' do - it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow #{facts[:fqdn]}#{newline}}) } + it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run\nauth any\nmethod save\nallow #{facts[:fqdn]}$}) } end describe 'puppetmaster has value' do let :params do super().merge(puppetmaster: 'mymaster.example.com') end - it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow mymaster.example.com#{newline}}) } + it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run\nauth any\nmethod save\nallow mymaster.example.com$}) } end describe 'listen_to has values' do let :params do super().merge(listen_to: ['node1.example.com', 'node2.example.com']) end - it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run#{newline}auth any#{newline}method save#{newline}allow node1\.example\.com,node2\.example\.com#{newline}}) } + it { is_expected.to contain_file("#{confdir}/auth.conf").with_content(%r{^path /run\nauth any\nmethod save\nallow node1\.example\.com,node2\.example\.com$}) } end end end describe 'with additional settings' do let :params do super().merge(additional_settings: { disable_warnings: 'deprecations' }) end it { is_expected.to contain_puppet__config__main('disable_warnings').with_value('deprecations') } end end end end diff --git a/spec/defines/puppet_config_entry_spec.rb b/spec/defines/puppet_config_entry_spec.rb index 93ab26b..1857781 100644 --- a/spec/defines/puppet_config_entry_spec.rb +++ b/spec/defines/puppet_config_entry_spec.rb @@ -1,80 +1,77 @@ require 'spec_helper' describe 'puppet::config::entry' do on_os_under_test.each do |os, facts| context "on #{os}" do let(:facts) { facts } let(:title) { 'foo' } - header = facts[:osfamily] == 'windows' ? "\r\n\r\n[main]" : "\n\n[main]" - context 'with a plain value' do let :pre_condition do "class {'puppet': }" end let :params do { :key => 'foo', :value => 'bar', :section => 'main', :sectionorder => 1, } end - it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content(header) + should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") should contain_concat__fragment('puppet.conf_main').with_order("1_main ") end it 'should contain the keyvalue pair' do should contain_concat__fragment('puppet.conf_main_foo').with_content(/^\s+foo = bar$/) should contain_concat__fragment('puppet.conf_main_foo').with_order("1_main_foo ") end end context 'with an array value' do let :pre_condition do "class {'puppet': }" end let :params do { :key => 'foo', :value => ['bar','baz'], :section => 'main', :sectionorder => 1, } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content(header) + should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") should contain_concat__fragment('puppet.conf_main').with_order("1_main ") end it 'should contain the keyvalue pair' do should contain_concat__fragment('puppet.conf_main_foo').with_content(/^\s+foo = bar,baz$/) should contain_concat__fragment('puppet.conf_main_foo').with_order("1_main_foo ") end end context 'with a custom joiner' do let :pre_condition do "class {'puppet': }" end let :params do { :key => 'foo', :value => ['bar','baz'], :joiner => ':', :section => 'main', :sectionorder => 1, } end it 'should contain the section header' do - should contain_concat__fragment('puppet.conf_main').with_content(header) + should contain_concat__fragment('puppet.conf_main').with_content("\n\n[main]") should contain_concat__fragment('puppet.conf_main').with_order("1_main ") end it 'should contain the keyvalue pair' do should contain_concat__fragment('puppet.conf_main_foo').with_content(/^\s+foo = bar:baz$/) should contain_concat__fragment('puppet.conf_main_foo').with_order("1_main_foo ") end end end end end