From be0781a9237fecd07f97a3651437136dcaa34ee7 Mon Sep 17 00:00:00 2001 From: Mickaël Canévet Date: Fri, 26 Dec 2014 11:26:03 +0100 Subject: Use rspec-puppet-facts --- spec/classes/dhcp_spec.rb | 300 ++++++++++++++++++---------------------------- 1 file changed, 119 insertions(+), 181 deletions(-) (limited to 'spec/classes') diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb index 5bc4a5b..d11cf7c 100644 --- a/spec/classes/dhcp_spec.rb +++ b/spec/classes/dhcp_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'dhcp' do + context 'when on an unsupported OS' do let (:facts) { { :operatingsystem => 'RedHat', @@ -17,200 +18,137 @@ describe 'dhcp' do end end - context 'when on Debian lenny' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'lenny', - :id => 'root', - :path => '/foo/bar' - } } - - # Package - it { should contain_package('dhcp-server').with( - :name => 'dhcp3-server' - ) } - - # Config - it { should contain_concat('/etc/dhcp3/dhcpd.conf').with( - :owner => 'root', - :group => 'root', - :mode => '0644' - ) } - - it { should contain_concat__fragment('00.dhcp.server.base').with( - :ensure => 'present', - :target => '/etc/dhcp3/dhcpd.conf', - :content => /log-facility/ - ).with_content(/ddns-update-style none;/).with_content(/#authoritative/) - } - - # Service - it { should contain_service('dhcpd').with( - :ensure => 'running', - :name => 'dhcp3-server', - :enable => true, - :pattern => '/usr/sbin/dhcpd3' - ) } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :concat_basedir => '/var/lib/puppet/concat', + }) + end - context 'when on Debian squeeze' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } + case facts[:osfamily] + when 'Debian' + case facts[:operatingsystemmajrelease] + when '5' + let(:pkg_name) { 'dhcp3-server' } + let(:confdir) { '/etc/dhcp3' } + let(:srv_name) { 'dhcp3-server' } + let(:srv_pattern) { '/usr/sbin/dhcp3' } + else + let(:pkg_name) { 'isc-dhcp-server' } + let(:confdir) { '/etc/dhcp' } + let(:srv_name) { 'isc-dhcp-server' } + let(:srv_pattern) { '/usr/sbin/dhcpd' } + end + end - # Package - it { should contain_package('dhcp-server').with( - :name => 'isc-dhcp-server' - ) } + # Package + it { should contain_package('dhcp-server').with( + :name => pkg_name + ) } - # Config - it { should contain_concat('/etc/dhcp/dhcpd.conf').with( - :owner => 'root', - :group => 'root', - :mode => '0644' - ) } + # Config + it { should contain_concat("#{confdir}/dhcpd.conf").with( + :owner => 'root', + :group => 'root', + :mode => '0644' + ) } - it { should contain_concat__fragment('00.dhcp.server.base').with( + it { should contain_concat__fragment('00.dhcp.server.base').with( :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', + :target => "#{confdir}/dhcpd.conf", :content => /log-facility/ ).with_content(/ddns-update-style none;/).with_content(/#authoritative/) - } - - # Service - it { should contain_service('dhcpd').with( - :ensure => 'running', - :name => 'isc-dhcp-server', - :enable => true, - :pattern => '/usr/sbin/dhcpd' - ) } - end - - context 'when passing ddns_update' do - context 'when passing wrong type' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - let (:params) { { - :server_ddns_update => true - } } - - it 'should fail' do - expect { - should contain_concat__fragment('00.dhcp.server.base') - }.to raise_error(Puppet::Error, /true is not a string./) - end - end - - context 'when passing valid value' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - let (:params) { { - :server_ddns_update => 'foo' - } } - - it { should contain_concat__fragment('00.dhcp.server.base').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', - :content => /log-facility/ - ).with_content(/ddns-update-style foo;/).with_content(/#authoritative/) } - end - end - context 'when passing authoritative' do - context 'when passing wrong type' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - let (:params) { { - :server_authoritative => 'foo' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('00.dhcp.server.base') - }.to raise_error(Puppet::Error, /"foo" is not a boolean./) + # Service + it { should contain_service('dhcpd').with( + :ensure => 'running', + :name => srv_name, + :enable => true, + :pattern => srv_pattern + ) } + + context 'when passing ddns_update' do + context 'when passing wrong type' do + let (:params) { { + :server_ddns_update => true + } } + + it 'should fail' do + expect { + should contain_concat__fragment('00.dhcp.server.base') + }.to raise_error(Puppet::Error, /true is not a string./) + end + end + + context 'when passing valid value' do + let (:params) { { + :server_ddns_update => 'foo' + } } + + it { should contain_concat__fragment('00.dhcp.server.base').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => /log-facility/ + ).with_content(/ddns-update-style foo;/).with_content(/#authoritative/) + } + end end - end - - context 'when passing valid value' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - let (:params) { { - :server_authoritative => true - } } - - it { should contain_concat__fragment('00.dhcp.server.base').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', - :content => /log-facility/ - ).with_content(/ddns-update-style none;/).with_content(/[^#]authoritative/) - } - end - end - context 'when passing opts' do - context 'when passing wrong type' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - let (:params) { { - :server_opts => 'foo' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('00.dhcp.server.base') - }.to raise_error(Puppet::Error, /"foo" is not an Array./) + context 'when passing authoritative' do + context 'when passing wrong type' do + let (:params) { { + :server_authoritative => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('00.dhcp.server.base') + }.to raise_error(Puppet::Error, /"foo" is not a boolean./) + end + end + + context 'when passing valid value' do + let (:params) { { + :server_authoritative => true + } } + + it { should contain_concat__fragment('00.dhcp.server.base').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => /log-facility/ + ).with_content(/ddns-update-style none;/).with_content(/[^#]authoritative/) + } + end end - end - context 'when passing valid value' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - let (:params) { { - :server_opts => ['foo', 'bar', 'baz'] - } } - - it { should contain_concat__fragment('00.dhcp.server.base').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', - :content => /log-facility/ - ).with_content(/ddns-update-style none;/).with_content(/#authoritative/).with_content(/foo;\nbar;\nbaz;\n/) - } + context 'when passing opts' do + context 'when passing wrong type' do + let (:params) { { + :server_opts => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('00.dhcp.server.base') + }.to raise_error(Puppet::Error, /"foo" is not an Array./) + end + end + + context 'when passing valid value' do + let (:params) { { + :server_opts => ['foo', 'bar', 'baz'] + } } + + it { should contain_concat__fragment('00.dhcp.server.base').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => /log-facility/ + ).with_content(/ddns-update-style none;/).with_content(/#authoritative/).with_content(/foo;\nbar;\nbaz;\n/) + } + end + end end end end -- cgit v1.2.3