]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/spec/defines/custom_config_spec.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / spec / defines / custom_config_spec.rb
1 require 'spec_helper'
2
3 describe 'apache::custom_config', :type => :define do
4   let :pre_condition do
5     'class { "apache": }'
6   end
7   let :title do
8     'rspec'
9   end
10   let :facts do
11     {
12       :osfamily               => 'Debian',
13       :operatingsystemrelease => '6',
14       :concat_basedir         => '/',
15       :lsbdistcodename        => 'squeeze',
16       :operatingsystem        => 'Debian',
17       :id                     => 'root',
18       :kernel                 => 'Linux',
19       :path                   => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
20       :is_pe                  => false,
21     }
22   end
23   context 'defaults with content' do
24     let :params do
25       {
26         'content' => '# Test',
27       }
28     end
29     it { is_expected.to contain_exec("service notify for rspec").with({
30       'refreshonly' => 'true',
31       'subscribe'   => 'File[apache_rspec]',
32       'command'     => '/usr/sbin/apachectl -t',
33       'notify'      => 'Class[Apache::Service]',
34       'before'      => 'Exec[remove rspec if invalid]',
35     })
36     }
37     it { is_expected.to contain_exec("remove rspec if invalid").with({
38       'unless'      => '/usr/sbin/apachectl -t',
39       'subscribe'   => 'File[apache_rspec]',
40       'refreshonly' => 'true',
41     })
42     }
43     it { is_expected.to contain_file("apache_rspec").with({
44       'ensure'  => 'present',
45       'content' => '# Test',
46       'require' => 'Package[httpd]',
47     })
48     }
49   end
50   context 'set everything with source' do
51     let :params do
52       {
53         'confdir'        => '/dne',
54         'priority'       => '30',
55         'source'         => 'puppet:///modules/apache/test',
56         'verify_command' => '/bin/true',
57       }
58     end
59     it { is_expected.to contain_exec("service notify for rspec").with({
60       'command'     => '/bin/true',
61     })
62     }
63     it { is_expected.to contain_exec("remove rspec if invalid").with({
64       'command'     => '/bin/rm /dne/30-rspec.conf',
65       'unless'      => '/bin/true',
66     })
67     }
68     it { is_expected.to contain_file("apache_rspec").with({
69       'path'   => '/dne/30-rspec.conf',
70       'ensure'  => 'present',
71       'source' => 'puppet:///modules/apache/test',
72       'require' => 'Package[httpd]',
73     })
74     }
75   end
76   context 'verify_config => false' do
77     let :params do
78       {
79         'content'       => '# test',
80         'verify_config' => false,
81       }
82     end
83     it { is_expected.to_not contain_exec('service notify for rspec') }
84     it { is_expected.to_not contain_exec('remove rspec if invalid') }
85     it { is_expected.to contain_file('apache_rspec').with({
86       'notify' => 'Class[Apache::Service]'
87     })
88     }
89   end
90   context 'ensure => absent' do
91     let :params do
92       {
93         'ensure' => 'absent'
94       }
95     end
96     it { is_expected.to_not contain_exec('service notify for rspec') }
97     it { is_expected.to_not contain_exec('remove rspec if invalid') }
98     it { is_expected.to contain_file('apache_rspec').with({
99       'ensure' => 'absent',
100     })
101     }
102   end
103   describe 'validation' do
104     context 'both content and source' do
105       let :params do
106         {
107           'content' => 'foo',
108           'source'  => 'bar',
109         }
110       end
111       it do
112         expect {
113           catalogue
114         }.to raise_error(Puppet::Error, /Only one of \$content and \$source can be specified\./)
115       end
116     end
117     context 'neither content nor source' do
118       it do
119         expect {
120           catalogue
121         }.to raise_error(Puppet::Error, /One of \$content and \$source must be specified\./)
122       end
123     end
124     context 'bad ensure' do
125       let :params do
126         {
127           'content' => 'foo',
128           'ensure'  => 'foo',
129         }
130       end
131       it do
132         expect {
133           catalogue
134         }.to raise_error(Puppet::Error, /is not supported for ensure/)
135       end
136     end
137   end
138 end