File: concat_fragment_spec.rb

package info (click to toggle)
puppet-module-puppetlabs-concat 7.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 532 kB
  • sloc: ruby: 2,584; sh: 46; makefile: 2
file content (158 lines) | stat: -rw-r--r-- 4,320 bytes parent folder | download
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# frozen_string_literal: true

require 'spec_helper'

describe 'concat::fragment' do
  shared_examples 'fragment' do |title, params|
    params = {} if params.nil?

    p = {
      content: nil,
      source: nil,
      order: 10,
    }.merge(params)

    let(:title) { title }
    let(:params) { params }
    let(:pre_condition) do
      "concat{ '#{p[:target]}': }"
    end

    it do
      is_expected.to contain_concat(p[:target])
    end
    it do
      is_expected.to contain_concat_file(p[:target])
    end
    it do
      is_expected.to contain_concat_fragment(title)
    end
  end

  context 'when title' do
    ['0', '1', 'a', 'z'].each do |title|
      it_behaves_like 'fragment', title, target: '/etc/motd',
                                         content: "content for #{title}"
    end
  end
  # title

  context 'when target =>' do
    ['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
      context target do
        it_behaves_like 'fragment', target, target: '/etc/motd',
                                            content: "content for #{target}"
      end
    end

    context 'when false' do
      let(:title) { 'motd_header' }
      let(:params) { { target: false } }

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'target' expects a .*String.*})
      end
    end
  end
  # target =>

  context 'when content =>' do
    ['', 'ashp is our hero'].each do |content|
      context content do
        it_behaves_like 'fragment', 'motd_header', content: content,
                                                   target: '/etc/motd'
      end
    end

    context 'when false' do
      let(:title) { 'motd_header' }
      let(:params) { { content: false, target: '/etc/motd' } }

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{expects a value of type Undef( or String|, String, or Deferred), got Boolean})
      end
    end
  end
  # content =>

  context 'when source =>' do
    ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source|
      context source do
        it_behaves_like 'fragment', 'motd_header',           source: source,
                                                             target: '/etc/motd'
      end
    end

    context 'when false' do
      let(:title) { 'motd_header' }
      let(:params) { { source: false, target: '/etc/motd' } }

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{parameter 'source' expects a .*String.*Array.*})
      end
    end
  end
  # source =>

  context 'when order =>' do
    ['', '42', 'a', 'z'].each do |order|
      context "'#{order}'" do
        it_behaves_like 'fragment', 'motd_header',           order: order,
                                                             target: '/etc/motd'
      end
    end

    context 'when false' do
      let(:title) { 'motd_header' }
      let(:params) { { order: false, target: '/etc/motd' } }

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{Evaluation Error.*expects.*Boolean.*})
      end
    end

    context 'when 123:456' do
      let(:title) { 'motd_header' }
      let(:params) { { order: '123:456', target: '/etc/motd' } }

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
      end
    end
    context 'when 23/456' do
      let(:title) { 'motd_header' }
      let(:params) { { order: '123/456', target: '/etc/motd' } }

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
      end
    end
    context 'when 123\n456' do
      let(:title) { 'motd_header' }
      let(:params) { { order: "123\n456", target: '/etc/motd' } }

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{cannot contain})
      end
    end
  end
  # order =>

  context 'with more than one content source' do
    context 'with source and content' do
      let(:title) { 'motd_header' }
      let(:params) do
        {
          target: '/etc/motd',
          source: '/foo',
          content: 'bar',
        }
      end

      it 'fails' do
        expect { catalogue }.to raise_error(Puppet::Error, %r{Can\'t use \'source\' and \'content\' at the same time}m)
      end
    end
  end
  # more than one content source
end