test delete action better, even for non-runnable LWRPs

This commit is contained in:
Adam Spiers 2014-03-22 22:35:54 +00:00
parent 2e3df98de8
commit e56a821156
5 changed files with 42 additions and 14 deletions

View File

@ -0,0 +1,26 @@
# Shared code used to test providers of non-runnable Chef resources
# representing Pacemaker CIB objects. For example the provider for
# primitives is runnable (since primitives can be started and stopped)
# but constraints cannot.
this_dir = File.dirname(__FILE__)
require File.expand_path('provider', this_dir)
require File.expand_path('shellout', this_dir)
shared_examples "a non-runnable resource" do |fixture|
include Chef::RSpec::Mixlib::ShellOut
it_should_behave_like "all Pacemaker LWRPs", fixture
describe ":delete action" do
it "should delete a resource" do
stub_shellout(fixture.definition_string)
provider.run_action :delete
cmd = "crm configure delete '#{fixture.name}'"
expect(@chef_run).to run_execute(cmd)
expect(@resource).to be_updated
end
end
end

View File

@ -62,3 +62,10 @@ shared_examples "action on non-existent resource" do |action, cmd, expected_erro
expect(@resource).not_to be_updated
end
end
shared_examples "all Pacemaker LWRPs" do |fixture|
describe ":delete action" do
it_should_behave_like "action on non-existent resource", \
:delete, "crm configure delete #{fixture.name}", nil
end
end

View File

@ -14,12 +14,11 @@ shared_examples "a runnable resource" do |fixture|
.and_return(running)
end
it_should_behave_like "all Pacemaker LWRPs", fixture
include Chef::RSpec::Mixlib::ShellOut
describe ":delete action" do
it_should_behave_like "action on non-existent resource", \
:delete, "crm configure delete #{fixture.name}", nil
it "should not delete a running resource" do
stub_shellout(fixture.definition_string)
expect_running(true)

View File

@ -1,7 +1,8 @@
require 'spec_helper'
this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/provider', this_dir)
require File.expand_path('../helpers/provider', this_dir)
require File.expand_path('../helpers/non_runnable_resource', this_dir)
require File.expand_path('../fixtures/colocation_constraint', this_dir)
describe "Chef::Provider::PacemakerColocation" do
@ -60,9 +61,6 @@ describe "Chef::Provider::PacemakerColocation" do
end
describe ":delete action" do
it_should_behave_like "action on non-existent resource", \
:delete, "crm configure delete #{fixture.name}", nil
end
it_should_behave_like "a non-runnable resource", fixture
end

View File

@ -1,8 +1,9 @@
require 'spec_helper'
this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/provider', this_dir)
require File.expand_path('../fixtures/location_constraint', this_dir)
require File.expand_path('../helpers/provider', this_dir)
require File.expand_path('../helpers/non_runnable_resource', this_dir)
require File.expand_path('../fixtures/location_constraint', this_dir)
describe "Chef::Provider::PacemakerLocation" do
# for use inside examples:
@ -59,9 +60,6 @@ describe "Chef::Provider::PacemakerLocation" do
end
describe ":delete action" do
it_should_behave_like "action on non-existent resource", \
:delete, "crm configure delete #{fixture.name}", nil
end
it_should_behave_like "a non-runnable resource", fixture
end