diff options
Diffstat (limited to 'spec/defines')
-rw-r--r-- | spec/defines/dhcp_failover_spec.rb | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/spec/defines/dhcp_failover_spec.rb b/spec/defines/dhcp_failover_spec.rb new file mode 100644 index 0000000..d8400b0 --- /dev/null +++ b/spec/defines/dhcp_failover_spec.rb @@ -0,0 +1,204 @@ +require 'spec_helper' + +describe 'dhcp::failover' do + let (:title) { 'failover-dhcp' } + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :concat_basedir => '/var/lib/puppet/concat', + :domain => 'example.com', + :ipaddress => '1.2.3.3', + }) + end + + context 'when passing wrong value for ensure' do + let (:params) { { + :ensure => 'foo', + :peer_address => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /"foo" does not match \["present", "absent"\]/) + end + end + + context 'when passing wrong type for address' do + let (:params) { { + :address => true, + :peer_address => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for address' do + let (:params) { { + :address => 'foo', + :peer_address => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /is not a valid IPv4 address\./) + end + end + + context 'when not passing peer_address' do + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /Must pass peer_address to Dhcp::Failover/) + end + end + + context 'when passing wrong type for peer_address' do + let (:params) { { + :peer_address => true, + } } + + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for peer_address' do + let (:params) { { + :peer_address => 'foo', + } } + + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /is not a valid IPv4 address\./) + end + end + + context 'when passing wrong type for peer_port' do + let (:params) { { + :peer_port => 'foo', + :peer_address => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /Expected first argument to be an Integer/) + end + end + + context 'when passing wrong type for port' do + let (:params) { { + :peer_address => '1.2.3.4', + :port => 'foo', + } } + + it 'should fail' do + expect { + should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + }.to raise_error(Puppet::Error, /Expected first argument to be an Integer/) + end + end + + + + context 'when using defaults' do + let (:params) { { + :peer_address => '1.2.3.4', + } } + + it { should contain_file('/etc/dhcp/failover/failover-dhcp.conf').with( + :ensure => 'file', + :owner => 'root', + :group => 'root' + ).with_content( + /failover peer "failover-dhcp" \{\n/ + ).with_content( + /primary;\n/ + ).with_content( + /address 1.2.3.3;\n/ + ).with_content( + /port 647;\n/ + ).with_content( + /peer address 1.2.3.4;\n/ + ).with_content( + /peer port 647;\n/ + ) } + it { should contain_concat__fragment('dhcp.failover.failover-dhcp').with({ + :content => "include \"/etc/dhcp/failover/failover-dhcp.conf\";\n", + :target => '/etc/dhcp/dhcpd.conf', + })} + end + + context 'when passing options as a hash' do + let (:params) { { + :peer_address => '1.2.3.4', + :options => { + 'max-response-delay' => '30', + 'max-unacked-updates' => '10', + 'load balance max seconds' => '3', + 'mclt' => '1800', + 'split' => '128', + }, + } } + + it { should contain_file('/etc/dhcp/failover/failover-dhcp.conf').with({ + :ensure => 'file', + :owner => 'root', + :group => 'root' + }).with_content( + /failover peer "failover-dhcp" \{\n/ + ).with_content( + / load balance max seconds 3;\n/ + ).with_content( + / max-response-delay 30;\n/ + ).with_content( + / max-unacked-updates 10;\n/ + ).with_content( + / mclt 1800;\n/ + ).with_content( + / split 128;\n/ + ) } + end + + context 'when overriding all parameters' do + let (:params) { { + :peer_address => '1.2.3.4', + :address => '1.2.3.5', + :peer_port => 847, + :port => 847, + :options => { + 'mclt' => 1800, + }, + :role => 'secondary', + } } + + it { should contain_file('/etc/dhcp/failover/failover-dhcp.conf').with({ + :ensure => 'file', + :owner => 'root', + :group => 'root' + }).with_content( + /secondary;\n/ + ).with_content( + /address 1.2.3.5;\n/ + ).with_content( + /port 847;\n/ + ).with_content( + /peer port 847;\n/ + ).with_content( + /mclt 1800;\n/ + ) } + end + end + end +end |