Skip to content

Commit 888dd0c

Browse files
author
Joshua Hoblitt
committed
improve consistency of class pureftpd::config* tests
1 parent b3191a3 commit 888dd0c

File tree

4 files changed

+183
-288
lines changed

4 files changed

+183
-288
lines changed

spec/classes/config_ldap_spec.rb

+46-181
Original file line numberDiff line numberDiff line change
@@ -1,204 +1,69 @@
11
require 'spec_helper'
22

3+
conf_options = [
4+
'LDAPServer',
5+
'LDAPPort',
6+
'LDAPBindDN',
7+
'LDAPBindPW',
8+
'LDAPBaseDN',
9+
'LDAPFilter',
10+
'LDAPHomeDir',
11+
'LDAPVersion',
12+
'LDAPDefaultUID',
13+
'LDAPForceDefaultUID',
14+
'LDAPDefaultGID',
15+
'LDAPForceDefaultGID',
16+
'LDAPUseTLS',
17+
'LDAPAuthMethod',
18+
]
19+
320
describe 'pureftpd::config::ldap' do
4-
let(:facts) {{ :osfamily=> 'RedHat' }}
521

6-
describe 'with no params' do
7-
it do
8-
should contain_class('pureftpd::config::ldap')
9-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
10-
.with_ensure('file').with_content('')
11-
end
12-
end
22+
shared_examples 'config' do |params, content|
23+
let(:facts) {{ :osfamily=> 'RedHat' }}
24+
let(:params) { params }
1325

14-
describe 'with ldapserver' do
15-
let(:params) {{ :ldapserver => 'ldap.example.com' }}
1626
it do
17-
should contain_class('pureftpd::config::ldap')
27+
should include_class('pureftpd::config::ldap')
1828
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
1929
.with_ensure('file') \
20-
.with_content(/^LDAPServer ldap.example.com/)
30+
.with_content(content)
2131
end
2232
end
2333

24-
describe 'with ldapport' do
25-
let(:params) {{ :ldapport => '389' }}
26-
it do
27-
should contain_class('pureftpd::config::ldap')
28-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
29-
.with_ensure('file') \
30-
.with_content(/^LDAPPort 389/)
31-
end
32-
end
34+
all_params = {}
35+
all_content = ''
36+
value = 'xxx'
3337

34-
describe 'with ldapbinddn' do
35-
let(:params) {{ :ldapbinddn => 'cn=Manager,dc=c9x,dc=org' }}
36-
it do
37-
should contain_class('pureftpd::config::ldap')
38-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
39-
.with_ensure('file') \
40-
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/)
41-
end
42-
end
43-
44-
describe 'with ldapbindpw' do
45-
let(:params) {{ :ldapbindpw => 'r00tPaSsw0rD' }}
46-
it do
47-
should contain_class('pureftpd::config::ldap')
48-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
49-
.with_ensure('file') \
50-
.with_content(/^LDAPBindPW r00tPaSsw0rD/)
51-
end
52-
end
38+
# accumutate all of the params and content strings as we test each individual
39+
# option so we can use them for the next test
40+
context 'one option at a time' do
41+
conf_options.each do |option|
42+
params = {}
43+
params[option.downcase.to_sym] = value
44+
content = sprintf("%-19s %s\n", option, value)
5345

54-
describe 'with ldapbasedn' do
55-
let(:params) {{ :ldapbasedn => 'cn=Users,dc=c9x,dc=org' }}
56-
it do
57-
should contain_class('pureftpd::config::ldap')
58-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
59-
.with_ensure('file') \
60-
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/)
61-
end
62-
end
46+
all_params.merge!(params)
47+
all_content += content
6348

64-
describe 'with ldapfilter' do
65-
let(:params) {{ :ldapfilter => '(&(objectClass=posixAccount)(uid=\L))' }}
66-
it do
67-
should contain_class('pureftpd::config::ldap')
68-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
69-
.with_ensure('file') \
70-
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))')))
49+
it_behaves_like 'config', params, content
7150
end
7251
end
73-
74-
describe 'with ldaphomedir' do
75-
let(:params) {{ :ldaphomedir => 'homeDirectory' }}
76-
it do
77-
should contain_class('pureftpd::config::ldap')
78-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
79-
.with_ensure('file') \
80-
.with_content(/^LDAPHomeDir homeDirectory/)
81-
end
52+
53+
# test all of the known options at once this works because the ordering of
54+
# options values in the output file is fixed
55+
context 'all options' do
56+
it_behaves_like 'config', all_params, all_content
8257
end
8358

84-
describe 'with ldapversion' do
85-
let(:params) {{ :ldapversion => '3' }}
86-
it do
87-
should contain_class('pureftpd::config::ldap')
88-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
89-
.with_ensure('file') \
90-
.with_content(/^LDAPVersion 3/)
91-
end
92-
end
59+
context 'invalid param' do
60+
let(:facts) {{ :osfamily=> 'RedHat' }}
61+
let(:params) {{ :foo => 'bar' }}
9362

