aboutsummaryrefslogtreecommitdiff
path: root/spec/defines/dhcp_hosts_spec.rb
diff options
context:
space:
mode:
authorMickaël Canévet <mickael.canevet@camptocamp.com>2014-12-26 11:26:03 +0100
committerMickaël Canévet <mickael.canevet@camptocamp.com>2014-12-26 11:26:03 +0100
commitbe0781a9237fecd07f97a3651437136dcaa34ee7 (patch)
treed9bb695b5bddf22aaa1abbf07c356867a5a89dfb /spec/defines/dhcp_hosts_spec.rb
parent372f3340c5ee7143c95a399a3b0d4cc07dfba3e0 (diff)
downloadpuppet-dhcp-be0781a9237fecd07f97a3651437136dcaa34ee7.tar.gz
puppet-dhcp-be0781a9237fecd07f97a3651437136dcaa34ee7.tar.bz2
Use rspec-puppet-facts
Diffstat (limited to 'spec/defines/dhcp_hosts_spec.rb')
-rw-r--r--spec/defines/dhcp_hosts_spec.rb707
1 files changed, 355 insertions, 352 deletions
diff --git a/spec/defines/dhcp_hosts_spec.rb b/spec/defines/dhcp_hosts_spec.rb
index 693760d..b6af1fd 100644
--- a/spec/defines/dhcp_hosts_spec.rb
+++ b/spec/defines/dhcp_hosts_spec.rb
@@ -2,385 +2,388 @@ require 'spec_helper'
describe 'dhcp::hosts' do
let (:title) { 'My hosts' }
- let (:facts) { {
- :operatingsystem => 'Debian',
- :osfamily => 'Debian',
- :lsbdistcodename => 'squeeze',
- :id => 'root',
- :path => '/foo/bar'
- } }
-
- context 'when passing wrong value for ensure' do
- let (:params) { {
- :hash_data => {},
- :subnet => '1.2.3.4',
- :ensure => 'running'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/)
- end
- end
-
- context 'when hash_data is not passed' do
- let (:params) { {
- :subnet => '1.2.3.4',
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /Must pass hash_data to Dhcp::Hosts/)
- end
- end
- context 'when passing wrong type for hash_data' do
- let (:params) { {
- :hash_data => 'foo',
- :subnet => '1.2.3.4',
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /"foo" is not a Hash\./)
- end
- end
-
- context 'when subnet is not passed' do
- let (:params) { {
- :hash_data => {},
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /Must pass subnet to Dhcp::Hosts/)
- end
- end
-
- context 'when passing wrong type for subnet' do
- let (:params) { {
- :hash_data => {},
- :subnet => true
- } }
+ on_supported_os.each do |os, facts|
+ context "on #{os}" do
+ let(:facts) do
+ facts.merge({
+ :concat_basedir => '/var/lib/puppet/concat',
+ })
+ end
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /true is not a string\./)
- end
- end
+ context 'when passing wrong value for ensure' do
+ let (:params) { {
+ :hash_data => {},
+ :subnet => '1.2.3.4',
+ :ensure => 'running'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/)
+ end
+ end
- context 'when passing wrong value for subnet' do
- let (:params) { {
- :hash_data => {},
- :subnet => 'foo'
- } }
+ context 'when hash_data is not passed' do
+ let (:params) { {
+ :subnet => '1.2.3.4',
+ } }
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /"foo" does not match/)
- end
- end
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /Must pass hash_data to Dhcp::Hosts/)
+ end
+ end
- context 'when passing wrong type for global_options' do
- let (:params) { {
- :hash_data => {},
- :subnet => '1.2.3.4',
- :global_options => 'foo'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /"foo" is not an Array\./)
- end
- end
+ context 'when passing wrong type for hash_data' do
+ let (:params) { {
+ :hash_data => 'foo',
+ :subnet => '1.2.3.4',
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /"foo" is not a Hash\./)
+ end
+ end
- context 'when passing wrong type for template' do
- let (:params) { {
- :hash_data => {},
- :subnet => '1.2.3.4',
- :template => true
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /true is not a string\./)
- end
- end
+ context 'when subnet is not passed' do
+ let (:params) { {
+ :hash_data => {},
+ } }
- context 'when passing one entry in hash_data' do
- context 'when passing wrong type for an host data' do
- let (:params) { {
- :hash_data => {
- 'host1' => true,
- },
- :subnet => '1.2.3.4'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /true is not a Hash/)
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /Must pass subnet to Dhcp::Hosts/)
+ end
end
- end
- context 'when interfaces is not passed' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /Missing interfaces hash for host 'host1'/)
+ context 'when passing wrong type for subnet' do
+ let (:params) { {
+ :hash_data => {},
+ :subnet => true
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
end
- end
- context 'when passing wrong value for an interface' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth 0' => '00:11:22:33:44:55',
- },
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /"eth 0" does not match/)
+ context 'when passing wrong value for subnet' do
+ let (:params) { {
+ :hash_data => {},
+ :subnet => 'foo'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /"foo" does not match/)
+ end
end
- end
- context 'when passing wrong type for a mac address' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => true,
- },
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /true is not a string\./)
+ context 'when passing wrong type for global_options' do
+ let (:params) { {
+ :hash_data => {},
+ :subnet => '1.2.3.4',
+ :global_options => 'foo'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /"foo" is not an Array\./)
+ end
end
- end
- context 'when passing wrong value for a mac address' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => 'my mac',
- },
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /"my mac" does not match/)
+ context 'when passing wrong type for template' do
+ let (:params) { {
+ :hash_data => {},
+ :subnet => '1.2.3.4',
+ :template => true
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
end
- end
- context 'when passing wrong type for fixed_address' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
+ context 'when passing one entry in hash_data' do
+ context 'when passing wrong type for an host data' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => true,
},
- 'fixed_address' => true,
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /true is not a string/)
- end
- end
-
- context 'when passing wrong value for fixed_address' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
+ :subnet => '1.2.3.4'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /true is not a Hash/)
+ end
+ end
+
+ context 'when interfaces is not passed' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ },
},
- 'fixed_address' => 'my wrong value',
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /"my wrong value" does not match/)
- end
- end
-
- context 'when not passing fixed_address' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
+ :subnet => '1.2.3.4'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /Missing interfaces hash for host 'host1'/)
+ end
+ end
+
+ context 'when passing wrong value for an interface' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth 0' => '00:11:22:33:44:55',
+ },
+ },
},
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it { should contain_concat__fragment('dhcp.host.My hosts').with(
- :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
- :content => /fixed-address host1;/
- ) }
- end
-
- context 'when not passing options' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
+ :subnet => '1.2.3.4'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /"eth 0" does not match/)
+ end
+ end
+
+ context 'when passing wrong type for a mac address' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => true,
+ },
+ },
},
- },
- },
- :subnet => '1.2.3.4',
- :global_options => ['foo', 'bar'],
- } }
-
- it { should contain_concat__fragment('dhcp.host.My hosts').with(
- :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
- :content => /foo;\nbar;\n/
- ) }
- end
-
- context 'when overriding options' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
+ :subnet => '1.2.3.4'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
+ end
+
+ context 'when passing wrong value for a mac address' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => 'my mac',
+ },
+ },
},
- 'options' => ['baz'],
- },
- },
- :subnet => '1.2.3.4',
- :global_options => ['foo', 'bar'],
- } }
-
- it { should contain_concat__fragment('dhcp.host.My hosts').with(
- :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
- :content => /baz;\n/
- ) }
- end
-
- context 'when passing wrong type for options' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
+ :subnet => '1.2.3.4'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /"my mac" does not match/)
+ end
+ end
+
+ context 'when passing wrong type for fixed_address' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ },
+ 'fixed_address' => true,
+ },
},
- 'options' => true,
- },
- },
- :subnet => '1.2.3.4',
- :global_options => ['foo', 'bar'],
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /true is not an Array\./)
- end
- end
-
- context 'when not passing options' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
+ :subnet => '1.2.3.4'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /true is not a string/)
+ end
+ end
+
+ context 'when passing wrong value for fixed_address' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ },
+ 'fixed_address' => 'my wrong value',
+ },
},
- },
- },
- :subnet => '1.2.3.4',
- :global_options => ['foo', 'bar'],
- } }
-
- it { should contain_concat__fragment('dhcp.host.My hosts').with(
- :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
- :content => /foo;\nbar;\n/
- ) }
- end
-
- context 'when passing two hosts' do
- let (:params) { {
- :hash_data => {
- 'host1' => {
- 'interfaces' => {
- 'eth0' => '00:11:22:33:44:55',
- 'wlan0' => '00:aa:bb:44:55:ff',
+ :subnet => '1.2.3.4'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /"my wrong value" does not match/)
+ end
+ end
+
+ context 'when not passing fixed_address' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ },
+ },
},
- },
- 'host2' => {
- 'interfaces' => {
- 'eth1' => '00:11:AF:33:44:55',
+ :subnet => '1.2.3.4'
+ } }
+
+ it { should contain_concat__fragment('dhcp.host.My hosts').with(
+ :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
+ :content => /fixed-address host1;/
+ ) }
+ end
+
+ context 'when not passing options' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ },
+ },
},
- 'fixed_address' => 'foo.example.com',
- 'options' => ['opt1'],
- },
- },
- :subnet => '1.2.3.4'
- } }
-
- it { should contain_concat__fragment('dhcp.host.My hosts').with(
- :target => '/etc/dhcp/hosts.d/1.2.3.4.conf').with_content(
- /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content(
- /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content(
- /host host2-eth1 \{\n hardware ethernet 00:11:AF:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/)
- }
- end
- end
+ :subnet => '1.2.3.4',
+ :global_options => ['foo', 'bar'],
+ } }
+
+ it { should contain_concat__fragment('dhcp.host.My hosts').with(
+ :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
+ :content => /foo;\nbar;\n/
+ ) }
+ end
+
+ context 'when overriding options' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ },
+ 'options' => ['baz'],
+ },
+ },
+ :subnet => '1.2.3.4',
+ :global_options => ['foo', 'bar'],
+ } }
+
+ it { should contain_concat__fragment('dhcp.host.My hosts').with(
+ :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
+ :content => /baz;\n/
+ ) }
+ end
+
+ context 'when passing wrong type for options' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ },
+ 'options' => true,
+ },
+ },
+ :subnet => '1.2.3.4',
+ :global_options => ['foo', 'bar'],
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /true is not an Array\./)
+ end
+ end
+
+ context 'when not passing options' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ },
+ },
+ },
+ :subnet => '1.2.3.4',
+ :global_options => ['foo', 'bar'],
+ } }
+
+ it { should contain_concat__fragment('dhcp.host.My hosts').with(
+ :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
+ :content => /foo;\nbar;\n/
+ ) }
+ end
+
+ context 'when passing two hosts' do
+ let (:params) { {
+ :hash_data => {
+ 'host1' => {
+ 'interfaces' => {
+ 'eth0' => '00:11:22:33:44:55',
+ 'wlan0' => '00:aa:bb:44:55:ff',
+ },
+ },
+ 'host2' => {
+ 'interfaces' => {
+ 'eth1' => '00:11:AF:33:44:55',
+ },
+ 'fixed_address' => 'foo.example.com',
+ 'options' => ['opt1'],
+ },
+ },
+ :subnet => '1.2.3.4'
+ } }
+
+ it { should contain_concat__fragment('dhcp.host.My hosts').with(
+ :target => '/etc/dhcp/hosts.d/1.2.3.4.conf').with_content(
+ /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content(
+ /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content(
+ /host host2-eth1 \{\n hardware ethernet 00:11:AF:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/)
+ }
+ end
+ end
- context 'when overriding template' do
- let (:params) { {
- :hash_data => {},
- :subnet => '1.2.3.4',
- :template => 'wrong/path',
- } }
-
- it 'should fail' do
- expect {
- should contain_concat__fragment('dhcp.host.My hosts')
- }.to raise_error(Puppet::Error, /Could not find template 'wrong\/path'/)
+ context 'when overriding template' do
+ let (:params) { {
+ :hash_data => {},
+ :subnet => '1.2.3.4',
+ :template => 'wrong/path',
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp.host.My hosts')
+ }.to raise_error(Puppet::Error, /Could not find template 'wrong\/path'/)
+ end
+ end
end
end
end