]> gitweb.fluxo.info Git - puppet-dhcp.git/commitdiff
Rename dhcp::shared-network to dhcp::shared_network, add specs
authorRaphaël Pinson <raphael.pinson@camptocamp.com>
Fri, 12 Apr 2013 09:10:45 +0000 (11:10 +0200)
committerRaphaël Pinson <raphael.pinson@camptocamp.com>
Fri, 12 Apr 2013 09:10:45 +0000 (11:10 +0200)
manifests/shared_network.pp
spec/defines/dhcp_shared_network_spec.rb [new file with mode: 0644]
templates/shared-network.erb

index 9a02a5b8eb57eaa2cc585f4e4cfd83618e7c797d..38f14fb7f6c9b302572a6d318af30536c9143559 100644 (file)
@@ -8,17 +8,22 @@
 #  - subnets must exists
 #  - subnets must have $is_shared set to true (default is false)
 #
-define dhcp::shared-network(
+define dhcp::shared_network(
   $ensure  = present,
-  $subnets = []
+  $subnets = [],
 ) {
 
-  include dhcp::params
+  include ::dhcp::params
 
-  concat::fragment {"shared-${name}":
+  validate_string($ensure)
+  validate_re($ensure, ['present', 'absent'],
+              "\$ensure must be either 'present' or 'absent', got '${ensure}'")
+  validate_array($subnets)
+
+  concat::fragment {"dhcp-shared-${name}":
     ensure  => $ensure,
     target  => "${dhcp::params::config_dir}/dhcpd.conf",
-    content => template('dhcp/shared-network.erb'),
+    content => template("${module_name}/shared-network.erb"),
     require => Dhcp::Subnet[$subnets],
   }
 
diff --git a/spec/defines/dhcp_shared_network_spec.rb b/spec/defines/dhcp_shared_network_spec.rb
new file mode 100644 (file)
index 0000000..ff5a2c5
--- /dev/null
@@ -0,0 +1,71 @@
+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/
+      )
+    }
+  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
+  end
+end
index 99a7acac3b9c286f46f30c77dd67dff6529157d2..407106a0c7db00d9555f7238b5fb914e153550f9 100644 (file)
@@ -1,6 +1,9 @@
-#### dhcp::shared-network <%= name %>
-shared-network <%= name %> {
-<% subnets.each do |subnet| -%>
+#### dhcp::shared_network <%= @name %>
+shared-network <%= @name %> {
+<% @subnets.each do |subnet|
+  scope.function_validate_string([subnet])
+  scope.function_validate_re([subnet, '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$'])
+-%>
   include "<%= scope.lookupvar("dhcp::params::config_dir") %>/subnets/<%= subnet %>.conf";
 <% end -%>
 }