94-
describe 'with ldapdefaultuid' do
95-
let(:params) {{ :ldapdefaultuid => '100' }}
96-
it do
97-
should contain_class('pureftpd::config::ldap')
98-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
99-
.with_ensure('file') \
100-
.with_content(/^LDAPDefaultUID 100/)
63+
it 'should fail' do
64+
expect { should include_class('pureftpd::config::ldap') }.
65+
to raise_error(Puppet::Error, /Invalid parameter foo/)
10166
end
10267
end
10368

104-
describe 'with ldapforcedefaultuid' do
105-
let(:params) {{ :ldapforcedefaultuid => 'False' }}
106-
it do
107-
should contain_class('pureftpd::config::ldap')
108-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
109-
.with_ensure('file') \
110-
.with_content(/^LDAPForceDefaultUID False/)
111-
end
112-
end
113-
114-
describe 'with ldapdefaultgid' do
115-
let(:params) {{ :ldapdefaultgid => '100' }}
116-
it do
117-
should contain_class('pureftpd::config::ldap')
118-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
119-
.with_ensure('file') \
120-
.with_content(/^LDAPDefaultGID 100/)
121-
end
122-
end
123-
124-
describe 'with ldapdefaultgid' do
125-
let(:params) {{ :ldapdefaultgid => '100' }}
126-
it do
127-
should contain_class('pureftpd::config::ldap')
128-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
129-
.with_ensure('file') \
130-
.with_content(/^LDAPDefaultGID 100/)
131-
end
132-
end
133-
134-
describe 'with ldapforcedefaultgid' do
135-
let(:params) {{ :ldapforcedefaultgid => 'False' }}
136-
it do
137-
should contain_class('pureftpd::config::ldap')
138-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
139-
.with_ensure('file') \
140-
.with_content(/^LDAPForceDefaultGID False/)
141-
end
142-
end
143-
144-
describe 'with ldapusetls' do
145-
let(:params) {{ :ldapusetls => 'False' }}
146-
it do
147-
should contain_class('pureftpd::config::ldap')
148-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
149-
.with_ensure('file') \
150-
.with_content(/^LDAPUseTLS False/)
151-
end
152-
end
153-
154-
describe 'with ldapauthmethod' do
155-
let(:params) {{ :ldapauthmethod => 'PASSWORD' }}
156-
it do
157-
should contain_class('pureftpd::config::ldap')
158-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
159-
.with_ensure('file') \
160-
.with_content(/^LDAPAuthMethod PASSWORD/)
161-
end
162-
end
163-
164-
describe 'with everything' do
165-
let(:params) {{
166-
:ldapserver => 'ldap.example.com',
167-
:ldapauthmethod => 'PASSWORD',
168-
:ldapport => '389',
169-
:ldapbinddn => 'cn=Manager,dc=c9x,dc=org',
170-
:ldapbindpw => 'r00tPaSsw0rD',
171-
:ldapbasedn => 'cn=Users,dc=c9x,dc=org',
172-
:ldapfilter => '(&(objectClass=posixAccount)(uid=\L))',
173-
:ldaphomedir => 'homeDirectory',
174-
:ldapversion => '3',
175-
:ldapdefaultuid => '100',
176-
:ldapforcedefaultuid => 'False',
177-
:ldapdefaultgid => '100',
178-
:ldapdefaultgid => '100',
179-
:ldapforcedefaultgid => 'False',
180-
:ldapusetls => 'False',
181-
:ldapauthmethod => 'PASSWORD',
182-
}}
183-
it do
184-
should contain_class('pureftpd::config::ldap')
185-
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
186-
.with_ensure('file') \
187-
.with_content(/^LDAPServer ldap.example.com/) \
188-
.with_content(/^LDAPPort 389/) \
189-
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/) \
190-
.with_content(/^LDAPBindPW r00tPaSsw0rD/) \
191-
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/) \
192-
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))'))) \
193-
.with_content(/^LDAPHomeDir homeDirectory/) \
194-
.with_content(/^LDAPVersion 3/) \
195-
.with_content(/^LDAPDefaultUID 100/) \
196-
.with_content(/^LDAPForceDefaultUID False/) \
197-
.with_content(/^LDAPDefaultGID 100/) \
198-
.with_content(/^LDAPDefaultGID 100/) \
199-
.with_content(/^LDAPForceDefaultGID False/) \
200-
.with_content(/^LDAPUseTLS False/) \
201-
.with_content(/^LDAPAuthMethod PASSWORD/) \
202-
end
203-
end
20469
end

spec/classes/config_mysql_spec.rb

+34-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
require 'spec_helper'
22

