postfix_map_spec.rb 3.78 KB
Newer Older
1
2
3
require 'spec_helper'

describe 'postfix::map' do
Raphaël Pinson's avatar
Raphaël Pinson committed
4
  let(:title) { 'foo' }
5
6
7
8
9
10
11

  let :pre_condition do
    "class { '::postfix': }"
  end

  on_supported_os.each do |os, facts|
    context "on #{os}" do
Romain Tartière's avatar
Romain Tartière committed
12
13
14
15
16
17
18
      let(:postfix_foo_db_path) do
        case facts[:osfamily]
        when 'FreeBSD' then '/usr/local/etc/postfix/foo.db'
        else '/etc/postfix/foo.db'
        end
      end

19
20
21
22
23
      let(:facts) do
        facts
      end

      context 'when passing wrong type for ensure' do
Raphaël Pinson's avatar
Raphaël Pinson committed
24
25
26
27
28
29
30
        let(:params) do
          {
            ensure: ['present'],
          }
        end

        it 'fails' do
Christos Papageorgiou's avatar
Christos Papageorgiou committed
31
          expect do
32
            is_expected.to contain_file('postfix map foo')
Christos Papageorgiou's avatar
Christos Papageorgiou committed
33
          end.to raise_error
34
35
36
37
        end
      end

      context 'when passing wrong value for ensure' do
Raphaël Pinson's avatar
Raphaël Pinson committed
38
39
40
41
42
43
44
        let(:params) do
          {
            ensure: 'running',
          }
        end

        it 'fails' do
Christos Papageorgiou's avatar
Christos Papageorgiou committed
45
          expect do
46
            is_expected.to contain_file('postfix map foo')
Christos Papageorgiou's avatar
Christos Papageorgiou committed
47
          end.to raise_error(Puppet::Error, %r{got 'running'})
48
49
50
51
        end
      end

      context 'when passing both source and content' do
Raphaël Pinson's avatar
Raphaël Pinson committed
52
53
54
55
56
57
        let(:params) do
          {
            source: '/tmp/bar',
            content: 'bar',
          }
        end
58

Raphaël Pinson's avatar
Raphaël Pinson committed
59
        it 'fails' do
Christos Papageorgiou's avatar
Christos Papageorgiou committed
60
          expect do
61
            is_expected.to contain_file('postfix map foo')
Christos Papageorgiou's avatar
Christos Papageorgiou committed
62
          end.to raise_error(Puppet::Error, %r{You must provide either 'source' or 'content'})
63
64
65
66
        end
      end

      context 'when passing source' do
Raphaël Pinson's avatar
Raphaël Pinson committed
67
68
69
70
71
72
73
74
75
        let(:params) do
          {
            source: '/tmp/bar',
          }
        end

        it {
          is_expected.to contain_file('postfix map foo').with(
            ensure: 'present',
Christos Papageorgiou's avatar
Christos Papageorgiou committed
76
            source: '/tmp/bar'
Raphaël Pinson's avatar
Raphaël Pinson committed
77
          ).without(:content)
78
79
80
81
82
83
        }
        it { is_expected.to contain_file('postfix map foo.db').with_ensure('present') }
        it { is_expected.to contain_exec('generate foo.db') }
      end

      context 'when passing content' do
Raphaël Pinson's avatar
Raphaël Pinson committed
84
85
86
87
88
89
90
91
92
        let(:params) do
          {
            content: 'bar',
          }
        end

        it {
          is_expected.to contain_file('postfix map foo').with(
            ensure: 'present',
Christos Papageorgiou's avatar
Christos Papageorgiou committed
93
            content: 'bar'
Raphaël Pinson's avatar
Raphaël Pinson committed
94
          ).without(:source)
95
96
97
98
99
100
        }
        it { is_expected.to contain_file('postfix map foo.db').with_ensure('present') }
        it { is_expected.to contain_exec('generate foo.db') }
      end

      context 'when not passing source or content' do
Raphaël Pinson's avatar
Raphaël Pinson committed
101
102
        it {
          is_expected.to contain_file('postfix map foo').with(
Christos Papageorgiou's avatar
Christos Papageorgiou committed
103
            ensure: 'present'
Raphaël Pinson's avatar
Raphaël Pinson committed
104
          ).without(:source).without(:content)
105
106
107
108
109
110
        }
        it { is_expected.to contain_file('postfix map foo.db').with_ensure('present') }
        it { is_expected.to contain_exec('generate foo.db') }
      end

      context 'when ensuring absence' do
Raphaël Pinson's avatar
Raphaël Pinson committed
111
112
113
114
115
        let(:params) do
          {
            ensure: 'absent',
          }
        end
116
117

        it { is_expected.to contain_file('postfix map foo').with_ensure('absent') }
118
        it { is_expected.to contain_file('postfix map foo').without_notify }
119
        it { is_expected.to contain_file('postfix map foo.db').with_ensure('absent') }
Romain Tartière's avatar
Romain Tartière committed
120
        it { is_expected.to contain_exec('generate foo.db').with(command: "rm #{postfix_foo_db_path}") }
121
122
123
      end

      context 'when using pcre type' do
Raphaël Pinson's avatar
Raphaël Pinson committed
124
125
126
127
128
        let(:params) do
          {
            type: 'pcre',
          }
        end
129
130
131
132
133
134

        it { is_expected.to contain_file('postfix map foo').with_ensure('present') }
        it { is_expected.not_to contain_file('postfix map foo.db') }
      end

      context 'when using cidr type' do
Raphaël Pinson's avatar
Raphaël Pinson committed
135
136
137
138
139
        let(:params) do
          {
            type: 'cidr',
          }
        end
140
141
142
143
144
145
146

        it { is_expected.to contain_file('postfix map foo').with_ensure('present') }
        it { is_expected.not_to contain_file('postfix map foo.db') }
      end
    end
  end
end