File: postfix_config_spec.rb

package info (click to toggle)
puppet-module-camptocamp-postfix 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576 kB
  • sloc: ruby: 1,544; sh: 10; makefile: 4
file content (99 lines) | stat: -rw-r--r-- 2,258 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# frozen_string_literal: true

require 'spec_helper'

describe 'postfix::config' do
  let(:title) { 'foo' }

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

  on_supported_os.each do |os, facts|
    context "on #{os}" do
      let(:postfix_main_cf_path) do
        case facts[:os]['family']
        when 'FreeBSD' then '/usr/local/etc/postfix/main.cf'
        else '/etc/postfix/main.cf'
        end
      end
      let(:facts) do
        facts
      end

      context 'when not passing value' do
        it 'fails' do
          expect do
            is_expected.to contain_augeas("set postfix 'foo'")
          end.to raise_error(Puppet::Error, %r{can not be empty if ensure = present})
        end
      end

      context 'when passing wrong value for ensure' do
        let(:params) do
          {
            value: 'bar',
            ensure: 'running',
          }
        end

        it 'fails' do
          expect do
            is_expected.to contain_augeas("set postfix 'foo'")
          end.to raise_error(Puppet::Error, %r{got 'running'})
        end
      end

      context 'when ensuring presence' do
        let(:params) do
          {
            value: 'bar',
            ensure: 'present',
          }
        end

        it {
          is_expected.to contain_augeas("manage postfix 'foo'").with(
            incl: postfix_main_cf_path,
            lens: 'Postfix_Main.lns',
            changes: "set foo 'bar'"
          )
        }
      end

      context 'when ensuring absence' do
        let(:params) do
          {
            value: 'bar',
            ensure: 'absent',
          }
        end

        it {
          is_expected.to contain_augeas("manage postfix 'foo'").with(
            incl: postfix_main_cf_path,
            lens: 'Postfix_Main.lns',
            changes: 'rm foo'
          )
        }
      end

      context 'when ensuring blank' do
        let(:params) do
          {
            value: 'bar',
            ensure: 'blank',
          }
        end

        it {
          is_expected.to contain_augeas("manage postfix 'foo'").with(
            incl: postfix_main_cf_path,
            lens: 'Postfix_Main.lns',
            changes: 'clear foo'
          )
        }
      end
    end
  end
end