Skip to content

Commit

Permalink
remove type tests, we have typing in puppet now
Browse files Browse the repository at this point in the history
  • Loading branch information
zilchms committed Feb 14, 2024
1 parent ab162f4 commit 234f496
Showing 1 changed file with 0 additions and 149 deletions.
149 changes: 0 additions & 149 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,153 +316,4 @@
end
end
end

describe 'failures' do
let(:facts) do
{
osfamily: 'Debian',
lsbdistcodename: 'squeeze',
monit_version: '5',
}
end

[-1, 65_536].each do |value|
context "when httpd_port is set to invalid value <#{value}>" do
let(:params) do
{
httpd: true,
httpd_port: value,
httpd_address: 'otherhost',
httpd_user: 'tester',
httpd_password: 'Passw0rd',
}
end

it 'fails' do
is_expected.to compile.and_raise_error(%r{expects an Integer\[1, 65535\] value})
end
end
end

context 'when check_interval is set to invalid value <0>' do
let(:params) { { check_interval: 0 } }

it 'fails' do
is_expected.to compile.and_raise_error(%r{expects an Integer\[1})
end
end

context 'when start_delay is set to invalid value <0>' do
let(:params) { { start_delay: 0 } }

it 'fails' do
is_expected.to compile.and_raise_error(%r{expects a value of type Undef or Integer\[1})
end
end
end

describe 'variable type and content validations' do
# set needed custom facts and variables
let(:facts) do
{
osfamily: 'Debian',
operatingsystemrelease: '6.0',
operatingsystemmajrelease: '6',
lsbdistcodename: 'squeeze',
monit_version: '5',
}
end
let(:validation_params) do
{
# :param => 'value',
}
end

validations = {
'absolute_path' => {
name: %w[config_file config_dir],
valid: ['/absolute/filepath', '/absolute/directory/'],
invalid: ['invalid', 3, 2.42, ['array'], { 'ha' => 'sh' }],
message: '(expects a String value|is not an absolute path)',
},
'array' => {
name: ['alert_emails'],
valid: [%w[valid array]],
invalid: ['string', { 'ha' => 'sh' }, 3, 2.42, true],
message: 'expects an Array value',
},
'bool_stringified' => {
name: %w[httpd manage_firewall service_enable service_manage mmonit_https mmonit_without_credential config_dir_purge],
valid: [true, 'true', false, 'false'],
invalid: ['invalid', 3, 2.42, ['array'], { 'ha' => 'sh' }, nil],
message: 'expects a value of type Boolean or Enum',
},
'integer' => {
name: %w[check_interval httpd_port mmonit_port],
valid: [242],
invalid: [2.42, 'invalid', ['array'], { 'ha' => 'sh ' }, true, false, nil],
message: 'expects an Integer',
},
'optional_integer' => {
name: ['start_delay'],
valid: [242],
invalid: [2.42, 'invalid', ['array'], { 'ha' => 'sh ' }, true, false, nil],
message: 'expects a value of type Undef or Integer',
},
'optional_logfile' => {
name: ['logfile'],
valid: ['/absolute/filepath', '/absolute/directory/', 'syslog', 'syslog facility log_local0'],
invalid: ['invalid', 3, 2.42, ['array'], { 'ha' => 'sh' }],
message: '(expects a value of type Undef or String|is not an absolute path)',
},
'optional_hash' => {
name: ['mailformat'],
valid: [{ 'ha' => 'sh' }],
invalid: ['string', 3, 2.42, ['array'], true, false, nil],
message: 'expects a value of type Undef or Hash',
},
'optional_string' => {
name: %w[mailserver mmonit_address],
valid: ['present'],
invalid: [['array'], { 'ha' => 'sh' }],
message: 'expects a value of type Undef or String',
},
'string' => {
name: %w[httpd_address httpd_allow httpd_user httpd_password
package_ensure package_name service_name mmonit_user
mmonit_password],
valid: ['present'],
invalid: [['array'], { 'ha' => 'sh' }],
message: 'expects a String value',
},
'service_ensure_string' => {
name: ['service_ensure'],
valid: ['running'],
invalid: [['array'], { 'ha' => 'sh' }],
message: 'expects a match for Enum\[\'running\', \'stopped\'\]',
},
}

validations.sort.each do |type, var|
var[:name].each do |var_name|
var[:valid].each do |valid|
context "with #{var_name} (#{type}) set to valid #{valid} (as #{valid.class})" do
let(:params) { validation_params.merge("#{var_name}": valid) }

it { is_expected.to compile }
end
end

var[:invalid].each do |invalid|
context "with #{var_name} (#{type}) set to invalid #{invalid} (as #{invalid.class})" do
let(:params) { validation_params.merge("#{var_name}": invalid) }

it 'fails' do
is_expected.to compile.and_raise_error(%r{#{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 234f496

Please sign in to comment.