Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/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     let(:title) { title }
15     let(:params) { params }
16     let(:pre_condition) do
17       "concat{ '#{p[:target]}': }"
18     end
19
20     it do
21       should contain_concat(p[:target])
22       should contain_concat_file(p[:target])
23       should contain_concat_fragment(title)
24     end
25   end
26
27   context 'title' do
28     ['0', '1', 'a', 'z'].each do |title|
29       it_behaves_like 'fragment', title, {
30         :target  => '/etc/motd',
31         :content => "content for #{title}"
32       }
33     end
34   end # title
35
36   context 'target =>' do
37     ['./etc/motd', 'etc/motd', 'motd_header'].each do |target|
38       context target do
39         it_behaves_like 'fragment', target, {
40           :target  => '/etc/motd',
41           :content => "content for #{target}"
42         }
43       end
44     end
45
46     context 'false' do
47       let(:title) { 'motd_header' }
48       let(:params) {{ :target => false }}
49
50       it 'should fail' do
51         expect { catalogue }.to raise_error(Puppet::Error, /parameter 'target' expects a .*String.*/)
52       end
53     end
54   end # target =>
55
56   context 'content =>' do
57     ['', 'ashp is our hero'].each do |content|
58       context content do
59         it_behaves_like 'fragment', 'motd_header', {
60           :content => content,
61           :target  => '/etc/motd',
62         }
63       end
64     end
65
66     context 'false' do
67       let(:title) { 'motd_header' }
68       let(:params) {{ :content => false, :target => '/etc/motd' }}
69
70       it 'should fail' do
71         expect { catalogue }.to raise_error(Puppet::Error, /parameter 'content' expects a .*String.*/ )
72       end
73     end
74   end # content =>
75
76   context 'source =>' do
77     ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source|
78       context source do
79         it_behaves_like 'fragment', 'motd_header', {
80           :source => source,
81           :target => '/etc/motd',
82         }
83       end
84     end
85
86     context 'false' do
87        let(:title) { 'motd_header' }
88        let(:params) {{ :source => false, :target => '/etc/motd' }}
89
90        it 'should fail' do
91          expect { catalogue }.to raise_error(Puppet::Error, /parameter 'source' expects a .*String.*Array.*/)
92        end
93      end
94   end # source =>
95
96   context 'order =>' do
97     ['', '42', 'a', 'z'].each do |order|
98       context '\'\'' do
99         it_behaves_like 'fragment', 'motd_header', {
100           :order  => order,
101           :target => '/etc/motd',
102         }
103       end
104     end
105
106     context 'false' do
107       let(:title) { 'motd_header' }
108       let(:params) {{ :order => false, :target => '/etc/motd' }}
109
110       it 'should fail' do
111         expect { catalogue }.to raise_error(Puppet::Error, /Evaluation Error.*expects.*Boolean.*/)
112       end
113     end
114
115     context '123:456' do
116       let(:title) { 'motd_header' }
117       let(:params) {{ :order => '123:456', :target => '/etc/motd' }}
118
119       it 'should fail' do
120         expect { catalogue }.to raise_error(Puppet::Error, /cannot contain/)
121       end
122     end
123     context '123/456' do
124       let(:title) { 'motd_header' }
125       let(:params) {{ :order => '123/456', :target => '/etc/motd' }}
126
127       it 'should fail' do
128         expect { catalogue }.to raise_error(Puppet::Error, /cannot contain/)
129       end
130     end
131     context '123\n456' do
132       let(:title) { 'motd_header' }
133       let(:params) {{ :order => "123\n456", :target => '/etc/motd' }}
134
135       it 'should fail' do
136         expect { catalogue }.to raise_error(Puppet::Error, /cannot contain/)
137       end
138     end
139   end # order =>
140
141   context 'more than one content source' do
142     context 'source and content' do
143       let(:title) { 'motd_header' }
144       let(:params) do
145         {
146           :target => '/etc/motd',
147           :source => '/foo',
148           :content => 'bar',
149         }
150       end
151
152       it 'should fail' do
153         expect { catalogue }.to raise_error(Puppet::Error, /Can\'t use \'source\' and \'content\' at the same time/m)
154       end
155     end
156   end # more than one content source
157 end