Skip to content

Commit

Permalink
Merge branch 'Phil-Friderici-custom_sshd_config_rebase' into custom_s…
Browse files Browse the repository at this point in the history
…shd_config_rebase
  • Loading branch information
boandersson committed Aug 23, 2016
2 parents 16952c2 + 4ca38f5 commit 42f9b24
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -883,4 +883,46 @@
end
end
end

describe 'variable type and content validations' do
# set needed custom facts and variables
let(:facts) do
{
:operatingsystemmajrelease => '7',
:osfamily => 'RedHat',
}
end
let(:mandatory_params) { {} }

validations = {
'array for pam_sshd_(auth|account|password|session)_lines' => {
:name => %w(pam_sshd_auth_lines pam_sshd_account_lines pam_sshd_password_lines pam_sshd_session_lines),
:params => { :pam_d_sshd_template => 'pam/sshd.custom.erb', :pam_sshd_auth_lines => ['#'], :pam_sshd_account_lines => ['#'], :pam_sshd_password_lines => ['#'], :pam_sshd_session_lines => ['#']},
:valid => [%w(array)],
:invalid => ['string', { 'ha' => 'sh' }, 3, 2.42, true, false],
:message => 'is not an Array',
},
}

validations.sort.each do |type, var|
var[:name].each do |var_name|
var[:params] = {} if var[:params].nil?
var[:valid].each do |valid|
context "when #{var_name} (#{type}) is set to valid #{valid} (as #{valid.class})" do
let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => valid, }].reduce(:merge) }
it { should compile }
end
end

var[:invalid].each do |invalid|
context "when #{var_name} (#{type}) is set to invalid #{invalid} (as #{invalid.class})" do
let(:params) { [mandatory_params, var[:params], { :"#{var_name}" => invalid, }].reduce(:merge) }
it 'should fail' do
expect { should contain_class(subject) }.to raise_error(Puppet::Error, /#{var[:message]}/)
end
end
end
end # var[:name].each
end # validations.sort.each
end # describe 'variable type and content validations'
end

0 comments on commit 42f9b24

Please sign in to comment.