]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/concat/spec/acceptance/concat_spec.rb
c281954b718a219600f28e5ae58a08354fcf727e
[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['puppetvardir']
9   when 'Darwin'
10     username = 'root'
11     groupname = 'wheel'
12     scriptname = 'concatfragments.rb'
13     vardir = default['puppetvardir']
14   when 'windows'
15     username = 'Administrator'
16     groupname = 'Administrators'
17     scriptname = 'concatfragments.rb'
18     result = on default, "echo #{default['puppetvardir']}"
19     vardir = result.raw_output.chomp
20   when 'Solaris'
21     username = 'root'
22     groupname = 'root'
23     scriptname = 'concatfragments.rb'
24     vardir = default['puppetvardir']
25   else
26     username = 'root'
27     groupname = 'root'
28     scriptname = 'concatfragments.rb'
29     vardir = default['puppetvardir']
30 end
31
32 describe 'basic concat test' do
33   basedir = default.tmpdir('concat')
34   safe_basedir = basedir.gsub(/[\/:]/, '_')
35
36   shared_examples 'successfully_applied' do |pp|
37     it 'applies the manifest twice with no stderr' do
38       apply_manifest(pp, :catch_failures => true)
39       apply_manifest(pp, :catch_changes => true)
40     end
41   end
42
43   context 'owner/group root' do
44     before(:all) do
45       pp = <<-EOS
46         file { '#{basedir}':
47           ensure => directory,
48         }
49       EOS
50       apply_manifest(pp)
51     end
52     pp = <<-EOS
53       concat { '#{basedir}/file':
54         owner => '#{username}',
55         group => '#{groupname}',
56         mode  => '0644',
57       }
58
59       concat::fragment { '1':
60         target  => '#{basedir}/file',
61         content => '1',
62         order   => '01',
63       }
64
65       concat::fragment { '2':
66         target  => '#{basedir}/file',
67         content => '2',
68         order   => '02',
69       }
70     EOS
71
72     it_behaves_like 'successfully_applied', pp
73
74     describe file("#{basedir}/file") do
75       it { should be_file }
76       it { should be_owned_by username }
77       it("should be group", :unless => (fact('osfamily') == 'windows')) { should be_grouped_into groupname }
78       it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
79         should be_mode 644
80       }
81       its(:content) {
82         should match '1'
83         should match '2'
84       }
85     end
86   end
87
88   context 'ensure' do
89     context 'works when set to present with path set' do
90       before(:all) do
91         pp = <<-EOS
92         file { '#{basedir}':
93           ensure => directory,
94         }
95         EOS
96         apply_manifest(pp)
97       end
98       pp="
99         concat { 'file':
100           ensure => present,
101           path   => '#{basedir}/file',
102           mode   => '0644',
103         }
104         concat::fragment { '1':
105           target  => 'file',
106           content => '1',
107           order   => '01',
108         }
109       "
110
111       it_behaves_like 'successfully_applied', pp
112
113       describe file("#{basedir}/file") do
114         it { should be_file }
115         it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
116           should be_mode 644
117         }
118         its(:content) { should match '1' }
119       end
120     end
121     context 'works when set to absent with path set' do
122       before(:all) do
123         pp = <<-EOS
124         file { '#{basedir}':
125           ensure => directory,
126         }
127         EOS
128         apply_manifest(pp)
129       end
130       pp="
131         concat { 'file':
132           ensure => absent,
133           path   => '#{basedir}/file',
134           mode   => '0644',
135         }
136         concat::fragment { '1':
137           target  => 'file',
138           content => '1',
139           order   => '01',
140         }
141       "
142
143       it 'applies the manifest twice with no stderr' do
144         apply_manifest(pp, :catch_failures => true)
145         apply_manifest(pp, :catch_changes => true)
146       end
147
148       describe file("#{basedir}/file") do
149         it { should_not be_file }
150       end
151     end
152   end
153 end