Skip to content

Commit

Permalink
Change allow() to expect() in openssl_spec
Browse files Browse the repository at this point in the history
This makes the mocking stronger because tests will fail if they aren't
called in a certain way.
  • Loading branch information
ekohl committed May 22, 2024
1 parent aeb88ae commit 5198eb5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions spec/unit/puppet/provider/x509_cert/openssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,24 @@
context 'when forcing key' do
it 'exists? should return true if certificate exists and is synced' do
resource[:force] = true
allow(File).to receive(:read)
expect(File).to receive(:read).with('/tmp/foo.crt').twice.and_return('cert')
expect(File).to receive(:read).with('/tmp/foo.key').and_return('pkey')
expect(Pathname).to receive(:new).with(path).and_return(pathname)
expect(pathname).to receive(:exist?).and_return(true)
allow(OpenSSL::X509::Certificate).to receive(:new).and_return(cert)
allow(OpenSSL::PKey::RSA).to receive(:new)
expect(OpenSSL::X509::Certificate).to receive(:new).with('cert').twice.and_return(cert)
expect(OpenSSL::PKey::RSA).to receive(:new)
expect(cert).to receive(:check_private_key).and_return(true)
expect(resource.provider.exists?).to be(true)
end

it 'exists? should return false if certificate exists and is not synced' do
resource[:force] = true
allow(File).to receive(:read)
expect(File).to receive(:read).with('/tmp/foo.crt').and_return('cert')
expect(File).to receive(:read).with('/tmp/foo.key').and_return('pkey')
expect(Pathname).to receive(:new).with(path).and_return(pathname)
expect(pathname).to receive(:exist?).and_return(true)
allow(OpenSSL::X509::Certificate).to receive(:new).and_return(cert)
allow(OpenSSL::PKey::RSA).to receive(:new)
expect(OpenSSL::X509::Certificate).to receive(:new).with('cert').and_return(cert)
expect(OpenSSL::PKey::RSA).to receive(:new)
expect(cert).to receive(:check_private_key).and_return(false)
expect(resource.provider.exists?).to be(false)
end
Expand Down

0 comments on commit 5198eb5

Please sign in to comment.