]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/classes/mod/php_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / classes / mod / php_spec.rb
1 require 'spec_helper'
2
3 describe 'apache::mod::php', :type => :class do
4   describe "on a Debian OS" do
5     let :facts do
6       {
7         :osfamily               => 'Debian',
8         :operatingsystemrelease => '6',
9         :concat_basedir         => '/dne',
10         :lsbdistcodename        => 'squeeze',
11         :operatingsystem        => 'Debian',
12         :id                     => 'root',
13         :kernel                 => 'Linux',
14         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
15         :is_pe                  => false,
16       }
17     end
18     context "with mpm_module => prefork" do
19       let :pre_condition do
20         'class { "apache": mpm_module => prefork, }'
21       end
22       it { is_expected.to contain_class("apache::params") }
23       it { is_expected.to contain_class("apache::mod::prefork") }
24       it { is_expected.to contain_apache__mod('php5') }
25       it { is_expected.to contain_package("libapache2-mod-php5") }
26       it { is_expected.to contain_file("php5.load").with(
27         :content => "LoadModule php5_module /usr/lib/apache2/modules/libphp5.so\n"
28       ) }
29     end
30     context "with mpm_module => itk" do
31       let :pre_condition do
32         'class { "apache": mpm_module => itk, }'
33       end
34       it { is_expected.to contain_class("apache::params") }
35       it { is_expected.to contain_class("apache::mod::itk") }
36       it { is_expected.to contain_apache__mod('php5') }
37       it { is_expected.to contain_package("libapache2-mod-php5") }
38       it { is_expected.to contain_file("php5.load").with(
39         :content => "LoadModule php5_module /usr/lib/apache2/modules/libphp5.so\n"
40       ) }
41     end
42   end
43   describe "on a RedHat OS" do
44     let :facts do
45       {
46         :osfamily               => 'RedHat',
47         :operatingsystemrelease => '6',
48         :concat_basedir         => '/dne',
49         :operatingsystem        => 'RedHat',
50         :id                     => 'root',
51         :kernel                 => 'Linux',
52         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
53         :is_pe                  => false,
54       }
55     end
56     context "with default params" do
57       let :pre_condition do
58         'class { "apache": }'
59       end
60       it { is_expected.to contain_class("apache::params") }
61       it { is_expected.to contain_apache__mod('php5') }
62       it { is_expected.to contain_package("php") }
63       it { is_expected.to contain_file("php5.load").with(
64         :content => "LoadModule php5_module modules/libphp5.so\n"
65       ) }
66     end
67     context "with alternative package name" do let :pre_condition do
68         'class { "apache": }'
69       end
70       let :params do
71         { :package_name => 'php54'}
72       end
73       it { is_expected.to contain_package("php54") }
74     end
75     context "with alternative path" do let :pre_condition do
76         'class { "apache": }'
77       end
78       let :params do
79         { :path => 'alternative-path'}
80       end
81       it { is_expected.to contain_file("php5.load").with(
82         :content => "LoadModule php5_module alternative-path\n"
83       ) }
84     end
85     context "with alternative extensions" do let :pre_condition do
86         'class { "apache": }'
87       end
88       let :params do
89         { :extensions => ['.php','.php5']}
90       end
91       it { is_expected.to contain_file("php5.conf").with_content(/AddHandler php5-script .php .php5\n/) }
92     end
93     context "with specific version" do
94       let :pre_condition do
95         'class { "apache": }'
96       end
97       let :params do
98         { :package_ensure => '5.3.13'}
99       end
100       it { is_expected.to contain_package("php").with(
101         :ensure => '5.3.13'
102       ) }
103     end
104     context "with mpm_module => prefork" do
105       let :pre_condition do
106         'class { "apache": mpm_module => prefork, }'
107       end
108       it { is_expected.to contain_class("apache::params") }
109       it { is_expected.to contain_class("apache::mod::prefork") }
110       it { is_expected.to contain_apache__mod('php5') }
111       it { is_expected.to contain_package("php") }
112       it { is_expected.to contain_file("php5.load").with(
113         :content => "LoadModule php5_module modules/libphp5.so\n"
114       ) }
115     end
116     context "with mpm_module => itk" do
117       let :pre_condition do
118         'class { "apache": mpm_module => itk, }'
119       end
120       it 'should raise an error' do
121         expect { expect(subject).to contain_class("apache::mod::itk") }.to raise_error Puppet::Error, /Unsupported osfamily RedHat/
122       end
123     end
124   end
125   describe "on a FreeBSD OS" do
126     let :facts do
127       {
128         :osfamily               => 'FreeBSD',
129         :operatingsystemrelease => '10',
130         :concat_basedir         => '/dne',
131         :operatingsystem        => 'FreeBSD',
132         :id                     => 'root',
133         :kernel                 => 'FreeBSD',
134         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
135         :is_pe                  => false,
136       }
137     end
138     context "with mpm_module => prefork" do
139       let :pre_condition do
140         'class { "apache": mpm_module => prefork, }'
141       end
142       it { is_expected.to contain_class('apache::params') }
143       it { is_expected.to contain_apache__mod('php5') }
144       it { is_expected.to contain_package("www/mod_php5") }
145       it { is_expected.to contain_file('php5.load') }
146     end
147     context "with mpm_module => itk" do
148       let :pre_condition do
149         'class { "apache": mpm_module => itk, }'
150       end
151       it { is_expected.to contain_class('apache::params') }
152       it { is_expected.to contain_class('apache::mod::itk') }
153       it { is_expected.to contain_apache__mod('php5') }
154       it { is_expected.to contain_package("www/mod_php5") }
155       it { is_expected.to contain_file('php5.load') }
156     end
157   end
158   describe "on a Gentoo OS" do
159     let :facts do
160       {
161         :osfamily               => 'Gentoo',
162         :operatingsystem        => 'Gentoo',
163         :operatingsystemrelease => '3.16.1-gentoo',
164         :concat_basedir         => '/dne',
165         :id                     => 'root',
166         :kernel                 => 'Linux',
167         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin',
168         :is_pe                  => false,
169       }
170     end
171     context "with mpm_module => prefork" do
172       let :pre_condition do
173         'class { "apache": mpm_module => prefork, }'
174       end
175       it { is_expected.to contain_class('apache::params') }
176       it { is_expected.to contain_apache__mod('php5') }
177       it { is_expected.to contain_package("dev-lang/php") }
178       it { is_expected.to contain_file('php5.load') }
179     end
180     context "with mpm_module => itk" do
181       let :pre_condition do
182         'class { "apache": mpm_module => itk, }'
183       end
184       it { is_expected.to contain_class('apache::params') }
185       it { is_expected.to contain_class('apache::mod::itk') }
186       it { is_expected.to contain_apache__mod('php5') }
187       it { is_expected.to contain_package("dev-lang/php") }
188       it { is_expected.to contain_file('php5.load') }
189     end
190   end
191   describe "OS independent tests" do
192     let :facts do
193       {
194         :osfamily               => 'Debian',
195         :operatingsystem        => 'Debian',
196         :operatingsystemrelease => '6',
197         :kernel                 => 'Linux',
198         :lsbdistcodename        => 'squeeze',
199         :concat_basedir         => '/dne',
200         :id                     => 'root',
201         :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
202         :is_pe                  => false,
203       }
204     end
205     context 'with content param' do
206       let :pre_condition do
207         'class { "apache": mpm_module => prefork, }'
208       end
209       let :params do
210         { :content => 'somecontent' }
211       end
212       it { should contain_file('php5.conf').with(
213         :content => 'somecontent'
214       ) }
215     end
216     context 'with template param' do
217       let :pre_condition do
218         'class { "apache": mpm_module => prefork, }'
219       end
220       let :params do
221         { :template => 'apache/mod/php5.conf.erb' }
222       end
223       it { should contain_file('php5.conf').with(
224         :content => /^# PHP is an HTML-embedded scripting language which attempts to make it/
225       ) }
226     end
227     context 'with source param' do
228       let :pre_condition do
229         'class { "apache": mpm_module => prefork, }'
230       end
231       let :params do
232         { :source => 'some-path' }
233       end
234       it { should contain_file('php5.conf').with(
235         :source => 'some-path'
236       ) }
237     end
238     context 'content has priority over template' do
239       let :pre_condition do
240         'class { "apache": mpm_module => prefork, }'
241       end
242       let :params do
243         {
244           :template => 'apache/mod/php5.conf.erb',
245           :content  => 'somecontent'
246         }
247       end
248       it { should contain_file('php5.conf').with(
249         :content => 'somecontent'
250       ) }
251     end
252     context 'source has priority over template' do
253       let :pre_condition do
254         'class { "apache": mpm_module => prefork, }'
255       end
256       let :params do
257         {
258           :template => 'apache/mod/php5.conf.erb',
259           :source   => 'some-path'
260         }
261       end
262       it { should contain_file('php5.conf').with(
263         :source => 'some-path'
264       ) }
265     end
266     context 'source has priority over content' do
267       let :pre_condition do
268         'class { "apache": mpm_module => prefork, }'
269       end
270       let :params do
271         {
272           :content => 'somecontent',
273           :source  => 'some-path'
274         }
275       end
276       it { should contain_file('php5.conf').with(
277         :source => 'some-path'
278       ) }
279     end
280     context 'with mpm_module => worker' do
281       let :pre_condition do
282         'class { "apache": mpm_module => worker, }'
283       end
284       it 'should raise an error' do
285         expect { expect(subject).to contain_apache__mod('php5') }.to raise_error Puppet::Error, /mpm_module => 'prefork' or mpm_module => 'itk'/
286       end
287     end
288   end
289 end