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

describe 'postfix::hash' do
  let (:title) { '/tmp/foo' }
  let (:facts) { {
Mickaël Canévet's avatar
Mickaël Canévet committed
6
7
    :lsbdistcodename => 'wheezy',
    :osfamily        => 'Debian',
8
    :path            => '/foo/bar',
9
  } }
Mickaël Canévet's avatar
Mickaël Canévet committed
10
11
12
  let :pre_condition do
    "class { '::postfix': }"
  end
13
14
15
16
17
18
19

  context 'when passing wrong type for ensure' do
    let (:params) { {
      :ensure => ['present'],
    } }
    it 'should fail' do
      expect {
Raphaël Pinson's avatar
Raphaël Pinson committed
20
        is_expected.to contain_file('/tmp/foo')
21
22
23
24
25
26
27
28
29
30
      }.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 {
Raphaël Pinson's avatar
Raphaël Pinson committed
31
        is_expected.to contain_file('/tmp/foo')
32
33
34
35
36
37
38
39
      }.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 {
Raphaël Pinson's avatar
Raphaël Pinson committed
40
        is_expected.to contain_file('/tmp/foo')
41
42
43
44
45
46
47
48
49
50
51
52
      }.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 {
Raphaël Pinson's avatar
Raphaël Pinson committed
53
        is_expected.to contain_file('/tmp/foo')
54
55
56
57
58
59
60
61
62
      }.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/)
    end
  end

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

Raphaël Pinson's avatar
Raphaël Pinson committed
63
    it { is_expected.to contain_file('/tmp/foo').with(
64
65
66
67
        :ensure => 'present',
        :source => '/tmp/bar'
      ).without(:content)
    }
Raphaël Pinson's avatar
Raphaël Pinson committed
68
69
    it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
    it { is_expected.to contain_exec('generate /tmp/foo.db') }
70
71
72
73
74
75
76
  end

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

Raphaël Pinson's avatar
Raphaël Pinson committed
77
    it { is_expected.to contain_file('/tmp/foo').with(
78
79
80
81
        :ensure  => 'present',
        :content => 'bar'
      ).without(:source)
    }
Raphaël Pinson's avatar
Raphaël Pinson committed
82
83
    it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
    it { is_expected.to contain_exec('generate /tmp/foo.db') }
84
85
86
  end

  context 'when not passing source or content' do
Raphaël Pinson's avatar
Raphaël Pinson committed
87
    it { is_expected.to contain_file('/tmp/foo').with(
88
89
90
        :ensure  => 'present'
      ).without(:source).without(:content)
    }
Raphaël Pinson's avatar
Raphaël Pinson committed
91
92
    it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
    it { is_expected.to contain_exec('generate /tmp/foo.db') }
93
94
95
96
97
98
99
  end

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

Raphaël Pinson's avatar
Raphaël Pinson committed
100
101
102
    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') }
103
104
  end
end