postfix_config_spec.rb 2.58 KB
Newer Older
Raphaël Pinson's avatar
Raphaël Pinson committed
1
2
3
4
require 'spec_helper'

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

Mickaël Canévet's avatar
Mickaël Canévet committed
6
7
8
  let :pre_condition do
    "class { 'postfix': }"
  end
Raphaël Pinson's avatar
Raphaël Pinson committed
9

10
11
12
13
14
  on_supported_os.each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts
      end
Raphaël Pinson's avatar
Raphaël Pinson committed
15

16
17
18
19
20
21
22
      context 'when not passing value' do
        it 'should fail' do
          expect {
            is_expected.to contain_augeas("set postfix 'foo'")
          }.to raise_error(Puppet::Error, /value can not be empty/)
        end
      end
Raphaël Pinson's avatar
Raphaël Pinson committed
23

24
25
26
27
28
29
30
31
32
33
      context 'when passing wrong type for value' do
        let (:params) { {
          :value => ['bar'],
        } }
        it 'should fail' do
          expect {
            is_expected.to contain_augeas("set postfix 'foo'")
          }.to raise_error(Puppet::Error, /\["bar"\] is not a string/)
        end
      end
Raphaël Pinson's avatar
Raphaël Pinson committed
34

35
36
37
38
39
40
41
42
43
44
45
      context 'when passing wrong type for ensure' do
        let (:params) { {
          :value  => 'bar',
          :ensure => ['present'],
        } }
        it 'should fail' do
          expect {
            is_expected.to contain_augeas("set postfix 'foo'")
          }.to raise_error(Puppet::Error, /\["present"\] is not a string/)
        end
      end
Raphaël Pinson's avatar
Raphaël Pinson committed
46

47
48
49
50
51
52
53
54
55
56
57
      context 'when passing wrong value for ensure' do
        let (:params) { {
          :value  => 'bar',
          :ensure => 'running',
        } }
        it 'should fail' do
          expect {
            is_expected.to contain_augeas("set postfix 'foo'")
          }.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/)
        end
      end
Raphaël Pinson's avatar
Raphaël Pinson committed
58

59
60
61
62
63
      context 'when ensuring presence' do
        let (:params) { {
          :value  => 'bar',
          :ensure => 'present',
        } }
Raphaël Pinson's avatar
Raphaël Pinson committed
64

65
66
67
68
69
70
        it { is_expected.to contain_augeas("manage postfix 'foo'").with(
          :incl    => '/etc/postfix/main.cf',
          :lens    => 'Postfix_Main.lns',
          :changes => "set foo 'bar'"
        ) }
      end
Raphaël Pinson's avatar
Raphaël Pinson committed
71

72
73
74
75
76
77
78
79
80
81
82
83
      context 'when ensuring absence' do
        let (:params) { {
          :value  => 'bar',
          :ensure => 'absent',
        } }

        it { is_expected.to contain_augeas("manage postfix 'foo'").with(
          :incl    => '/etc/postfix/main.cf',
          :lens    => 'Postfix_Main.lns',
          :changes => "rm foo"
        ) }
      end
Raphaël Pinson's avatar
Raphaël Pinson committed
84

85
86
87
88
89
      context 'when ensuring blank' do
        let (:params) { {
          :value  => 'bar',
          :ensure => 'blank',
        } }
Raphaël Pinson's avatar
Raphaël Pinson committed
90

91
92
93
94
95
96
97
        it { is_expected.to contain_augeas("manage postfix 'foo'").with(
          :incl    => '/etc/postfix/main.cf',
          :lens    => 'Postfix_Main.lns',
          :changes => "clear foo"
        ) }
      end
    end
Raphaël Pinson's avatar
Raphaël Pinson committed
98
  end
Raphaël Pinson's avatar
Raphaël Pinson committed
99
end