eliminate code duplication with shared context for LWRP tests

This commit is contained in:
Adam Spiers
2014-03-22 13:02:46 +00:00
parent cb492df519
commit bb280de1e0
7 changed files with 58 additions and 66 deletions

View File

@@ -1,5 +1,27 @@
# Shared code used to test providers of CIB objects # Shared code used to test providers of CIB objects
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__))
shared_context "a Pacemaker LWRP" do
before(:each) do
runner_opts = {
:step_into => [lwrp_name]
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
camelized_subclass_name = "Pacemaker" + lwrp_name.capitalize
@resource_class = ::Chef::Resource.const_get(camelized_subclass_name)
@provider_class = ::Chef::Provider.const_get(camelized_subclass_name)
@resource = @resource_class.new(fixture.name, @run_context)
end
let (:provider) { @provider_class.new(@resource, @run_context) }
end
shared_examples "action on non-existent resource" do |action, cmd, expected_error| shared_examples "action on non-existent resource" do |action, cmd, expected_error|
include Chef::RSpec::Pacemaker::CIBObject include Chef::RSpec::Pacemaker::CIBObject

View File

@@ -8,22 +8,17 @@ describe "Chef::Provider::PacemakerClone" do
# for use outside examples (e.g. when invoking shared_examples) # for use outside examples (e.g. when invoking shared_examples)
fixture = Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup fixture = Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup
before(:each) do def lwrp_name
runner_opts = { 'clone'
:step_into => ['pacemaker_clone'] end
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
@resource = Chef::Resource::PacemakerClone.new(fixture.name, @run_context) include_context "a Pacemaker LWRP"
before(:each) do
@resource.rsc fixture.rsc.dup @resource.rsc fixture.rsc.dup
@resource.meta Hash[fixture.meta.dup] @resource.meta Hash[fixture.meta.dup]
end end
let (:provider) { Chef::Provider::PacemakerClone.new(@resource, @run_context) }
def cib_object_class def cib_object_class
Pacemaker::Resource::Clone Pacemaker::Resource::Clone
end end

View File

@@ -8,22 +8,17 @@ describe "Chef::Provider::PacemakerColocation" do
# for use outside examples (e.g. when invoking shared_examples) # for use outside examples (e.g. when invoking shared_examples)
fixture = Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup fixture = Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup
before(:each) do def lwrp_name
runner_opts = { 'colocation'
:step_into => ['pacemaker_colocation'] end
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
@resource = Chef::Resource::PacemakerColocation.new(fixture.name, @run_context) include_context "a Pacemaker LWRP"
before(:each) do
@resource.score fixture.score @resource.score fixture.score
@resource.resources fixture.resources.dup @resource.resources fixture.resources.dup
end end
let (:provider) { Chef::Provider::PacemakerColocation.new(@resource, @run_context) }
def cib_object_class def cib_object_class
Pacemaker::Constraint::Colocation Pacemaker::Constraint::Colocation
end end

View File

@@ -8,22 +8,17 @@ describe "Chef::Provider::PacemakerGroup" do
# for use outside examples (e.g. when invoking shared_examples) # for use outside examples (e.g. when invoking shared_examples)
fixture = Chef::RSpec::Pacemaker::Config::RESOURCE_GROUP.dup fixture = Chef::RSpec::Pacemaker::Config::RESOURCE_GROUP.dup
before(:each) do def lwrp_name
runner_opts = { 'group'
:step_into => ['pacemaker_group'] end
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
@resource = Chef::Resource::PacemakerGroup.new(fixture.name, @run_context) include_context "a Pacemaker LWRP"
before(:each) do
@resource.members fixture.members.dup @resource.members fixture.members.dup
@resource.meta Hash[fixture.meta.dup] @resource.meta Hash[fixture.meta.dup]
end end
let (:provider) { Chef::Provider::PacemakerGroup.new(@resource, @run_context) }
def cib_object_class def cib_object_class
Pacemaker::Resource::Group Pacemaker::Resource::Group
end end

View File

@@ -8,23 +8,18 @@ describe "Chef::Provider::PacemakerLocation" do
# for use outside examples (e.g. when invoking shared_examples) # for use outside examples (e.g. when invoking shared_examples)
fixture = Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup fixture = Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup
before(:each) do def lwrp_name
runner_opts = { 'location'
:step_into => ['pacemaker_location'] end
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
@resource = Chef::Resource::PacemakerLocation.new(fixture.name, @run_context) include_context "a Pacemaker LWRP"
before(:each) do
@resource.rsc fixture.rsc @resource.rsc fixture.rsc
@resource.score fixture.score @resource.score fixture.score
@resource.node fixture.node.dup @resource.node fixture.node.dup
end end
let (:provider) { Chef::Provider::PacemakerLocation.new(@resource, @run_context) }
def cib_object_class def cib_object_class
Pacemaker::Constraint::Location Pacemaker::Constraint::Location
end end

View File

@@ -8,22 +8,17 @@ describe "Chef::Provider::PacemakerMs" do
# for use outside examples (e.g. when invoking shared_examples) # for use outside examples (e.g. when invoking shared_examples)
fixture = Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup fixture = Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup
before(:each) do def lwrp_name
runner_opts = { 'ms'
:step_into => ['pacemaker_ms'] end
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
@resource = Chef::Resource::PacemakerMs.new(fixture.name, @run_context) include_context "a Pacemaker LWRP"
before(:each) do
@resource.rsc fixture.rsc.dup @resource.rsc fixture.rsc.dup
@resource.meta Hash[fixture.meta.dup] @resource.meta Hash[fixture.meta.dup]
end end
let (:provider) { Chef::Provider::PacemakerMs.new(@resource, @run_context) }
def cib_object_class def cib_object_class
Pacemaker::Resource::MasterSlave Pacemaker::Resource::MasterSlave
end end

View File

@@ -8,24 +8,19 @@ describe "Chef::Provider::PacemakerPrimitive" do
# for use outside examples (e.g. when invoking shared_examples) # for use outside examples (e.g. when invoking shared_examples)
fixture = Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE fixture = Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE
before(:each) do def lwrp_name
runner_opts = { 'primitive'
:step_into => ['pacemaker_primitive'] end
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
@resource = Chef::Resource::PacemakerPrimitive.new(fixture.name, @run_context) include_context "a Pacemaker LWRP"
before(:each) do
@resource.agent fixture.agent @resource.agent fixture.agent
@resource.params Hash[fixture.params] @resource.params Hash[fixture.params]
@resource.meta Hash[fixture.meta] @resource.meta Hash[fixture.meta]
@resource.op Hash[fixture.op] @resource.op Hash[fixture.op]
end end
let (:provider) { Chef::Provider::PacemakerPrimitive.new(@resource, @run_context) }
def cib_object_class def cib_object_class
Pacemaker::Resource::Primitive Pacemaker::Resource::Primitive
end end