]> gitweb.fluxo.info Git - puppet-dhcp.git/commitdiff
Add spec tests for the dhcp class
authorRaphaël Pinson <raphael.pinson@camptocamp.com>
Thu, 11 Apr 2013 10:34:23 +0000 (12:34 +0200)
committerRaphaël Pinson <raphael.pinson@camptocamp.com>
Thu, 11 Apr 2013 10:34:23 +0000 (12:34 +0200)
manifests/hosts.pp
manifests/params.pp
spec/classes/dhcp_spec.rb [new file with mode: 0644]

index b159449acb4d78153659956d13d9f8c60a557a98..426d661a0fc7ebc540f97b04cc7fa40b8ec1fbec 100644 (file)
@@ -42,7 +42,7 @@ define dhcp::hosts (
   $template = 'dhcp/host.conf.erb',
 ) {
 
-  include dhcp::params
+  include ::dhcp::params
 
   concat::fragment {"dhcp.host.${name}":
     target  => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf",
index 925f3f53455edd03d6e995721f465dbf761a7e76..0938e4a8389fd77aaa01ad2d14535cfa56969786 100644 (file)
@@ -27,7 +27,7 @@ class dhcp::params {
     }
 
     default: {
-      fail "${name} is not available for ${::operatingsystem}/${::lsbdistcodename}"
+      fail "Unsupported OS ${::operatingsystem}/${::lsbdistcodename}"
     }
 
   }
diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb
new file mode 100644 (file)
index 0000000..c833c52
--- /dev/null
@@ -0,0 +1,73 @@
+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'
+    ) }
+
+    # 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'
+    ) }
+
+    # Service
+    it { should contain_service('dhcpd').with(
+      :ensure  => 'running',
+      :name    => 'isc-dhcp-server',
+      :enable  => true,
+      :pattern => '/usr/sbin/dhcpd'
+    ) }
+  end
+end