Update concat
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / acceptance / concat_spec.rb
1 require 'spec_helper_acceptance'
2
3 case fact('osfamily')
4   when 'AIX'
5     username = 'root'
6     groupname = 'system'
7     scriptname = 'concatfragments.rb'
8     vardir = default.puppet['vardir']
9     if vardir.nil? or vardir == ''
10       vardir = '/opt/puppetlabs/puppet/cache'
11     end
12   when 'Darwin'
13     username = 'root'
14     groupname = 'wheel'
15     scriptname = 'concatfragments.rb'
16     vardir = default.puppet['vardir']
17     if vardir.nil? or vardir == ''
18       vardir = '/opt/puppetlabs/puppet/cache'
19     end
20   when 'windows'
21     username = 'Administrator'
22     groupname = 'Administrators'
23     scriptname = 'concatfragments.rb'
24     result = on default, "echo #{default.puppet['vardir']}"
25     vardir = result.raw_output.chomp
26   when 'Solaris'
27     username = 'root'
28     groupname = 'root'
29     scriptname = 'concatfragments.rb'
30     vardir = default.puppet['vardir']
31     if vardir.nil? or vardir == ''
32       vardir = '/opt/puppetlabs/puppet/cache'
33     end
34   else
35     username = 'root'
36     groupname = 'root'
37     scriptname = 'concatfragments.rb'
38     vardir = default.puppet['vardir']
39     if vardir.nil? or vardir == ''
40       vardir = '/opt/puppetlabs/puppet/cache'
41     end
42 end
43
44 describe 'basic concat test' do
45   basedir = default.tmpdir('concat')
46   safe_basedir = basedir.gsub(/[\/:]/, '_')
47
48   shared_examples 'successfully_applied' do |pp|
49     it 'applies the manifest twice with no stderr' do
50       apply_manifest(pp, :catch_failures => true)
51       apply_manifest(pp, :catch_changes => true)
52     end
53   end
54
55   context 'owner/group root' do
56     before(:all) do
57       pp = <<-EOS
58         file { '#{basedir}':
59           ensure => directory,
60         }
61       EOS
62       apply_manifest(pp)
63     end
64     pp = <<-EOS
65       concat { '#{basedir}/file':
66         owner => '#{username}',
67         group => '#{groupname}',
68         mode  => '0644',
69       }
70
71       concat::fragment { '1':
72         target  => '#{basedir}/file',
73         content => '1',
74         order   => '01',
75       }
76
77       concat::fragment { '2':
78         target  => '#{basedir}/file',
79         content => '2',
80         order   => '02',
81       }
82     EOS
83
84     it_behaves_like 'successfully_applied', pp
85
86     describe file("#{basedir}/file") do
87       it { should be_file }
88       it { should be_owned_by username }
89       it("should be group", :unless => (fact('osfamily') == 'windows')) { should be_grouped_into groupname }
90       it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
91         should be_mode 644
92       }
93       its(:content) {
94         should match '1'
95         should match '2'
96       }
97     end
98   end
99
100   context 'ensure' do
101     context 'works when set to present with path set' do
102       before(:all) do
103         pp = <<-EOS
104         file { '#{basedir}':
105           ensure => directory,
106         }
107         EOS
108         apply_manifest(pp)
109       end
110       pp="
111         concat { 'file':
112           ensure => present,
113           path   => '#{basedir}/file',
114           mode   => '0644',
115         }
116         concat::fragment { '1':
117           target  => 'file',
118           content => '1',
119           order   => '01',
120         }
121       "
122
123       it_behaves_like 'successfully_applied', pp
124
125       describe file("#{basedir}/file") do
126         it { should be_file }
127         it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
128           should be_mode 644
129         }
130         its(:content) { should match '1' }
131       end
132     end
133     context 'works when set to absent with path set' do
134       before(:all) do
135         pp = <<-EOS
136         file { '#{basedir}':
137           ensure => directory,
138         }
139         EOS
140         apply_manifest(pp)
141       end
142       pp="
143         concat { 'file':
144           ensure => absent,
145           path   => '#{basedir}/file',
146           mode   => '0644',
147         }
148         concat::fragment { '1':
149           target  => 'file',
150           content => '1',
151           order   => '01',
152         }
153       "
154
155       it 'applies the manifest twice with no stderr' do
156         apply_manifest(pp, :catch_failures => true)
157         apply_manifest(pp, :catch_changes => true)
158       end
159
160       describe file("#{basedir}/file") do
161         it { should_not be_file }
162       end
163     end
164     context 'works when set to present with path that has special characters' do
165       filename = fact('osfamily') == 'windows' ? 'file(1)' : 'file(1:2)'
166
167       before(:all) do
168         pp = <<-EOS
169         file { '#{basedir}':
170           ensure => directory,
171         }
172         EOS
173         apply_manifest(pp)
174       end
175       pp="
176         concat { '#{filename}':
177           ensure => present,
178           path   => '#{basedir}/#{filename}',
179           mode   => '0644',
180         }
181         concat::fragment { '1':
182           target  => '#{filename}',
183           content => '1',
184           order   => '01',
185         }
186       "
187
188       it_behaves_like 'successfully_applied', pp
189
190       describe file("#{basedir}/#{filename}") do
191         it { should be_file }
192         it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
193           should be_mode 644
194         }
195         its(:content) { should match '1' }
196       end
197     end
198     context 'noop properly' do
199       before(:all) do
200         pp = <<-EOS
201         file { '#{basedir}':
202           ensure => directory,
203         }
204         EOS
205         apply_manifest(pp)
206       end
207       pp="
208         concat { 'file':
209           ensure => present,
210           path   => '#{basedir}/file',
211           mode   => '0644',
212           noop   => true,
213         }
214         concat::fragment { '1':
215           target  => 'file',
216           content => '1',
217           order   => '01',
218         }
219       "
220
221       it_behaves_like 'successfully_applied', pp
222
223       describe file("#{basedir}/file") do
224         it { should_not be_file }
225       end
226     end
227   end
228 end