
puppetlabs_spec_helper recommends rspec-mocks instead of mocha[1] and
it uses rspec-mocks by default instead of mocha since v 5.0.0[2]
This is the prep work to adapt to that migration.
[1] https://github.com/puppetlabs/puppetlabs_spec_helper/#mock_with
[2] 493f0cbc1c
Closes-Bug: #2004135
Change-Id: If8bd21cfe760f7ba92af017981a39c80bdc2b676
40 lines
1.6 KiB
Ruby
40 lines
1.6 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
|
|
allow(File).to receive(:file?).with('/etc/ssl/certs/test.pem').and_return(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
|
|
allow(File).to receive(:file?).with('/etc/ssl/certs/test.pem').and_return(true)
|
|
allow(File).to receive(:readlines).with('/etc/ssl/certs/test.pem').and_return(['----- 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
|
|
allow(File).to receive(:file?).with('/etc/ssl/certs/test.pem').and_return(true)
|
|
# NOTE(tobias-urdin): There is spacing in the return data here on purpose to test the ruby string strip.
|
|
allow(File).to receive(:readlines).with('/etc/ssl/certs/test.pem').and_return(['----- BEGIN CERTIFICATE -----', ' abc321 ', '----- END CERTIFICATE -----'])
|
|
is_expected.to run.with_params('/etc/ssl/certs/test.pem').and_return('abc321')
|
|
end
|
|
end
|
|
end
|