Skip to content

Commit

Permalink
improve consistency of class pureftpd::config* tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Sep 9, 2013
1 parent b3191a3 commit 888dd0c
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 288 deletions.
227 changes: 46 additions & 181 deletions spec/classes/config_ldap_spec.rb
Original file line number Diff line number Diff line change
@@ -1,204 +1,69 @@
require 'spec_helper'

conf_options = [
'LDAPServer',
'LDAPPort',
'LDAPBindDN',
'LDAPBindPW',
'LDAPBaseDN',
'LDAPFilter',
'LDAPHomeDir',
'LDAPVersion',
'LDAPDefaultUID',
'LDAPForceDefaultUID',
'LDAPDefaultGID',
'LDAPForceDefaultGID',
'LDAPUseTLS',
'LDAPAuthMethod',
]

describe 'pureftpd::config::ldap' do
let(:facts) {{ :osfamily=> 'RedHat' }}

describe 'with no params' do
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file').with_content('')
end
end
shared_examples 'config' do |params, content|
let(:facts) {{ :osfamily=> 'RedHat' }}
let(:params) { params }

describe 'with ldapserver' do
let(:params) {{ :ldapserver => 'ldap.example.com' }}
it do
should contain_class('pureftpd::config::ldap')
should include_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPServer ldap.example.com/)
.with_content(content)
end
end

