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

describe 'postfix::config' do
  let (:title) { 'foo' }
  let (:facts) { {
Mickaël Canévet's avatar
Mickaël Canévet committed
6
7
    :lsbdistcodename => 'wheezy',
    :osfamily        => 'Debian',
Raphaël Pinson's avatar
Raphaël Pinson committed
8
  } }
Mickaël Canévet's avatar
Mickaël Canévet committed
9
10
11
  let :pre_condition do
    "class { 'postfix': }"
  end
Raphaël Pinson's avatar
Raphaël Pinson committed
12
13
14
15

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

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

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

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

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

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

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

Raphaël Pinson's avatar
Raphaël Pinson committed
75
    it { is_expected.to contain_augeas("manage postfix 'foo'").with(
Raphaël Pinson's avatar
Raphaël Pinson committed
76
77
78
79
80
      :incl    => '/etc/postfix/main.cf',
      :lens    => 'Postfix_Main.lns',
      :changes => "rm foo"
    ) }
  end
Raphaël Pinson's avatar
Raphaël Pinson committed
81
82
83
84
85
86
87
88
89
90
91
92
93

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

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