postfix_hash_spec.rb 2.55 KB
Newer Older
1
2
3
4
5
6
require 'spec_helper'

describe 'postfix::hash' do
  let (:title) { '/tmp/foo' }
  let (:facts) { {
    :osfamily => 'Debian',
7
    :needs_postfix_class => true,
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
100
  } }

  context 'when passing wrong type for ensure' do
    let (:params) { {
      :ensure => ['present'],
    } }
    it 'should fail' do
      expect {
        should contain_file('/tmp/foo')
      }.to raise_error(Puppet::Error, /\["present"\] is not a string/)
    end
  end

  context 'when passing wrong value for ensure' do
    let (:params) { {
      :ensure => 'running',
    } }
    it 'should fail' do
      expect {
        should contain_file('/tmp/foo')
      }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
    end
  end

  context 'when passing wrong value for title' do
    let (:title) { 'foo' }
    it 'should fail' do
      expect {
        should contain_file('/tmp/foo')
      }.to raise_error(Puppet::Error, /"foo" is not an absolute path/)
    end
  end

  context 'when passing both source and content' do
    let (:params) { {
      :source  => '/tmp/bar',
      :content => 'bar',
    } }

    it 'should fail' do
      expect {
        should contain_file('/tmp/foo')
      }.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/)
    end
  end

  context 'when passing source' do
    let (:params) { {
      :source  => '/tmp/bar',
    } }

    it { should contain_file('/tmp/foo').with(
        :ensure => 'present',
        :source => '/tmp/bar'
      ).without(:content)
    }
    it { should contain_file('/tmp/foo.db').with_ensure('present') }
    it { should contain_exec('generate /tmp/foo.db') }
  end

  context 'when passing content' do
    let (:params) { {
      :content => 'bar',
    } }

    it { should contain_file('/tmp/foo').with(
        :ensure  => 'present',
        :content => 'bar'
      ).without(:source)
    }
    it { should contain_file('/tmp/foo.db').with_ensure('present') }
    it { should contain_exec('generate /tmp/foo.db') }
  end

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

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

    it { should contain_file('/tmp/foo').with_ensure('absent') }
    it { should contain_file('/tmp/foo.db').with_ensure('absent') }
    it { should contain_exec('generate /tmp/foo.db') }
  end
end