aboutsummaryrefslogtreecommitdiff
path: root/spec/defines/dhcp_shared_network_spec.rb
blob: d59f73cba5af65b8c87d608c0402f07a3faf38bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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