3-
test_options = [
4-
'MYSQLServer',
5-
'MYSQLPort',
6-
'MYSQLSocket',
7-
'MYSQLUser',
8-
'MYSQLPassword',
9-
'MYSQLDatabase',
10-
'MYSQLCrypt',
11-
'MYSQLTransactions',
12-
'MYSQLGetPW',
13-
'MYSQLGetUID',
14-
'MYSQLDefaultUID',
15-
'MYSQLGetGID',
16-
'MYSQLDefaultGID',
17-
'MYSQLGetDir',
18-
'MYSQLForceTildeExpansion',
19-
'MYSQLGetQTAFS',
20-
'MYSQLGetQTASZ',
21-
'MYSQLGetRatioUL',
22-
'MYSQLGetRatioDL',
23-
'MYSQLGetBandwidthUL',
24-
'MYSQLGetBandwidthDL',
25-
]
3+
conf_options = [
4+
'MYSQLServer',
5+
'MYSQLPort',
6+
'MYSQLSocket',
7+
'MYSQLUser',
8+
'MYSQLPassword',
9+
'MYSQLDatabase',
10+
'MYSQLCrypt',
11+
'MYSQLTransactions',
12+
'MYSQLGetPW',
13+
'MYSQLGetUID',
14+
'MYSQLDefaultUID',
15+
'MYSQLGetGID',
16+
'MYSQLDefaultGID',
17+
'MYSQLGetDir',
18+
'MYSQLForceTildeExpansion',
19+
'MYSQLGetQTAFS',
20+
'MYSQLGetQTASZ',
21+
'MYSQLGetRatioUL',
22+
'MYSQLGetRatioDL',
23+
'MYSQLGetBandwidthUL',
24+
'MYSQLGetBandwidthDL',
25+
]
2626

2727
describe 'pureftpd::config::mysql' do
2828

@@ -45,7 +45,7 @@
4545
# accumutate all of the params and content strings as we test each individual
4646
# option so we can use them for the next test
4747
context 'one option at a time' do
48-
test_options.each do |option|
48+
conf_options.each do |option|
4949
params = {}
5050
params[option.downcase.to_sym] = value
5151
content = sprintf("%-19s %s\n", option, value)
@@ -63,4 +63,14 @@
6363
it_behaves_like 'config', all_params, all_content
6464
end
6565

66+
context 'invalid param' do
67+
let(:facts) {{ :osfamily=> 'RedHat' }}
68+
let(:params) {{ :foo => 'bar' }}
69+
70+
it 'should fail' do
71+
expect { should include_class('pureftpd::config::mysql') }.
72+
to raise_error(Puppet::Error, /Invalid parameter foo/)
73+
end
74+
end
75+
6676
end

spec/classes/config_pgsql_spec.rb

+31-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
require 'spec_helper'
22

3-
test_options = [
4-
'PGSQLServer',
5-
'PGSQLPort',
6-
'PGSQLUser',
7-
'PGSQLPassword',
8-
'PGSQLDatabase',
9-
'PGSQLCrypt',
10-
'PGSQLGetPW',
11-
'PGSQLGetUID',
12-
'PGSQLDefaultUID',
13-
'PGSQLGetGID',
14-
'PGSQLDefaultGID',
15-
'PGSQLGetDir',
16-
'PGSQLGetQTAFS',
17-
'PGSQLGetQTASZ',
18-
'PGSQLGetRatioUL',
19-
'PGSQLGetRatioDL',
20-
'PGSQLGetBandwidthUL',
21-
'PGSQLGetBandwidthDL',
22-
]
3+
conf_options = [
4+
'PGSQLServer',
5+
'PGSQLPort',
6+
'PGSQLUser',
7+
'PGSQLPassword',
8+
'PGSQLDatabase',
9+
'PGSQLCrypt',
10+
'PGSQLGetPW',
11+
'PGSQLGetUID',
12+
'PGSQLDefaultUID',
13+
'PGSQLGetGID',
14+
'PGSQLDefaultGID',
15+
'PGSQLGetDir',
16+
'PGSQLGetQTAFS',
17+
'PGSQLGetQTASZ',
18+
'PGSQLGetRatioUL',
19+
'PGSQLGetRatioDL',
20+
'PGSQLGetBandwidthUL',
21+
'PGSQLGetBandwidthDL',
22+
]
2323

2424
describe 'pureftpd::config::pgsql' do
2525

@@ -42,7 +42,7 @@
4242
# accumutate all of the params and content strings as we test each individual
4343
# option so we can use them for the next test
4444
context 'one option at a time' do
45-
test_options.each do |option|
45+
conf_options.each do |option|
4646
params = {}
4747
params[option.downcase.to_sym] = value
4848
content = sprintf("%-19s %s\n", option, value)
@@ -60,4 +60,14 @@
6060
it_behaves_like 'config', all_params, all_content
6161
end
6262

63+
context 'invalid param' do
64+
let(:facts) {{ :osfamily=> 'RedHat' }}
65+
let(:params) {{ :foo => 'bar' }}
66+
67+
it 'should fail' do
68+
expect { should include_class('pureftpd::config::pgsql') }.
69+
to raise_error(Puppet::Error, /Invalid parameter foo/)
70+
end
71+
end
72+
6373
end

0 commit comments

Comments
 (0)