postfix_transport_spec.rb 3.6 KB
Newer Older
1
2
3
4
5
require 'spec_helper'

describe 'postfix::transport' do
  let (:title) { 'foo' }
  let (:facts) { {
Mickaël Canévet's avatar
Mickaël Canévet committed
6
7
8
    :augeasversion => '1.2.0',
    :osfamily      => 'Debian',
    :rubyversion   => '1.9.3',
9
    :path            => '/foo/bar',
10
  } }
Mickaël Canévet's avatar
Mickaël Canévet committed
11
12
13
  let :pre_condition do
    "class { 'augeas': }"
  end
14
15
16
17
18
19
20
21

  context 'when sending wrong type for destination' do
    let (:params) { {
      :destination => ['bar'],
    } }

    it 'should fail' do
      expect {
Raphaël Pinson's avatar
Raphaël Pinson committed
22
        is_expected.to contain_augeas('Postfix transport - foo')
23
24
25
26
27
28
29
30
31
32
33
34
      }.to raise_error(Puppet::Error, /\["bar"\] is not a string/)
    end
  end

  context 'when sending wrong type for nexthop' do
    let (:params) { {
      :destination => 'bar',
      :nexthop     => ['baz'],
    } }

    it 'should fail' do
      expect {
Raphaël Pinson's avatar
Raphaël Pinson committed
35
        is_expected.to contain_augeas('Postfix transport - foo')
36
37
38
39
40
41
42
43
44
45
46
47
      }.to raise_error(Puppet::Error, /\["baz"\] is not a string/)
    end
  end

  context 'when sending wrong type for file' do
    let (:params) { {
      :destination => 'bar',
      :file        => ['baz'],
    } }

    it 'should fail' do
      expect {
Raphaël Pinson's avatar
Raphaël Pinson committed
48
        is_expected.to contain_augeas('Postfix transport - foo')
49
50
51
52
53
54
55
56
57
58
59
60
      }.to raise_error(Puppet::Error, /\["baz"\] is not a string/)
    end
  end

  context 'when sending wrong value for file' do
    let (:params) { {
      :destination => 'bar',
      :file        => 'baz',
    } }

    it 'should fail' do
      expect {
Raphaël Pinson's avatar
Raphaël Pinson committed
61
        is_expected.to contain_augeas('Postfix transport - foo')
62
63
64
65
66
67
68
69
70
71
72
73
      }.to raise_error(Puppet::Error, /"baz" is not an absolute path/)
    end
  end

  context 'when sending wrong type for ensure' do
    let (:params) { {
      :destination => 'bar',
      :ensure      => ['baz'],
    } }

    it 'should fail' do
      expect {
Raphaël Pinson's avatar
Raphaël Pinson committed
74
        is_expected.to contain_augeas('Postfix transport - foo')
75
76
77
78
79
80
81
82
83
84
85
86
      }.to raise_error(Puppet::Error, /\["baz"\] is not a string/)
    end
  end

  context 'when sending wrong value for ensure' do
    let (:params) { {
      :destination => 'bar',
      :ensure      => 'running',
    } }

    it 'should fail' do
      expect {
Raphaël Pinson's avatar
Raphaël Pinson committed
87
        is_expected.to contain_augeas('Postfix transport - foo')
88
89
90
91
92
      }.to raise_error(Puppet::Error, /\$ensure must be either/)
    end
  end

  context 'when using default values' do
Raphaël Pinson's avatar
Raphaël Pinson committed
93
94
    it { is_expected.to contain_class('postfix::augeas') }
    it { is_expected.to contain_augeas('Postfix transport - foo').with(
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
      :incl    => '/etc/postfix/transport',
      :lens    => 'Postfix_Transport.lns',
      :changes => [
        "set pattern[. = 'foo'] 'foo'",
        "clear pattern[. = 'foo']/transport",
        "clear pattern[. = 'foo']/nexthop",
      ])
    }
  end

  context 'when overriding default values' do
    let (:params) { {
      :destination => 'bar',
      :nexthop     => 'baz',
      :file        => '/tmp/transport',
      :ensure      => 'present',
    } }

Raphaël Pinson's avatar
Raphaël Pinson committed
113
114
    it { is_expected.to contain_class('postfix::augeas') }
    it { is_expected.to contain_augeas('Postfix transport - foo').with(
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
      :incl    => '/tmp/transport',
      :lens    => 'Postfix_Transport.lns',
      :changes => [
        "set pattern[. = 'foo'] 'foo'",
        "set pattern[. = 'foo']/transport 'bar'",
        "set pattern[. = 'foo']/nexthop 'baz'",
      ])
    }
  end

  context 'when ensuring absence' do
    let (:params) { {
      :destination => 'bar',
      :ensure      => 'absent',
    } }

Raphaël Pinson's avatar
Raphaël Pinson committed
131
132
    it { is_expected.to contain_class('postfix::augeas') }
    it { is_expected.to contain_augeas('Postfix transport - foo').with(
133
134
135
136
137
138
139
140
      :incl    => '/etc/postfix/transport',
      :lens    => 'Postfix_Transport.lns',
      :changes => [
        "rm pattern[. = 'foo']",
      ])
    }
  end
end