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

describe 'postfix::config' do
  let (:title) { 'foo' }
  let (:facts) { {
    :osfamily => 'Debian',
7
    :needs_postfix_class => true,
Raphaël Pinson's avatar
Raphaël Pinson committed
8
9
10
11
12
13
  } }

  context 'when not passing value' do
    it 'should fail' do
      expect {
        should contain_augeas("set postfix 'foo'")
Todd Eddy's avatar
Todd Eddy committed
14
      }.to raise_error(Puppet::Error, /value can not be empty/)
Raphaël Pinson's avatar
Raphaël Pinson committed
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
    end
  end

  context 'when passing wrong type for value' do
    let (:params) { {
      :value => ['bar'],
    } }
    it 'should fail' do
      expect {
        should contain_augeas("set postfix 'foo'")
      }.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 {
        should contain_augeas("set postfix 'foo'")
      }.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 {
        should contain_augeas("set postfix 'foo'")
Todd Eddy's avatar
Todd Eddy committed
49
      }.to raise_error(Puppet::Error, /must be either 'present', 'absent' or 'blank'/)
Raphaël Pinson's avatar
Raphaël Pinson committed
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
    end
  end

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

    it { should contain_augeas("set postfix 'foo' to 'bar'").with(
      :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',
    } }

    it { should contain_augeas("rm postfix 'foo'").with(
      :incl    => '/etc/postfix/main.cf',
      :lens    => 'Postfix_Main.lns',
      :changes => "rm foo"
    ) }
  end
end