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