diff --git a/spec/helpers/non_runnable_resource.rb b/spec/helpers/non_runnable_resource.rb new file mode 100644 index 0000000..594406a --- /dev/null +++ b/spec/helpers/non_runnable_resource.rb @@ -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 diff --git a/spec/helpers/provider.rb b/spec/helpers/provider.rb index 591f89a..38f8fc3 100644 --- a/spec/helpers/provider.rb +++ b/spec/helpers/provider.rb @@ -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 diff --git a/spec/helpers/runnable_resource.rb b/spec/helpers/runnable_resource.rb index 5695d35..ec831d5 100644 --- a/spec/helpers/runnable_resource.rb +++ b/spec/helpers/runnable_resource.rb @@ -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) diff --git a/spec/providers/colocation_spec.rb b/spec/providers/colocation_spec.rb index 541c07b..aa43d7e 100644 --- a/spec/providers/colocation_spec.rb +++ b/spec/providers/colocation_spec.rb @@ -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 diff --git a/spec/providers/location_spec.rb b/spec/providers/location_spec.rb index 80566c8..fa3c1fe 100644 --- a/spec/providers/location_spec.rb +++ b/spec/providers/location_spec.rb @@ -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