summaryrefslogtreecommitdiff
path: root/spec/defines/augeas_lens_spec.rb
blob: 7feeefbdbdbd2a5dbeb528df2d71a583b7aef6f5 (plain)
1
2
3
4
5
6
7
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
101
102
103
104
105
106
107
108
109
110
111
112
require 'spec_helper'

describe 'augeas::lens' do
  let (:title) { 'foo' }

  context 'when not declaring augeas class first' do
    let (:params) do
      {
        :lens_source => '/tmp/foo.aug',
      }
    end

    it 'should error' do
      expect {
        is_expected.to contain_file('/usr/share/augeas/lenses/foo.aug')
      }.to raise_error(Puppet::Error, /You must declare the augeas class/)
    end
  end

  context 'when declaring augeas class first' do

    on_supported_os.each do |os, facts|
      context "on #{os}" do
        let(:facts) do
          facts.merge({
            :augeasversion => :undef,
          })
        end

        context 'With standard augeas version' do

          let(:pre_condition) do
            "class { '::augeas': }"
          end

          context 'when no lens_source is passed' do
            it 'should error' do
              expect {
                is_expected.to contain_file('/usr/share/augeas/lenses/foo.aug')
              }.to raise_error(Puppet::Error, /Must pass lens_source/)
            end
          end

          context 'when lens_source is passed' do
            let (:params) do
              {
                :lens_source => '/tmp/foo.aug',
              }
            end

            it { is_expected.to contain_file('/usr/share/augeas/lenses/foo.aug') }
            it { is_expected.to contain_exec('Typecheck lens foo') }
            it { is_expected.not_to contain_file('/usr/share/augeas/lenses/tests/test_foo.aug') }
            it { is_expected.not_to contain_exec('Test lens foo') }
          end

          context 'when lens_source and test_source are passed' do
            let (:params) do
              {
                :lens_source => '/tmp/foo.aug',
                :test_source => '/tmp/test_foo.aug',
              }
            end

            it { is_expected.to contain_file('/usr/share/augeas/lenses/foo.aug') }
            it { is_expected.to contain_exec('Typecheck lens foo') }
            it { is_expected.to contain_file('/usr/share/augeas/lenses/tests/test_foo.aug') }
            it { is_expected.to contain_exec('Test lens foo') }
          end
        end

        context 'when stock_since is passed and augeas is older' do
          let (:params) do
            {
              :lens_source => '/tmp/foo.aug',
              :stock_since => '1.2.3',
            }
          end

          let(:pre_condition) do
            "class { '::augeas': version => '1.0.0' }"
          end

          it { is_expected.to contain_file('/usr/share/augeas/lenses/foo.aug') }
          it { is_expected.to contain_exec('Typecheck lens foo') }
        end

        context 'when stock_since is passed and augeas is newer' do
          let (:params) do
            {
              :lens_source => '/tmp/foo.aug',
              :stock_since => '1.2.3',
            }
          end

          let(:pre_condition) do
            "class { '::augeas': version => '1.3.0' }"
          end

          it do
            pending "undefined method `negative_failure_message'"
            is_expected.not_to contain_file('/usr/share/augeas/lenses/foo.aug')
          end
          it do
            pending "undefined method `negative_failure_message'"
            is_expected.not_to contain_exec('Typecheck lens foo')
          end
        end
      end
    end
  end
end