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: I47b660d1713b394a2dd72a24a87b614d551fe802
This commit is contained in:
parent
d72f4b7535
commit
feea648419
|
@ -11,6 +11,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! }
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
require 'puppet'
|
||||
require 'mocha'
|
||||
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'lib', 'puppet', 'provider', 'ring_account_device', 'swift_ring_builder')
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
provider_class = Puppet::Type.type(:ring_account_device).provider(:swift_ring_builder)
|
||||
describe provider_class do
|
||||
|
||||
|
@ -52,15 +48,15 @@ Devices: id region zone ip address:port replic_ip:replic_port
|
|||
end
|
||||
|
||||
it 'ring_account_device should exist when found in builder file' do
|
||||
provider.class.stubs(:swift_ring_builder).returns account_builder_output
|
||||
File.expects(:exists?).with(builder_file_path).returns(true)
|
||||
allow(provider.class).to receive(:swift_ring_builder).and_return account_builder_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path).and_return(true)
|
||||
expect(provider.exists?).to eq({:id=>"1", :region=>"1", :zone=>"1", :weight=>"1.00", :partitions=>"262144", :balance=>"0.00", :meta=>"", :policy_index=>''})
|
||||
end
|
||||
|
||||
it 'should be able to lookup the local ring' do
|
||||
File.expects(:exists?).with(builder_file_path).returns(true)
|
||||
provider.expects(:builder_file_path).twice.returns(builder_file_path)
|
||||
provider.expects(:swift_ring_builder).returns account_builder_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path).and_return(true)
|
||||
expect(provider).to receive(:builder_file_path).twice.and_return(builder_file_path)
|
||||
expect(provider).to receive(:swift_ring_builder).and_return account_builder_output
|
||||
resources = provider.lookup_ring
|
||||
expect(resources['192.168.101.13:6002/1']).to_not be_nil
|
||||
expect(resources['192.168.101.14:6002/1']).to_not be_nil
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
require 'puppet'
|
||||
require 'mocha'
|
||||
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'lib', 'puppet', 'provider', 'ring_container_device', 'swift_ring_builder')
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
provider_class = Puppet::Type.type(:ring_container_device).provider(:swift_ring_builder)
|
||||
describe provider_class do
|
||||
|
||||
|
@ -49,15 +45,15 @@ Devices: id region zone ip address:port replic_ip:replic_port
|
|||
end
|
||||
|
||||
it 'ring_container_device should exist when found in builder file' do
|
||||
provider.expects(:swift_ring_builder).returns container_builder_output
|
||||
File.expects(:exists?).with(builder_file_path).returns(true)
|
||||
expect(provider).to receive(:swift_ring_builder).and_return container_builder_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path).and_return(true)
|
||||
expect(provider.exists?).to eq({:id=>"1", :region=>"1", :zone=>"1", :weight=>"1.00", :partitions=>"262144", :balance=>"0.00", :meta=>"", :policy_index=>''})
|
||||
end
|
||||
|
||||
it 'should be able to lookup the local ring' do
|
||||
File.expects(:exists?).with(builder_file_path).returns(true)
|
||||
provider.expects(:builder_file_path).twice.returns(builder_file_path)
|
||||
provider.expects(:swift_ring_builder).returns container_builder_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path).and_return(true)
|
||||
expect(provider).to receive(:builder_file_path).twice.and_return(builder_file_path)
|
||||
expect(provider).to receive(:swift_ring_builder).and_return container_builder_output
|
||||
resources = provider.lookup_ring
|
||||
expect(resources['192.168.101.13:6002/1']).to_not be_nil
|
||||
expect(resources['192.168.101.14:6002/1']).to_not be_nil
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
require 'puppet'
|
||||
require 'mocha'
|
||||
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'lib', 'puppet', 'provider', 'ring_object_device', 'swift_ring_builder')
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
provider_class = Puppet::Type.type(:ring_object_device).provider(:swift_ring_builder)
|
||||
describe provider_class do
|
||||
|
||||
|
@ -61,15 +57,15 @@ Devices: id region zone ip address:port replic_ip:replic_port
|
|||
end
|
||||
|
||||
it 'ring_object_device should exist when found in builder file' do
|
||||
provider.expects(:swift_ring_builder).returns object_builder_output
|
||||
File.expects(:exists?).with(builder_file_path).returns(true)
|
||||
expect(provider).to receive(:swift_ring_builder).and_return object_builder_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path).and_return(true)
|
||||
expect(provider.exists?).to eq({:id=>"1", :region=>"1", :zone=>"1", :weight=>"1.00", :partitions=>"262144", :balance=>"0.00", :meta=>"", :policy_index=>''})
|
||||
end
|
||||
|
||||
it 'should be able to lookup the local ring' do
|
||||
File.expects(:exists?).with(builder_file_path).returns(true)
|
||||
provider.expects(:builder_file_path).twice.returns(builder_file_path)
|
||||
provider.expects(:swift_ring_builder).returns object_builder_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path).and_return(true)
|
||||
expect(provider).to receive(:builder_file_path).twice.and_return(builder_file_path)
|
||||
expect(provider).to receive(:swift_ring_builder).and_return object_builder_output
|
||||
resources = provider.lookup_ring
|
||||
expect(resources['192.168.101.13:6002/1']).to_not be_nil
|
||||
expect(resources['192.168.101.14:6002/1']).to_not be_nil
|
||||
|
@ -138,15 +134,15 @@ Devices: id region zone ip address:port replic_ip:replic_port
|
|||
end
|
||||
|
||||
it 'ring_object_device should exist when found in builder file with policy_index=1' do
|
||||
provider_policy1.expects(:swift_ring_builder).returns object_builder_policy1_output
|
||||
File.expects(:exists?).with(builder_file_path_policy1).returns(true)
|
||||
expect(provider_policy1).to receive(:swift_ring_builder).and_return object_builder_policy1_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path_policy1).and_return(true)
|
||||
expect(provider_policy1.exists?).to eq({:id=>"1", :region=>"1", :zone=>"1", :weight=>"1.00", :partitions=>"262144", :balance=>"0.00", :meta=>"", :policy_index=>"1"})
|
||||
end
|
||||
|
||||
it 'lookup local ring and object resource names should start with policy_index if a policy is set' do
|
||||
File.expects(:exists?).with(builder_file_path_policy1).returns(true)
|
||||
provider_policy1.expects(:builder_file_path).twice.returns(builder_file_path_policy1)
|
||||
provider_policy1.expects(:swift_ring_builder).returns object_builder_output
|
||||
expect(File).to receive(:exists?).with(builder_file_path_policy1).and_return(true)
|
||||
expect(provider_policy1).to receive(:builder_file_path).twice.and_return(builder_file_path_policy1)
|
||||
expect(provider_policy1).to receive(:swift_ring_builder).and_return object_builder_output
|
||||
resources = provider_policy1.lookup_ring
|
||||
expect(resources['1:192.168.101.13:6002/1']).to_not be_nil
|
||||
expect(resources['1:192.168.101.14:6002/1']).to_not be_nil
|
||||
|
|
|
@ -17,20 +17,20 @@ describe provider_class do
|
|||
@provider = provider_class.new
|
||||
|
||||
# A catch all; no parameters set
|
||||
@resource.stubs(:[]).returns(nil)
|
||||
allow(@resource).to receive(:[]).and_return(nil)
|
||||
|
||||
# But set name, source and path
|
||||
@resource.stubs(:[]).with(:name).returns "swift-object-server"
|
||||
@resource.stubs(:[]).with(:ensure).returns :enable
|
||||
@resource.stubs(:[]).with(:pattern).returns "swift-object"
|
||||
@resource.stubs(:[]).with(:manifest).returns "object-server"
|
||||
@resource.stubs(:ref).returns "Service[myservice]"
|
||||
allow(@resource).to receive(:[]).with(:name).and_return "swift-object-server"
|
||||
allow(@resource).to receive(:[]).with(:ensure).and_return :enable
|
||||
allow(@resource).to receive(:[]).with(:pattern).and_return "swift-object"
|
||||
allow(@resource).to receive(:[]).with(:manifest).and_return "object-server"
|
||||
allow(@resource).to receive(:ref).and_return "Service[myservice]"
|
||||
|
||||
@provider.resource = @resource
|
||||
|
||||
@provider.stubs(:command).with(:systemctl_run).returns "systemctl_run"
|
||||
allow(@provider).to receive(:command).with(:systemctl_run).and_return "systemctl_run"
|
||||
|
||||
@provider.stubs(:systemctl_run)
|
||||
allow(@provider).to receive(:systemctl_run)
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
require 'puppet'
|
||||
require 'mocha'
|
||||
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec', 'fixtures', 'modules', 'inifile', 'lib', 'puppet', 'util', 'ini_file')
|
||||
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'lib', 'puppet', 'provider', 'swift_storage_policy', 'ruby')
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
provider_class = Puppet::Type.type(:swift_storage_policy).provider(:ruby)
|
||||
describe provider_class do
|
||||
|
||||
|
@ -110,7 +106,7 @@ default = false
|
|||
fh.write(swift_conf_no_policy)
|
||||
end
|
||||
@swiftconffile = swift_conf.path
|
||||
provider0.class.stubs(:get_swift_conf_file).returns @swiftconffile
|
||||
allow(provider0.class).to receive(:get_swift_conf_file).and_return @swiftconffile
|
||||
end
|
||||
|
||||
it 'the swift_storage_policy 0 resource should contain the correct policy_title and name' do
|
||||
|
@ -142,7 +138,7 @@ default = false
|
|||
:provider => :ruby
|
||||
)
|
||||
)
|
||||
provider1.class.stubs(:get_swift_conf_file).returns @swiftconffile
|
||||
allow(provider1.class).to receive(:get_swift_conf_file).and_return @swiftconffile
|
||||
# storage-policy:1 should not yet exist in swift.conf
|
||||
expect(provider1.exists?).to be_falsey
|
||||
# Create policy 1,flush calls provider "write_policy"
|
||||
|
@ -165,7 +161,7 @@ default = false
|
|||
:provider => :ruby
|
||||
)
|
||||
)
|
||||
provider2.class.stubs(:get_swift_conf_file).returns @swiftconffile
|
||||
allow(provider2.class).to receive(:get_swift_conf_file).and_return @swiftconffile
|
||||
# storage-policy:2 should raise an error for duplicate name/alias conflict with storage-policy:0
|
||||
provider2.create
|
||||
expect { provider2.flush }.to raise_error(Puppet::Error, /trying to set a duplicate name/)
|
||||
|
@ -184,7 +180,7 @@ default = false
|
|||
:provider => :ruby
|
||||
)
|
||||
)
|
||||
provider2.class.stubs(:get_swift_conf_file).returns @swiftconffile
|
||||
allow(provider2.class).to receive(:get_swift_conf_file).and_return @swiftconffile
|
||||
provider2.create
|
||||
expect { provider2.flush }.not_to raise_error
|
||||
# storage-policy:0,1,2 should exist in swift.conf
|
||||
|
@ -201,7 +197,7 @@ default = false
|
|||
:provider => :ruby
|
||||
)
|
||||
)
|
||||
provider1.class.stubs(:get_swift_conf_file).returns @swiftconffile
|
||||
allow(provider1.class).to receive(:get_swift_conf_file).and_return @swiftconffile
|
||||
provider1.create
|
||||
expect { provider1.flush }.to raise_error(Puppet::Error, /default=true already set in a policy storage-policy:0/)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue