Skip to content

Commit

Permalink
Clean up fact overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Apr 30, 2020
1 parent 4395709 commit e6917d6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 55 deletions.
9 changes: 3 additions & 6 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'
require 'deep_merge'

describe 'puppet' do
on_supported_os.each do |os, facts|
Expand Down Expand Up @@ -29,11 +28,9 @@
package_provider = nil
end

let :facts do
facts.deep_merge(
# Cron/systemd timers are based on the IP - make it consistent
networking: { ip: '192.0.2.100' }
)
let(:facts) do
# Cron/systemd timers are based on the IP - make it consistent
override_facts(facts, networking: {ip: '192.0.2.100'})
end

let :params do
Expand Down
38 changes: 14 additions & 24 deletions spec/classes/puppet_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'spec_helper'
require 'deep_merge'

describe 'puppet' do
on_supported_os.each do |os, facts|
on_supported_os.each do |os, os_facts|
context "on #{os}" do
case facts[:osfamily]
case os_facts[:osfamily]
when 'FreeBSD'
dir_owner = 'puppet'
dir_group = 'puppet'
Expand Down Expand Up @@ -40,7 +39,7 @@
end

let :facts do
facts.merge(domain: 'example.org')
override_facts(os_facts, networking: {domain: 'example.org'})
end

let :params do
Expand All @@ -61,7 +60,7 @@
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]) }
it { is_expected.to contain_puppet__config__main('server').with_value(facts[:networking]['fqdn']) }
end

describe 'with allow_any_crl_auth' do
Expand Down Expand Up @@ -118,7 +117,7 @@
end

context 'domain fact is unset' do
let(:facts) { facts.merge(domain: nil) }
let(:facts) { override_facts(super(), networking: {domain: nil}) }

it { is_expected.to raise_error(Puppet::Error, /\$::domain fact found to be undefined and \$srv_domain is undefined/) }
end
Expand All @@ -137,13 +136,10 @@
context 'with client_certname => $::clientcert' do
let :facts do
# rspec-puppet(-facts) doesn't mock this
facts.deep_merge(clientcert: 'client.example.com')
end
let :params do
super().merge(client_certname: facts[:clientcert])
super().merge(clientcert: 'client.example.com')
end

it { is_expected.to contain_puppet__config__main('certname').with_value(facts[:clientcert]) }
it { is_expected.to contain_puppet__config__main('certname').with_value('client.example.com') }
end

context 'with client_certname => "foobar"' do
Expand Down Expand Up @@ -172,24 +168,18 @@
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
context 'with global puppetmaster' do
let(:facts) { super().merge(puppetmaster: 'global.example.com') }

let :facts do
facts.merge(puppetmaster: 'global.example.com')
describe 'it overrides fqdn' do
it { is_expected.to contain_puppet__config__main('server').with_value('global.example.com') }
end

it { is_expected.to contain_puppet__config__main('server').with_value('mymaster.example.com') }
end
describe 'the puppetmaster parameter overrides global puppetmaster' do
let(:params) { super().merge(puppetmaster: 'mymaster.example.com') }

describe 'global puppetmaster overrides fqdn' do
let :facts do
facts.merge(puppetmaster: 'global.example.com')
it { is_expected.to contain_puppet__config__main('server').with_value('mymaster.example.com') }
end

it { is_expected.to contain_puppet__config__main('server').with_value('global.example.com') }
end
end

Expand Down
41 changes: 18 additions & 23 deletions spec/classes/puppet_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,37 @@
it { should contain_puppet__config__main('ca_port').with_value(8140) }
end

describe 'with package_source => Httpurl' do
let :params do {
:package_source => 'https://example.com:123/test'
} end
# compilation is broken due to paths
context 'on non-windows', unless: facts[:osfamily] == 'windows' do
describe 'with package_source => Httpurl' do
let :params do {
:package_source => 'https://example.com:123/test'
} end

if facts[:osfamily] != 'windows'
it { is_expected.to compile }
end
end

describe 'with package_source => Unixpath' do
let :params do {
:package_source => '/test/folder/path/source.rpm'
} end
describe 'with package_source => Unixpath' do
let :params do {
:package_source => '/test/folder/path/source.rpm'
} end

if facts[:osfamily] != 'windows'
it { is_expected.to compile }
end
end

describe 'with package_source => Windowspath' do
let :params do {
:package_source => 'C:\test\folder\path\source.exe'
} end
describe 'with package_source => Windowspath' do
let :params do {
:package_source => 'C:\test\folder\path\source.exe'
} end

if facts[:osfamily] != 'windows'
it { is_expected.to compile }
end
end

describe 'with package_source => foo' do
let :params do {
:package_source => 'foo'
} end
describe 'with package_source => foo' do
let :params do {
:package_source => 'foo'
} end

if facts[:osfamily] != 'windows'
it { is_expected.not_to compile }
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/puppet_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@

describe 'with uppercase hostname' do
let(:facts) do
super().merge(
fqdn: 'PUPPETMASTER.example.com',
override_facts(super(),
networking: {fqdn: 'PUPPETMASTER.example.com'},
# clientcert is always lowercase by Puppet design
clientcert: 'puppetmaster.example.com'
)
Expand Down

0 comments on commit e6917d6

Please sign in to comment.