Replace mocha by rspec-mocks
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: I48ce7e9537589cf15e600faa119160d003f23964
This commit is contained in:
parent
e4890cfc26
commit
9566c770c0
|
@ -13,6 +13,8 @@ RSpec.configure do |c|
|
|||
|
||||
c.module_path = File.join(fixture_path, 'modules')
|
||||
c.manifest_dir = File.join(fixture_path, 'manifests')
|
||||
|
||||
c.mock_with :rspec
|
||||
end
|
||||
|
||||
at_exit { RSpec::Puppet::Coverage.report! }
|
||||
|
|
|
@ -27,16 +27,16 @@ describe provider_class do
|
|||
shared_examples 'murano_application' do
|
||||
describe '#create' do
|
||||
it 'should create application' do
|
||||
provider.expects(:auth_murano).with("package-import", ['/tmp/io.murano.zip', '--is-public'] )
|
||||
.returns('')
|
||||
expect(provider).to receive(:auth_murano).with("package-import", ['/tmp/io.murano.zip', '--is-public'] )
|
||||
.and_return('')
|
||||
provider.create
|
||||
end
|
||||
end
|
||||
|
||||
describe '#flush' do
|
||||
it 'should flush application' do
|
||||
provider.expects(:auth_murano).with("package-import", ['/tmp/io.murano.zip', '--is-public', '--exists-action', 'u'] )
|
||||
.returns('')
|
||||
expect(provider).to receive(:auth_murano).with("package-import", ['/tmp/io.murano.zip', '--is-public', '--exists-action', 'u'] )
|
||||
.and_return('')
|
||||
provider.flush
|
||||
end
|
||||
end
|
||||
|
@ -44,16 +44,16 @@ describe provider_class do
|
|||
describe '#destroy' do
|
||||
it 'should destroy application' do
|
||||
resource[:ensure] = :absent
|
||||
provider.expects(:auth_murano).with("package-delete", 'io.murano')
|
||||
.returns('')
|
||||
expect(provider).to receive(:auth_murano).with("package-delete", 'io.murano')
|
||||
.and_return('')
|
||||
provider.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe '#instances' do
|
||||
it 'finds packages' do
|
||||
provider.class.expects(:auth_murano).with("package-list")
|
||||
.returns("+----------------------------------+--------------------+----------------------------------------+---------------+-----------+\n| ID | Name | FQN | Author | Is Public |\n+----------------------------------+--------------------+----------------------------------------+---------------+-----------+\n| 9a23e4aea548462d82b66f2aee0f196e | Core library | io.murano | murano.io | True |\n+----------------------------------+--------------------+----------------------------------------+---------------+-----------+\n")
|
||||
expect(provider.class).to receive(:auth_murano).with("package-list")
|
||||
.and_return("+----------------------------------+--------------------+----------------------------------------+---------------+-----------+\n| ID | Name | FQN | Author | Is Public |\n+----------------------------------+--------------------+----------------------------------------+---------------+-----------+\n| 9a23e4aea548462d82b66f2aee0f196e | Core library | io.murano | murano.io | True |\n+----------------------------------+--------------------+----------------------------------------+---------------+-----------+\n")
|
||||
instances = provider_class.instances
|
||||
expect(instances.count).to eq(1)
|
||||
expect(instances[0].name).to eq('io.murano')
|
||||
|
|
|
@ -33,7 +33,7 @@ describe Puppet::Provider::Murano do
|
|||
|
||||
it 'should fail if config is empty' do
|
||||
conf = {}
|
||||
klass.expects(:murano_conf).returns(conf)
|
||||
expect(klass).to receive(:murano_conf).and_return(conf)
|
||||
expect do
|
||||
klass.murano_credentials
|
||||
end.to raise_error(Puppet::Error, credential_error)
|
||||
|
@ -41,7 +41,7 @@ describe Puppet::Provider::Murano do
|
|||
|
||||
it 'should fail if config does not have keystone_authtoken section.' do
|
||||
conf = {'foo' => 'bar'}
|
||||
klass.expects(:murano_conf).returns(conf)
|
||||
expect(klass).to receive(:murano_conf).and_return(conf)
|
||||
expect do
|
||||
klass.murano_credentials
|
||||
end.to raise_error(Puppet::Error, credential_error)
|
||||
|
@ -49,7 +49,7 @@ describe Puppet::Provider::Murano do
|
|||
|
||||
it 'should fail if config does not contain all auth params' do
|
||||
conf = {'keystone_authtoken' => {'invalid_value' => 'foo'}}
|
||||
klass.expects(:murano_conf).returns(conf)
|
||||
expect(klass).to receive(:murano_conf).and_return(conf)
|
||||
expect do
|
||||
klass.murano_credentials
|
||||
end.to raise_error(Puppet::Error, credential_error)
|
||||
|
@ -70,8 +70,8 @@ describe Puppet::Provider::Murano do
|
|||
:OS_USER_DOMAIN_NAME => credential_hash['user_domain_name'],
|
||||
|
||||
}
|
||||
klass.expects(:get_murano_credentials).with().returns(credential_hash)
|
||||
klass.expects(:withenv).with(authenv)
|
||||
expect(klass).to receive(:get_murano_credentials).with(no_args).and_return(credential_hash)
|
||||
expect(klass).to receive(:withenv).with(authenv)
|
||||
klass.auth_murano('test_retries')
|
||||
end
|
||||
|
||||
|
@ -96,8 +96,8 @@ describe Puppet::Provider::Murano do
|
|||
'project_domain_name' => 'Default',
|
||||
'user_domain_name' => 'Default',
|
||||
}
|
||||
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
|
||||
mock.expects(:read).with('/etc/murano/murano.conf')
|
||||
expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock)
|
||||
expect(mock).to receive(:read).with('/etc/murano/murano.conf')
|
||||
expect(klass.murano_credentials).to eq(creds)
|
||||
end
|
||||
|
||||
|
@ -121,18 +121,20 @@ describe Puppet::Provider::Murano do
|
|||
:OS_PROJECT_DOMAIN_NAME => creds['project_domain_name'],
|
||||
:OS_USER_DOMAIN_NAME => creds['user_domain_name'],
|
||||
}
|
||||
klass.expects(:get_murano_credentials).with().returns(creds)
|
||||
klass.expects(:withenv).with(authenv)
|
||||
expect(klass).to receive(:get_murano_credentials).with(no_args).and_return(creds)
|
||||
expect(klass).to receive(:withenv).with(authenv)
|
||||
klass.auth_murano('test_retries')
|
||||
end
|
||||
|
||||
['[Errno 111] Connection refused',
|
||||
'(HTTP 400)'].reverse.each do |valid_message|
|
||||
it "should retry when murano cli returns with error #{valid_message}" do
|
||||
klass.expects(:get_murano_credentials).with().returns({})
|
||||
klass.expects(:sleep).with(10).returns(nil)
|
||||
klass.expects(:murano).twice.with(['test_retries']).raises(
|
||||
Exception, valid_message).then.returns('')
|
||||
expect(klass).to receive(:get_murano_credentials).with(no_args).and_return({})
|
||||
expect(klass).to receive(:sleep).with(10).and_return(nil)
|
||||
expect(klass).to receive(:murano).with(['test_retries']).and_invoke(
|
||||
lambda { |*args| raise Exception, valid_message},
|
||||
lambda { |*args| return '' }
|
||||
)
|
||||
klass.auth_murano('test_retries')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue