Merge "Replace mocha by rspec-mocks"
This commit is contained in:
commit
c8978dcba2
|
@ -13,6 +13,8 @@ RSpec.configure do |c|
|
||||||
|
|
||||||
c.module_path = File.join(fixture_path, 'modules')
|
c.module_path = File.join(fixture_path, 'modules')
|
||||||
c.manifest_dir = File.join(fixture_path, 'manifests')
|
c.manifest_dir = File.join(fixture_path, 'manifests')
|
||||||
|
|
||||||
|
c.mock_with :rspec
|
||||||
end
|
end
|
||||||
|
|
||||||
at_exit { RSpec::Puppet::Coverage.report! }
|
at_exit { RSpec::Puppet::Coverage.report! }
|
||||||
|
|
|
@ -32,7 +32,7 @@ describe Puppet::Provider::Ironic do
|
||||||
|
|
||||||
it 'should fail if config is empty' do
|
it 'should fail if config is empty' do
|
||||||
conf = {}
|
conf = {}
|
||||||
klass.expects(:ironic_conf).returns(conf)
|
expect(klass).to receive(:ironic_conf).and_return(conf)
|
||||||
expect do
|
expect do
|
||||||
klass.ironic_credentials
|
klass.ironic_credentials
|
||||||
end.to raise_error(Puppet::Error, credential_error)
|
end.to raise_error(Puppet::Error, credential_error)
|
||||||
|
@ -40,7 +40,7 @@ describe Puppet::Provider::Ironic do
|
||||||
|
|
||||||
it 'should fail if config does not have keystone_authtoken section.' do
|
it 'should fail if config does not have keystone_authtoken section.' do
|
||||||
conf = {'foo' => 'bar'}
|
conf = {'foo' => 'bar'}
|
||||||
klass.expects(:ironic_conf).returns(conf)
|
expect(klass).to receive(:ironic_conf).and_return(conf)
|
||||||
expect do
|
expect do
|
||||||
klass.ironic_credentials
|
klass.ironic_credentials
|
||||||
end.to raise_error(Puppet::Error, credential_error)
|
end.to raise_error(Puppet::Error, credential_error)
|
||||||
|
@ -48,7 +48,7 @@ describe Puppet::Provider::Ironic do
|
||||||
|
|
||||||
it 'should fail if config does not contain all auth params' do
|
it 'should fail if config does not contain all auth params' do
|
||||||
conf = {'keystone_authtoken' => {'invalid_value' => 'foo'}}
|
conf = {'keystone_authtoken' => {'invalid_value' => 'foo'}}
|
||||||
klass.expects(:ironic_conf).returns(conf)
|
expect(klass).to receive(:ironic_conf).and_return(conf)
|
||||||
expect do
|
expect do
|
||||||
klass.ironic_credentials
|
klass.ironic_credentials
|
||||||
end.to raise_error(Puppet::Error, credential_error)
|
end.to raise_error(Puppet::Error, credential_error)
|
||||||
|
@ -67,18 +67,20 @@ describe Puppet::Provider::Ironic do
|
||||||
:OS_PROJECT_DOMAIN_NAME => credential_hash['project_domain_name'],
|
:OS_PROJECT_DOMAIN_NAME => credential_hash['project_domain_name'],
|
||||||
:OS_USER_DOMAIN_NAME => credential_hash['user_domain_name'],
|
:OS_USER_DOMAIN_NAME => credential_hash['user_domain_name'],
|
||||||
}
|
}
|
||||||
klass.expects(:get_ironic_credentials).with().returns(credential_hash)
|
expect(klass).to receive(:get_ironic_credentials).with(no_args).and_return(credential_hash)
|
||||||
klass.expects(:withenv).with(authenv)
|
expect(klass).to receive(:withenv).with(authenv)
|
||||||
klass.auth_ironic('test_retries')
|
klass.auth_ironic('test_retries')
|
||||||
end
|
end
|
||||||
|
|
||||||
['[Errno 111] Connection refused',
|
['[Errno 111] Connection refused',
|
||||||
'(HTTP 400)'].reverse.each do |valid_message|
|
'(HTTP 400)'].reverse.each do |valid_message|
|
||||||
it "should retry when ironic cli returns with error #{valid_message}" do
|
it "should retry when ironic cli returns with error #{valid_message}" do
|
||||||
klass.expects(:get_ironic_credentials).with().returns({})
|
expect(klass).to receive(:get_ironic_credentials).with(no_args).and_return({})
|
||||||
klass.expects(:sleep).with(10).returns(nil)
|
expect(klass).to receive(:sleep).with(10).and_return(nil)
|
||||||
klass.expects(:ironic).twice.with(['test_retries']).raises(
|
expect(klass).to receive(:ironic).with(['test_retries']).and_invoke(
|
||||||
Exception, valid_message).then.returns('')
|
lambda { |x| raise valid_message },
|
||||||
|
lambda { |x| return '' }
|
||||||
|
)
|
||||||
klass.auth_ironic('test_retries')
|
klass.auth_ironic('test_retries')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -93,7 +95,7 @@ describe Puppet::Provider::Ironic do
|
||||||
net1
|
net1
|
||||||
net2
|
net2
|
||||||
EOT
|
EOT
|
||||||
klass.expects(:auth_ironic).returns(output)
|
expect(klass).to receive(:auth_ironic).and_return(output)
|
||||||
result = klass.list_ironic_resources('foo')
|
result = klass.list_ironic_resources('foo')
|
||||||
expect(result).to eql(['net1', 'net2'])
|
expect(result).to eql(['net1', 'net2'])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue