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: I5baa93e0a994da7f3fafe79ce2a3e1d9232ce56e
This commit is contained in:
Takashi Kajinami 2023-01-30 13:19:48 +09:00
parent 9da8335992
commit 710b668f91
4 changed files with 24 additions and 22 deletions

View File

@ -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! }

View File

@ -38,9 +38,9 @@ describe provider_class do
describe 'managing qos' do describe 'managing qos' do
describe '#create' do describe '#create' do
it 'creates a qos' do it 'creates a qos' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume qos', 'create', '--format', 'shell', ['--property', 'key1=value1', '--property', 'key2=value2', 'QoS_1']) .with('volume qos', 'create', '--format', 'shell', ['--property', 'key1=value1', '--property', 'key2=value2', 'QoS_1'])
.returns('id="e0df397a-72d5-4494-9e26-4ac37632ff04" .and_return('id="e0df397a-72d5-4494-9e26-4ac37632ff04"
name="QoS_1" name="QoS_1"
properties="key1=\'value1\', key2=\'value2\'" properties="key1=\'value1\', key2=\'value2\'"
') ')
@ -51,7 +51,7 @@ properties="key1=\'value1\', key2=\'value2\'"
describe '#destroy' do describe '#destroy' do
it 'destroys a qos' do it 'destroys a qos' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume qos', 'delete', 'QoS_1') .with('volume qos', 'delete', 'QoS_1')
provider.destroy provider.destroy
expect(provider.exists?).to be_falsey expect(provider.exists?).to be_falsey
@ -60,9 +60,9 @@ properties="key1=\'value1\', key2=\'value2\'"
describe '#instances' do describe '#instances' do
it 'finds qos' do it 'finds qos' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume qos', 'list', '--quiet', '--format', 'csv', []) .with('volume qos', 'list', '--quiet', '--format', 'csv', [])
.returns('"ID","Name","Consumer","Associations","Specs" .and_return('"ID","Name","Consumer","Associations","Specs"
"28b632e8-6694-4bba-bf68-67b19f619019","qos-1","front-end","my_type1, my_type2","read_iops=\'value1\', write_iops=\'value2\'" "28b632e8-6694-4bba-bf68-67b19f619019","qos-1","front-end","my_type1, my_type2","read_iops=\'value1\', write_iops=\'value2\'"
"4f992f69-14ec-4132-9313-55cc06a6f1f6","qos-2","both","","" "4f992f69-14ec-4132-9313-55cc06a6f1f6","qos-2","both","",""
') ')
@ -82,9 +82,9 @@ properties="key1=\'value1\', key2=\'value2\'"
#Test with python-openstackclient => 3.8.0 output (column header change from 'Specs' to 'Properties') #Test with python-openstackclient => 3.8.0 output (column header change from 'Specs' to 'Properties')
describe '#instances' do describe '#instances' do
it 'finds qos' do it 'finds qos' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume qos', 'list', '--quiet', '--format', 'csv', []) .with('volume qos', 'list', '--quiet', '--format', 'csv', [])
.returns('"ID","Name","Consumer","Associations","Properties" .and_return('"ID","Name","Consumer","Associations","Properties"
"28b632e8-6694-4bba-bf68-67b19f619019","qos-1","front-end","my_type1","read_iops=\'value1\'" "28b632e8-6694-4bba-bf68-67b19f619019","qos-1","front-end","my_type1","read_iops=\'value1\'"
') ')
instances = provider_class.instances instances = provider_class.instances

View File

@ -15,8 +15,8 @@ describe Puppet::Provider::Cinder do
it 'should fail if no auth params are passed and the cinder config file does not have the expected contents' do it 'should fail if no auth params are passed and the cinder config file does not have the expected contents' do
mock = {} mock = {}
Puppet::Util::IniConfig::File.expects(:new).returns(mock) expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock)
mock.expects(:read).with('/etc/cinder/cinder.conf') expect(mock).to receive(:read).with('/etc/cinder/cinder.conf')
expect do expect do
klass.cinder_credentials klass.cinder_credentials
end.to raise_error(Puppet::Error, /Cinder types will not work/) end.to raise_error(Puppet::Error, /Cinder types will not work/)
@ -39,8 +39,8 @@ describe Puppet::Provider::Cinder do
'password' => 'password', 'password' => 'password',
} }
} }
Puppet::Util::IniConfig::File.expects(:new).returns(mock) expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock)
mock.expects(:read).with('/etc/cinder/cinder.conf') expect(mock).to receive(:read).with('/etc/cinder/cinder.conf')
expect(klass.cinder_credentials).to eq(creds_hash) expect(klass.cinder_credentials).to eq(creds_hash)
end end

