aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/.rspec6
-rw-r--r--spec/classes/dhcp_spec.rb198
-rw-r--r--spec/defines/dhcp_hosts_spec.rb384
-rw-r--r--spec/defines/dhcp_shared_network_spec.rb81
-rw-r--r--spec/defines/dhcp_subnet_spec.rb252
-rw-r--r--spec/fixtures/manifests/site.pp6
-rw-r--r--spec/spec_helper.rb4
7 files changed, 931 insertions, 0 deletions
diff --git a/spec/.rspec b/spec/.rspec
new file mode 100644
index 0000000..91cd642
--- /dev/null
+++ b/spec/.rspec
@@ -0,0 +1,6 @@
+--format
+s
+--colour
+--loadby
+mtime
+--backtrace
diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb
new file mode 100644
index 0000000..9db478c
--- /dev/null
+++ b/spec/classes/dhcp_spec.rb
@@ -0,0 +1,198 @@
+require 'spec_helper'
+
+describe 'dhcp' do
+ context 'when on an unsupported OS' do
+ let (:facts) { {
+ :operatingsystem => 'RedHat',
+ :osfamily => 'Redhat',
+ :lsbdistcodename => 'Santiago'
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_package('dhcp-server')
+ }.to raise_error(Puppet::Error, /Unsupported OS RedHat\/Santiago/)
+ end
+ end
+
+ context 'when on Debian lenny' do
+ let (:facts) { {
+ :operatingsystem => 'Debian',
+ :osfamily => 'Debian',
+ :lsbdistcodename => 'lenny'
+ } }
+
+ # 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
+
+ context 'when on Debian squeeze' do
+ let (:facts) { {
+ :operatingsystem => 'Debian',
+ :osfamily => 'Debian',
+ :lsbdistcodename => 'squeeze'
+ } }
+
+ # Package
+ it { should contain_package('dhcp-server').with(
+ :name => 'isc-dhcp-server'
+ ) }
+
+ # Config
+ it { should contain_concat('/etc/dhcp/dhcpd.conf').with(
+ :owner => 'root',
+ :group => 'root',
+ :mode => '0644'
+ ) }
+
+ 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/)
+ }
+
+ # 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'
+ } }
+ 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'
+ } }
+ 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'
+ } }
+ 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 (:facts) { {
+ :operatingsystem => 'Debian',
+ :osfamily => 'Debian',
+ :lsbdistcodename => 'squeeze'
+ } }
+ 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'
+ } }
+ 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 (:facts) { {
+ :operatingsystem => 'Debian',
+ :osfamily => 'Debian',
+ :lsbdistcodename => 'squeeze'
+ } }
+ 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
diff --git a/spec/defines/dhcp_hosts_spec.rb b/spec/defines/dhcp_hosts_spec.rb
new file mode 100644
index 0000000..8170ed5
--- /dev/null
+++ b/spec/defines/dhcp_hosts_spec.rb
@@ -0,0 +1,384 @@
+require 'spec_helper'
+
+describe 'dhcp::hosts' do
+ let (:title) { 'My hosts' }
+ let (:facts) { {
+ :operatingsystem => 'Debian',
+ :osfamily => 'Debian',
+ :lsbdistcodename => 'squeeze',
+ } }
+
+ 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
+ } }
+
+ 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 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
+
+ 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 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 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/)
+ 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'/)
+ 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/)
+ 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\./)
+ 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/)
+ 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,
+ },
+ },
+ :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'
+ } }
+
+ 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 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',
+ :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'/)
+ end
+ end
+end
diff --git a/spec/defines/dhcp_shared_network_spec.rb b/spec/defines/dhcp_shared_network_spec.rb
new file mode 100644
index 0000000..d59f73c
--- /dev/null
+++ b/spec/defines/dhcp_shared_network_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+
+describe 'dhcp::shared_network' do
+ let (:title) { 'My network' }
+ let (:facts) { {
+ :operatingsystem => 'Debian',
+ :osfamily => 'Debian',
+ :lsbdistcodename => 'squeeze'
+ } }
+
+ context 'when passing wrong value for ensure' do
+ let (:params) { {
+ :ensure => 'running',
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp-shared-My network')
+ }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/)
+ end
+ end
+
+ context 'when passing wrong type for subnets' do
+ let (:params) { {
+ :subnets => true,
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp-shared-My network')
+ }.to raise_error(Puppet::Error, /true is not an Array\./)
+ end
+ end
+
+ context 'when passing no parameters' do
+ it { should contain_concat__fragment('dhcp-shared-My network').with(
+ :ensure => 'present',
+ :target => '/etc/dhcp/dhcpd.conf'
+ ).with_content(
+ /shared-network My network \{\n\}/
+ )
+ }
+ end
+
+ context 'when passing wrong type for a subnet' do
+ let (:params) { {
+ :subnets => [true],
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp-shared-My network')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
+ end
+
+ context 'when passing wrong value for a subnet' do
+ let (:params) { {
+ :subnets => ['wrong value'],
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat__fragment('dhcp-shared-My network')
+ }.to raise_error(Puppet::Error, /"wrong value" does not match/)
+ end
+ end
+
+ context 'when passing subnets' do
+ let (:params) { {
+ :subnets => ['1.2.3.4', '5.6.7.8'],
+ } }
+
+ it { should contain_concat__fragment('dhcp-shared-My network').with(
+ :ensure => 'present',
+ :target => '/etc/dhcp/dhcpd.conf'
+ ).with_content(
+ /shared-network My network \{\n include "\/etc\/dhcp\/subnets\/1\.2\.3\.4\.conf";\n include "\/etc\/dhcp\/subnets\/5\.6\.7\.8\.conf";\n\}/)
+ }
+ end
+end
diff --git a/spec/defines/dhcp_subnet_spec.rb b/spec/defines/dhcp_subnet_spec.rb
new file mode 100644
index 0000000..b679551
--- /dev/null
+++ b/spec/defines/dhcp_subnet_spec.rb
@@ -0,0 +1,252 @@
+require 'spec_helper'
+
+describe 'dhcp::subnet' do
+ let (:title) { '1.2.3.4' }
+ let (:facts) { {
+ :operatingsystem => 'Debian',
+ :osfamily => 'Debian',
+ :lsbdistcodename => 'squeeze',
+ :netmask_eth0 => '255.255.255.0',
+ :domain => 'example.com',
+ } }
+
+ context 'when passing wrong value for ensure' do
+ let (:params) { {
+ :ensure => 'running',
+ :broadcast => '1.2.3.4',
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/)
+ end
+ end
+
+ context 'when not passing broadcast' do
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /Must pass broadcast to Dhcp::Subnet/)
+ end
+ end
+
+ context 'when passing wrong type for broadcast' do
+ let (:params) { {
+ :broadcast => true,
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
+ end
+
+ context 'when passing wrong value for broadcast' do
+ let (:params) { {
+ :broadcast => 'foo',
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /"foo" does not match/)
+ end
+ end
+
+ context 'when passing wrong type for netmask' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :netmask => true,
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
+ end
+
+ context 'when passing wrong value for netmask' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :netmask => 'foo',
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /"foo" does not match/)
+ end
+ end
+
+ context 'when passing wrong type for routers' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :routers => true,
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /true is not an Array\./)
+ end
+ end
+
+ context 'when passing wrong type for subnet_mask' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :subnet_mask => true,
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
+ end
+
+ context 'when passing wrong type for domain_name' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :domain_name => true,
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /true is not a string\./)
+ end
+ end
+
+ context 'when passing wrong type for is_shared' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :is_shared => 'foo',
+ } }
+
+ it 'should fail' do
+ expect {
+ should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf')
+ }.to raise_error(Puppet::Error, /"foo" is not a boolean\./)
+ end
+ end
+
+ context 'when using defaults' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ } }
+
+ it { should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf').with(
+ :owner => 'root',
+ :group => 'root',
+ :mode => '0644'
+ ) }
+
+ it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with(
+ :ensure => 'present',
+ :owner => 'root',
+ :group => 'root'
+ ).with_content(
+ /subnet 1\.2\.3\.4 netmask 255\.255\.255\.0 \{\n/
+ ).with_content(
+ /option routers 255\.255\.255\.0;\n/
+ ).with_content(
+ /option subnet-mask 255\.255\.255\.0;\n/
+ ).with_content(
+ /option broadcast-address 1\.2\.3\.4;\n/
+ ).with_content(
+ /option domain-name "example\.com";\n/
+ ) }
+
+ it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with(
+ :ensure => 'present',
+ :target => '/etc/dhcp/dhcpd.conf',
+ :content => "include \"/etc/dhcp/subnets/1.2.3.4.conf\";\n"
+ ) }
+
+ it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.hosts').with(
+ :ensure => 'present',
+ :target => '/etc/dhcp/dhcpd.conf',
+ :content => "include \"/etc/dhcp/hosts.d/1\.2\.3\.4\.conf\";\n"
+ ) }
+
+ it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.base').with(
+ :ensure => 'present',
+ :target => '/etc/dhcp/hosts.d/1.2.3.4.conf',
+ :content => "# File managed by puppet\n",
+ :order => '00'
+ ) }
+ end
+
+ context 'when is_shared is true' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :is_shared => true,
+ } }
+
+ it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with(
+ :ensure => 'absent'
+ ) }
+ end
+
+ context 'when passing other_opts as array' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :other_opts => ['foo', 'bar'],
+ } }
+
+ it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with(
+ :ensure => 'present',
+ :owner => 'root',
+ :group => 'root'
+ ).with_content(
+ / foo;\n bar;\n/
+ ) }
+ end
+
+ context 'when passing other_opts as string' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :other_opts => 'bar',
+ } }
+
+ it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with(
+ :ensure => 'present',
+ :owner => 'root',
+ :group => 'root'
+ ).with_content(
+ / bar;\n/
+ ) }
+ end
+
+ context 'when overriding all parameters' do
+ let (:params) { {
+ :broadcast => '1.2.3.4',
+ :netmask => '255.1.2.0',
+ :routers => ['2.3.4.5', '3.4.5.6'],
+ :subnet_mask => '255.255.1.0',
+ :domain_name => 'foo.io',
+ :other_opts => ['foo', 'bar'],
+ } }
+
+ it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with(
+ :ensure => 'present',
+ :owner => 'root',
+ :group => 'root'
+ ).with_content(
+ /subnet 1\.2\.3\.4 netmask 255\.1\.2\.0 \{\n/
+ ).with_content(
+ /option routers 2\.3\.4\.5,3\.4\.5\.6;\n/
+ ).with_content(
+ /option subnet-mask 255\.255\.1\.0;\n/
+ ).with_content(
+ /option broadcast-address 1\.2\.3\.4;\n/
+ ).with_content(
+ /option domain-name "foo\.io";\n/
+ ).with_content(
+ / foo;\n bar;\n/
+ ) }
+ end
+end
diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..0380291
--- /dev/null
+++ b/spec/fixtures/manifests/site.pp
@@ -0,0 +1,6 @@
+# Fake $::concat_basedir fact
+$concat_basedir = '/var/lib/puppet/concat'
+
+# Default node to test defines
+node default {
+}
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..4edc964
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,4 @@
+require 'mocha'
+require 'rspec-puppet'
+require 'puppetlabs_spec_helper/module_spec_helper'
+