Merge "Replace mocha by rspec-mocks"

This commit is contained in:
Zuul 2023-01-31 15:48:33 +00:00 committed by Gerrit Code Review
commit 6a4adce43c
5 changed files with 45 additions and 43 deletions

View File

@ -14,6 +14,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! }

View File

@ -37,14 +37,14 @@ describe Puppet::Type.type(:nova_aggregate).provider(:openstack) do
describe '#instances' do
it 'finds existing aggregates' do
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'list', '--quiet', '--format', 'csv', [])
.returns('"ID","Name","Availability Zone"
.and_return('"ID","Name","Availability Zone"
just,"simple","just"
')
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'show', '--format', 'shell', 'simple')
.returns('"id="just"
.and_return('"id="just"
name="simple"
availability_zone=just"
properties="key1=\'tomato\', key2=\'mushroom\'"
@ -59,18 +59,18 @@ hosts="[]"
describe '#create' do
it 'creates aggregate' do
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'create', '--format', 'shell',
['just', '--zone', 'simple', '--property', 'nice=cookie' ])
.returns('name="just"
.and_return('name="just"
id="just"
availability_zone="simple"
properties="{u\'nice\': u\'cookie\'}"
hosts="[]"
')
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'add host', ['just', 'example'])
.returns('name="just"
.and_return('name="just"
id="just"
availability_zone="simple"
properties="{u\'nice\': u\'cookie\'}"
@ -84,9 +84,9 @@ hosts="[u\'example\']"
describe '#destroy' do
it 'removes aggregate with hosts' do
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'remove host', ['just', 'example'])
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'delete', 'just')
provider.instance_variable_set(:@property_hash, aggregate_attrs)
provider.destroy
@ -151,47 +151,47 @@ hosts="[u\'example\']"
it 'creates aggregate with filter_hosts toggled' do
provider.class.stubs(:get_known_hosts)
.returns(['known', 'known_too'])
allow(provider.class).to receive(:get_known_hosts)
.and_return(['known', 'known_too'])
# these expectations are the actual tests that check the provider's behaviour
# and make sure only known hosts ('known' is the only known host) will be
# aggregated.
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'create', '--format', 'shell', ['just', '--zone', 'simple', "--property", "nice=cookie"])
.once
.returns('name="just"
.and_return('name="just"
id="just"
availability_zone="simple"
properties="{u\'nice\': u\'cookie\'}"
hosts="[]"
')
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'add host', ['just', 'known'])
.once
.returns('name="just"
.and_return('name="just"
id="just"
availability_zone="simple"
properties="{u\'nice\': u\'cookie\'}"
hosts="[u\'known\']"
')
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'add host', ['just', 'known_too'])
.once
.returns('name="just"
.and_return('name="just"
id="just"
availability_zone="simple"
properties="{u\'nice\': u\'cookie\'}"
hosts="[u\'known\', u\'known_too\']"
')
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('aggregate', 'remove host', ['just', 'known'])
.once
.returns('name="just"
.and_return('name="just"
id="just"
availability_zone="simple"
properties="{u\'nice\': u\'cookie\'}"

View File

@ -38,9 +38,9 @@ describe Puppet::Type.type(:nova_flavor).provider(:openstack) do
describe '#create' do
context 'with defaults' do
it 'creates flavor' do
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('flavor', 'create', '--format', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
.returns('os-flv-disabled:disabled="False"
.and_return('os-flv-disabled:disabled="False"
os-flv-ext-data:ephemeral="0"
disk="1"
id="1"
@ -63,9 +63,9 @@ vcpus="1"')
end
it 'creates flavor' do
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('flavor', 'create', '--format', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
.returns('os-flv-disabled:disabled="False"
.and_return('os-flv-disabled:disabled="False"
os-flv-ext-data:ephemeral="0"
disk="1"
id="1"
@ -75,11 +75,11 @@ ram="512"
rxtx_factor="1.0"
swap=""
vcpus="1"')
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('flavor', 'set', ['example', '--project', '3073e17b-fb7f-4524-bdcd-c54bc70e9da9'])
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('project', 'show', '--format', 'shell', '3073e17b-fb7f-4524-bdcd-c54bc70e9da9')
.returns('enabled="True"
.and_return('enabled="True"
name="admin"
id="3073e17b-fb7f-4524-bdcd-c54bc70e9da9"
domain_id="domain_one_id"
@ -99,9 +99,9 @@ domain_id="domain_one_id"
end
it 'creates flavor with project_name' do
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('flavor', 'create', '--format', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
.returns('os-flv-disabled:disabled="False"
.and_return('os-flv-disabled:disabled="False"
os-flv-ext-data:ephemeral="0"
disk="1"
id="1"
@ -111,11 +111,11 @@ ram="512"
rxtx_factor="1.0"
swap=""
vcpus="1"')
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('flavor', 'set', ['example', '--project', 'admin'])
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('project', 'show', '--format', 'shell', 'admin')
.returns('enabled="True"
.and_return('enabled="True"
name="admin"
id="3073e17b-fb7f-4524-bdcd-c54bc70e9da9"
domain_id="domain_one_id"
@ -130,7 +130,7 @@ domain_id="domain_one_id"
describe '#destroy' do
it 'removes flavor' do
described_class.expects(:openstack)
expect(described_class).to receive(:openstack)
.with('flavor', 'delete', '1')
provider.instance_variable_set(:@property_hash, flavor_attrs)
provider.destroy
@ -141,7 +141,7 @@ domain_id="domain_one_id"
describe '#flush' do
context '.project' do
it 'updates flavor' do
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('flavor', 'set', ['example', '--project', '3073e17b-fb7f-4524-bdcd-c54bc70e9da9'])
provider.project = '3073e17b-fb7f-4524-bdcd-c54bc70e9da9'
provider.flush
@ -150,7 +150,7 @@ domain_id="domain_one_id"
context '.project_name' do
it 'updates flavor' do
provider.class.expects(:openstack)
expect(provider.class).to receive(:openstack)
.with('flavor', 'set', ['example', '--project', 'admin'])
provider.project_name = 'admin'
provider.flush

View File

@ -42,9 +42,9 @@ describe provider_class do
it_behaves_like 'authenticated with environment variables' do
describe '#instances' do
it 'finds existing services' do
provider_class.expects(:openstack)
expect(provider_class).to receive(:openstack)
.with('compute service', 'list', '--quiet', '--format', 'csv', [])
.returns('"Id","Binary","Host","Zone","Status","State","Updated At"
.and_return('"Id","Binary","Host","Zone","Status","State","Updated At"
"1","waffles","myhost","internal","enabled","down","2016-01-01T12:00:00.000000"')
instances = provider_class.instances
@ -55,8 +55,8 @@ describe provider_class do
describe '#destroy' do
it 'destroys a service' do
provider.class.stubs(:openstack)
.with('compute service', 'delete', [])
allow(provider.class).to receive(:openstack)
.with('compute service', 'delete', [])
provider.destroy
expect(provider.exists?).to be_falsey
end

View File

@ -35,7 +35,7 @@ describe Puppet::Provider::Nova do
it 'should fail if config is empty' do
conf = {}
klass.expects(:nova_conf).returns(conf)
expect(klass).to receive(:nova_conf).and_return(conf)
expect do
klass.nova_credentials
end.to raise_error(Puppet::Error, credential_error)
@ -43,7 +43,7 @@ describe Puppet::Provider::Nova do
it 'should fail if config does not have keystone_authtoken section.' do
conf = {'foo' => 'bar'}
klass.expects(:nova_conf).returns(conf)
expect(klass).to receive(:nova_conf).and_return(conf)
expect do
klass.nova_credentials
end.to raise_error(Puppet::Error, credential_error)
@ -51,7 +51,7 @@ describe Puppet::Provider::Nova do
it 'should fail if config does not contain all auth params' do
conf = {'keystone_authtoken' => {'invalid_value' => 'foo'}}
klass.expects(:nova_conf).returns(conf)
expect(klass).to receive(:nova_conf).and_return(conf)
expect do
klass.nova_credentials
end.to raise_error(Puppet::Error, credential_error)
@ -59,7 +59,7 @@ describe Puppet::Provider::Nova do
it 'should use specified uri in the auth endpoint' do
conf = {'keystone_authtoken' => credential_hash}
klass.expects(:nova_conf).returns(conf)
expect(klass).to receive(:nova_conf).and_return(conf)
expect(klass.get_auth_endpoint).to eq(auth_endpoint)
end