describe 'with ldapport' do
let(:params) {{ :ldapport => '389' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPPort 389/)
end
end
all_params = {}
all_content = ''
value = 'xxx'

describe 'with ldapbinddn' do
let(:params) {{ :ldapbinddn => 'cn=Manager,dc=c9x,dc=org' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/)
end
end

describe 'with ldapbindpw' do
let(:params) {{ :ldapbindpw => 'r00tPaSsw0rD' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPBindPW r00tPaSsw0rD/)
end
end
# accumutate all of the params and content strings as we test each individual
# option so we can use them for the next test
context 'one option at a time' do
conf_options.each do |option|
params = {}
params[option.downcase.to_sym] = value
content = sprintf("%-19s %s\n", option, value)

describe 'with ldapbasedn' do
let(:params) {{ :ldapbasedn => 'cn=Users,dc=c9x,dc=org' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/)
end
end
all_params.merge!(params)
all_content += content

describe 'with ldapfilter' do
let(:params) {{ :ldapfilter => '(&(objectClass=posixAccount)(uid=\L))' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))')))
it_behaves_like 'config', params, content
end
end

describe 'with ldaphomedir' do
let(:params) {{ :ldaphomedir => 'homeDirectory' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPHomeDir homeDirectory/)
end

# test all of the known options at once this works because the ordering of
# options values in the output file is fixed
context 'all options' do
it_behaves_like 'config', all_params, all_content
end

describe 'with ldapversion' do
let(:params) {{ :ldapversion => '3' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPVersion 3/)
end
end
context 'invalid param' do
let(:facts) {{ :osfamily=> 'RedHat' }}
let(:params) {{ :foo => 'bar' }}

describe 'with ldapdefaultuid' do
let(:params) {{ :ldapdefaultuid => '100' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPDefaultUID 100/)
it 'should fail' do
expect { should include_class('pureftpd::config::ldap') }.
to raise_error(Puppet::Error, /Invalid parameter foo/)
end
end

describe 'with ldapforcedefaultuid' do
let(:params) {{ :ldapforcedefaultuid => 'False' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPForceDefaultUID False/)
end
end

describe 'with ldapdefaultgid' do
let(:params) {{ :ldapdefaultgid => '100' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPDefaultGID 100/)
end
end

describe 'with ldapdefaultgid' do
let(:params) {{ :ldapdefaultgid => '100' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPDefaultGID 100/)
end
end

describe 'with ldapforcedefaultgid' do
let(:params) {{ :ldapforcedefaultgid => 'False' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPForceDefaultGID False/)
end
end

describe 'with ldapusetls' do
let(:params) {{ :ldapusetls => 'False' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPUseTLS False/)
end
end

describe 'with ldapauthmethod' do
let(:params) {{ :ldapauthmethod => 'PASSWORD' }}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPAuthMethod PASSWORD/)
end
end

describe 'with everything' do
let(:params) {{
:ldapserver => 'ldap.example.com',
:ldapauthmethod => 'PASSWORD',
:ldapport => '389',
:ldapbinddn => 'cn=Manager,dc=c9x,dc=org',
:ldapbindpw => 'r00tPaSsw0rD',
:ldapbasedn => 'cn=Users,dc=c9x,dc=org',
:ldapfilter => '(&(objectClass=posixAccount)(uid=\L))',
:ldaphomedir => 'homeDirectory',
:ldapversion => '3',
:ldapdefaultuid => '100',
:ldapforcedefaultuid => 'False',
:ldapdefaultgid => '100',
:ldapdefaultgid => '100',
:ldapforcedefaultgid => 'False',
:ldapusetls => 'False',
:ldapauthmethod => 'PASSWORD',
}}
it do
should contain_class('pureftpd::config::ldap')
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
.with_ensure('file') \
.with_content(/^LDAPServer ldap.example.com/) \
.with_content(/^LDAPPort 389/) \
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/) \
.with_content(/^LDAPBindPW r00tPaSsw0rD/) \
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/) \
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))'))) \
.with_content(/^LDAPHomeDir homeDirectory/) \
.with_content(/^LDAPVersion 3/) \
.with_content(/^LDAPDefaultUID 100/) \
.with_content(/^LDAPForceDefaultUID False/) \
.with_content(/^LDAPDefaultGID 100/) \
.with_content(/^LDAPDefaultGID 100/) \
.with_content(/^LDAPForceDefaultGID False/) \
.with_content(/^LDAPUseTLS False/) \
.with_content(/^LDAPAuthMethod PASSWORD/) \
end
end
end
58 changes: 34 additions & 24 deletions spec/classes/config_mysql_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
require 'spec_helper'

test_options = [
'MYSQLServer',
'MYSQLPort',
'MYSQLSocket',
'MYSQLUser',
'MYSQLPassword',
'MYSQLDatabase',
'MYSQLCrypt',
'MYSQLTransactions',
'MYSQLGetPW',
'MYSQLGetUID',
'MYSQLDefaultUID',
'MYSQLGetGID',
'MYSQLDefaultGID',
'MYSQLGetDir',
'MYSQLForceTildeExpansion',
'MYSQLGetQTAFS',
'MYSQLGetQTASZ',
'MYSQLGetRatioUL',
'MYSQLGetRatioDL',
'MYSQLGetBandwidthUL',
'MYSQLGetBandwidthDL',
]
conf_options = [
'MYSQLServer',
'MYSQLPort',
'MYSQLSocket',
'MYSQLUser',
'MYSQLPassword',
'MYSQLDatabase',
'MYSQLCrypt',
'MYSQLTransactions',
'MYSQLGetPW',
'MYSQLGetUID',
'MYSQLDefaultUID',
'MYSQLGetGID',
'MYSQLDefaultGID',
'MYSQLGetDir',
'MYSQLForceTildeExpansion',
'MYSQLGetQTAFS',
'MYSQLGetQTASZ',
'MYSQLGetRatioUL',
'MYSQLGetRatioDL',
'MYSQLGetBandwidthUL',
'MYSQLGetBandwidthDL',
]

describe 'pureftpd::config::mysql' do

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

context 'invalid param' do
let(:facts) {{ :osfamily=> 'RedHat' }}
let(:params) {{ :foo => 'bar' }}

it 'should fail' do
expect { should include_class('pureftpd::config::mysql') }.
to raise_error(Puppet::Error, /Invalid parameter foo/)
end
end

end
52 changes: 31 additions & 21 deletions spec/classes/config_pgsql_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
require 'spec_helper'

test_options = [
'PGSQLServer',
'PGSQLPort',
'PGSQLUser',
'PGSQLPassword',
'PGSQLDatabase',
'PGSQLCrypt',
'PGSQLGetPW',
'PGSQLGetUID',
'PGSQLDefaultUID',
'PGSQLGetGID',
'PGSQLDefaultGID',
'PGSQLGetDir',
'PGSQLGetQTAFS',
'PGSQLGetQTASZ',
'PGSQLGetRatioUL',
'PGSQLGetRatioDL',
'PGSQLGetBandwidthUL',
'PGSQLGetBandwidthDL',
]
conf_options = [
'PGSQLServer',
'PGSQLPort',
'PGSQLUser',
'PGSQLPassword',
'PGSQLDatabase',
'PGSQLCrypt',
'PGSQLGetPW',
'PGSQLGetUID',
'PGSQLDefaultUID',
'PGSQLGetGID',
'PGSQLDefaultGID',
'PGSQLGetDir',
'PGSQLGetQTAFS',
'PGSQLGetQTASZ',
'PGSQLGetRatioUL',
'PGSQLGetRatioDL',
'PGSQLGetBandwidthUL',
'PGSQLGetBandwidthDL',
]

describe 'pureftpd::config::pgsql' do

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

context 'invalid param' do
let(:facts) {{ :osfamily=> 'RedHat' }}
let(:params) {{ :foo => 'bar' }}

it 'should fail' do
expect { should include_class('pureftpd::config::pgsql') }.
to raise_error(Puppet::Error, /Invalid parameter foo/)
end
end

end
Loading

0 comments on commit 888dd0c

Please sign in to comment.