View File

@ -40,9 +40,9 @@ describe provider_class do
describe 'managing type' do describe 'managing type' do
describe '#create' do describe '#create' do
it 'creates a type' do it 'creates a type' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume type', 'create', '--format', 'shell', ['--property', 'key=value', '--property', 'new_key=a-new_value', '--property', 'multiattach="<is> True"', '--public', 'Backend_1']) .with('volume type', 'create', '--format', 'shell', ['--property', 'key=value', '--property', 'new_key=a-new_value', '--property', 'multiattach="<is> True"', '--public', 'Backend_1'])
.returns('id="90e19aff-1b35-4d60-9ee3-383c530275ab" .and_return('id="90e19aff-1b35-4d60-9ee3-383c530275ab"
name="Backend_1" name="Backend_1"
properties="key=\'value\', new_key=\'a-new_value\', multiattach=\'<is> True\'" properties="key=\'value\', new_key=\'a-new_value\', multiattach=\'<is> True\'"
is_public="True" is_public="True"
@ -55,7 +55,7 @@ access_project_ids=""
describe '#destroy' do describe '#destroy' do
it 'destroys a type' do it 'destroys a type' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume type', 'delete', 'Backend_1') .with('volume type', 'delete', 'Backend_1')
provider.destroy provider.destroy
expect(provider.exists?).to be_falsey expect(provider.exists?).to be_falsey
@ -64,15 +64,15 @@ access_project_ids=""
describe '#instances' do describe '#instances' do
it 'finds types' do it 'finds types' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume type', 'list', '--quiet', '--format', 'csv', '--long') .with('volume type', 'list', '--quiet', '--format', 'csv', '--long')
.returns('"ID","Name","Is Public","Properties" .and_return('"ID","Name","Is Public","Properties"
"28b632e8-6694-4bba-bf68-67b19f619019","type-1","True","key1=\'value1\'" "28b632e8-6694-4bba-bf68-67b19f619019","type-1","True","key1=\'value1\'"
"4f992f69-14ec-4132-9313-55cc06a6f1f6","type-2","False","key2=\'value2\'" "4f992f69-14ec-4132-9313-55cc06a6f1f6","type-2","False","key2=\'value2\'"
') ')
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume type', 'show', '--format', 'shell', '4f992f69-14ec-4132-9313-55cc06a6f1f6') .with('volume type', 'show', '--format', 'shell', '4f992f69-14ec-4132-9313-55cc06a6f1f6')
.returns(' .and_return('
id="4f992f69-14ec-4132-9313-55cc06a6f1f6" id="4f992f69-14ec-4132-9313-55cc06a6f1f6"
name="type-2" name="type-2"
properties="key2=\'value2\'" properties="key2=\'value2\'"
@ -91,15 +91,15 @@ access_project_ids="54f4d231201b4944a5fa4587a09bda23, 54f4d231201b4944a5fa4587a0
end end
it 'finds types with a Properties hash' do it 'finds types with a Properties hash' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume type', 'list', '--quiet', '--format', 'csv', '--long') .with('volume type', 'list', '--quiet', '--format', 'csv', '--long')
.returns('"ID","Name","Is Public","Properties" .and_return('"ID","Name","Is Public","Properties"
"28b632e8-6694-4bba-bf68-67b19f619019","type-1","True","{\'key1\': \'value1\'}" "28b632e8-6694-4bba-bf68-67b19f619019","type-1","True","{\'key1\': \'value1\'}"
"4f992f69-14ec-4132-9313-55cc06a6f1f6","type-2","False","{\'key2\': \'value2\'}" "4f992f69-14ec-4132-9313-55cc06a6f1f6","type-2","False","{\'key2\': \'value2\'}"
') ')
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('volume type', 'show', '--format', 'shell', '4f992f69-14ec-4132-9313-55cc06a6f1f6') .with('volume type', 'show', '--format', 'shell', '4f992f69-14ec-4132-9313-55cc06a6f1f6')
.returns(' .and_return('
id="4f992f69-14ec-4132-9313-55cc06a6f1f6" id="4f992f69-14ec-4132-9313-55cc06a6f1f6"
name="type-2" name="type-2"
properties="key2=\'value2\'" properties="key2=\'value2\'"