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: I5e822f07c79fe16baee90eebd557ee8d7ed1237d
68 lines
1.7 KiB
Ruby
68 lines
1.7 KiB
Ruby
require 'puppet'
|
|
require 'spec_helper'
|
|
require 'puppet/provider/nova'
|
|
require 'rspec/mocks'
|
|
|
|
describe Puppet::Provider::Nova do
|
|
|
|
def klass
|
|
described_class
|
|
end
|
|
|
|
let :credential_hash do
|
|
{
|
|
'auth_url' => 'https://192.168.56.210:5000/v3/',
|
|
'project_name' => 'admin_tenant',
|
|
'username' => 'admin',
|
|
'password' => 'password',
|
|
'region_name' => 'Region1',
|
|
}
|
|
end
|
|
|
|
let :auth_endpoint do
|
|
'https://192.168.56.210:5000/v3/'
|
|
end
|
|
|
|
let :credential_error do
|
|
/Nova types will not work/
|
|
end
|
|
|
|
after :each do
|
|
klass.reset
|
|
end
|
|
|
|
describe 'when determining credentials' do
|
|
|
|
it 'should fail if config is empty' do
|
|
conf = {}
|
|
expect(klass).to receive(:nova_conf).and_return(conf)
|
|
expect do
|
|
klass.nova_credentials
|
|
end.to raise_error(Puppet::Error, credential_error)
|
|
end
|
|
|
|
it 'should fail if config does not have keystone_authtoken section.' do
|
|
conf = {'foo' => 'bar'}
|
|
expect(klass).to receive(:nova_conf).and_return(conf)
|
|
expect do
|
|
klass.nova_credentials
|
|
end.to raise_error(Puppet::Error, credential_error)
|
|
end
|
|
|
|
it 'should fail if config does not contain all auth params' do
|
|
conf = {'keystone_authtoken' => {'invalid_value' => 'foo'}}
|
|
expect(klass).to receive(:nova_conf).and_return(conf)
|
|
expect do
|
|
klass.nova_credentials
|
|
end.to raise_error(Puppet::Error, credential_error)
|
|
end
|
|
|
|
it 'should use specified uri in the auth endpoint' do
|
|
conf = {'keystone_authtoken' => credential_hash}
|
|
expect(klass).to receive(:nova_conf).and_return(conf)
|
|
expect(klass.get_auth_endpoint).to eq(auth_endpoint)
|
|
end
|
|
|
|
end
|
|
end
|