puppet-neutron/spec/functions/convert_cert_to_string_spec.rb
Tobias Urdin 37bb654424 Use puppet4 functions-api
Change-Id: Id124ec4c598c7b6bcb7c8134d75825fd01d938d2
2018-12-18 10:32:11 +00:00

40 lines
1.5 KiB
Ruby

require 'spec_helper'
describe 'convert_cert_to_string' do
it 'exists' do
is_expected.not_to eq(nil)
end
it 'fails with no arguments' do
is_expected.to run.with_params.and_raise_error(ArgumentError)
end
it 'fails when arg is not a string' do
is_expected.to run.with_params(123).and_raise_error(ArgumentError)
end
context 'when file does not exist' do
it 'fails when cert file doesnt exist' do
File.stubs(:file?).with('/etc/ssl/certs/test.pem').returns(false)
is_expected.to run.with_params('/etc/ssl/certs/test.pem').and_raise_error(Puppet::ParseError)
end
end
context 'with certificate that doesnt need strip' do
it 'should return proper value' do
File.stubs(:file?).with('/etc/ssl/certs/test.pem').returns(true)
File.stubs(:readlines).with('/etc/ssl/certs/test.pem').returns(['----- BEGIN CERTIFICATE -----', 'abc123data', '----- END CERTIFICATE -----'])
is_expected.to run.with_params('/etc/ssl/certs/test.pem').and_return('abc123data')
end
end
context 'with certificate that requires strip' do
it 'should return proper value' do
File.stubs(:file?).with('/etc/ssl/certs/test.pem').returns(true)
# NOTE(tobias-urdin): There is spacing in the return data here on purpose to test the ruby string strip.
File.stubs(:readlines).with('/etc/ssl/certs/test.pem').returns(['----- BEGIN CERTIFICATE -----', ' abc321 ', '----- END CERTIFICATE -----'])
is_expected.to run.with_params('/etc/ssl/certs/test.pem').and_return('abc321')
end
end
end