]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/concat/spec/unit/defines/concat_fragment_spec.rb
upgrade to concat 2.0.0
[dsa-puppet.git] / 3rdparty / modules / concat / spec / unit / defines / concat_fragment_spec.rb
1 require 'spec_helper'
2
3 describe 'concat::fragment', :type => :define do
4
5   shared_examples 'fragment' do |title, params|
6     params = {} if params.nil?
7
8     p = {
9       :content => nil,
10       :source  => nil,
11       :order   => 10,
12     }.merge(params)
13
14     id               = 'root'
15     gid              = 'root'
16
17     let(:title) { title }
18     let(:params) { params }
19     let(:pre_condition) do
20       "concat{ '#{p[:target]}': }"
21     end
22
23     it do
24       should contain_concat(p[:target])
25       should contain_concat_file(p[:target])
26       should contain_concat_fragment(title)
27     end
28   end
29
30   context 'title' do
31     ['0', '1', 'a', 'z'].each do |title|
32       it_behaves_like 'fragment', title, {
33         :target  => '/etc/motd',
34         :content => "content for #{title}"
35       }
36     end
37   end # title
38
39   context 'target =>' do
40     ['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
41       context target do
42         it_behaves_like 'fragment', target, {
43           :target  => '/etc/motd',
44           :content => "content for #{target}"
45         }
46       end
47     end
48
49     context 'false' do
50       let(:title) { 'motd_header' }
51       let(:params) {{ :target => false }}
52
53       it 'should fail' do
54         expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
55       end
56     end
57   end # target =>
58
59   context 'content =>' do
60     ['', 'ashp is our hero'].each do |content|
61       context content do
62         it_behaves_like 'fragment', 'motd_header', {
63           :content => content,
64           :target  => '/etc/motd',
65         }
66       end
67     end
68
69     context 'false' do
70       let(:title) { 'motd_header' }
71       let(:params) {{ :content => false, :target => '/etc/motd' }}
72
73       it 'should fail' do
74         expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
75       end
76     end
77   end # content =>
78
79   context 'source =>' do
80     ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source|
81       context source do
82         it_behaves_like 'fragment', 'motd_header', {
83           :source => source,
84           :target => '/etc/motd',
85         }
86       end
87     end
88
89     context 'false' do
90       let(:title) { 'motd_header' }
91       let(:params) {{ :source => false, :target => '/etc/motd' }}
92
93       it 'should fail' do
94         expect { catalogue }.to raise_error(Puppet::Error, /is not a string or an Array/)
95       end
96     end
97   end # source =>
98
99   context 'more than one content source' do
100     context 'source and content' do
101       let(:title) { 'motd_header' }
102       let(:params) do
103         {
104           :target => '/etc/motd', 
105           :source => '/foo',
106           :content => 'bar',
107         }
108       end
109
110       it 'should fail' do
111         expect { catalogue }.to raise_error(Puppet::Error, /Can't use 'source' and 'content' at the same time/)
112       end
113     end
114   end # more than one content source
115 end