postfix_hash_spec.rb 3.33 KB
Newer Older
1
2
3
4
require 'spec_helper'

describe 'postfix::hash' do
  let (:title) { '/tmp/foo' }
5

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

10
11
12
13
14
  on_supported_os.each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts
      end
15

16
17
18
19
20
21
22
23
24
25
      context 'when passing wrong type for ensure' do
        let (:params) { {
          :ensure => ['present'],
        } }
        it 'should fail' do
          expect {
            is_expected.to contain_file('/tmp/foo')
          }.to raise_error(Puppet::Error, /\["present"\] is not a string/)
        end
      end
26

27
28
29
30
31
32
33
34
35
36
      context 'when passing wrong value for ensure' do
        let (:params) { {
          :ensure => 'running',
        } }
        it 'should fail' do
          expect {
            is_expected.to contain_file('/tmp/foo')
          }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
        end
      end
37

38
39
40
41
42
43
44
45
      context 'when passing wrong value for title' do
        let (:title) { 'foo' }
        it 'should fail' do
          expect {
            is_expected.to contain_file('/tmp/foo')
          }.to raise_error(Puppet::Error, /"foo" is not an absolute path/)
        end
      end
46

47
48
49
50
51
      context 'when passing both source and content' do
        let (:params) { {
          :source  => '/tmp/bar',
          :content => 'bar',
        } }
52

53
54
55
56
57
58
        it 'should fail' do
          expect {
            is_expected.to contain_file('/tmp/foo')
          }.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/)
        end
      end
59

60
61
62
63
      context 'when passing source' do
        let (:params) { {
          :source  => '/tmp/bar',
        } }
64

65
66
67
68
69
70
71
        it { is_expected.to contain_file('/tmp/foo').with(
          :ensure => 'present',
          :source => '/tmp/bar'
        ).without(:content)
        }
        it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
        it { is_expected.to contain_exec('generate /tmp/foo.db') }
72
        it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
73
      end
74

75
76
77
78
      context 'when passing content' do
        let (:params) { {
          :content => 'bar',
        } }
79

80
81
82
83
84
85
86
        it { is_expected.to contain_file('/tmp/foo').with(
          :ensure  => 'present',
          :content => 'bar'
        ).without(:source)
        }
        it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
        it { is_expected.to contain_exec('generate /tmp/foo.db') }
87
        it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
88
89
90
91
92
93
94
95
96
      end

      context 'when not passing source or content' do
        it { is_expected.to contain_file('/tmp/foo').with(
          :ensure  => 'present'
        ).without(:source).without(:content)
        }
        it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
        it { is_expected.to contain_exec('generate /tmp/foo.db') }
97
        it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
98
      end
99

100
101
102
103
      context 'when ensuring absence' do
        let (:params) { {
          :ensure => 'absent',
        } }
104

105
106
107
        it { is_expected.to contain_file('/tmp/foo').with_ensure('absent') }
        it { is_expected.to contain_file('/tmp/foo.db').with_ensure('absent') }
        it { is_expected.to contain_exec('generate /tmp/foo.db') }
108
        it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
109
110
      end
    end
111
112
  end
end