diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2022-03-31 21:33:32 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2022-03-31 21:34:02 -0700 |
commit | 1147c39a4b6cbb36b8293ee02ceb122e89217408 (patch) | |
tree | 5fe52e95cdb55e903cfecd87d9f6f96bb6a95db0 | |
parent | 5ad5f9179c5790f0bbd0532d8f6a972f7eeea8fe (diff) | |
download | chef-1147c39a4b6cbb36b8293ee02ceb122e89217408.tar.gz |
more consolidation
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/resource/core_partials/rest_resource.rb | 23 | ||||
-rw-r--r-- | spec/unit/resource/core_partials/rest_resource_spec.rb (renamed from spec/unit/provider/rest_resource_spec.rb) | 16 | ||||
-rw-r--r-- | spec/unit/resource/rest_resource_spec.rb | 35 |
3 files changed, 27 insertions, 47 deletions
diff --git a/lib/chef/resource/core_partials/rest_resource.rb b/lib/chef/resource/core_partials/rest_resource.rb index 9c388ea694..e64d589f5a 100644 --- a/lib/chef/resource/core_partials/rest_resource.rb +++ b/lib/chef/resource/core_partials/rest_resource.rb @@ -72,9 +72,18 @@ action :delete do end end -private - action_class do + # Override this for postprocessing device-specifics (paging, data conversion) + def rest_postprocess(response) + response + end + + # Override this for error handling of device-specifics (readable error messages) + def rest_errorhandler(error_obj) + error_obj + end + + private def resource_exists? @resource_exists @@ -322,16 +331,6 @@ action_class do Chef.run_context.transport.connection end - # Override this for postprocessing device-specifics (paging, data conversion) - def rest_postprocess(response) - response - end - - # Override this for error handling of device-specifics (readable error messages) - def rest_errorhandler(error_obj) - error_obj - end - # Remove all empty keys (recusively) from Hash. # @see https://stackoverflow.com/questions/56457020/#answer-56458673 def deep_compact!(hsh) diff --git a/spec/unit/provider/rest_resource_spec.rb b/spec/unit/resource/core_partials/rest_resource_spec.rb index 4201958d57..0a6a36c21d 100644 --- a/spec/unit/provider/rest_resource_spec.rb +++ b/spec/unit/resource/core_partials/rest_resource_spec.rb @@ -76,6 +76,22 @@ describe "rest_resource using query-based addressing" do expect(provider).to respond_to(:action_nothing) end + it "sets the default action as :configure" do + expect(resource.action).to eql([:configure]) + end + + it "supports :configure action" do + expect { resource.action :configure }.not_to raise_error + end + + it "supports :delete action" do + expect { resource.action :delete }.not_to raise_error + end + + it "should mixin RestResourceDSL" do + expect(resource.class.included_modules).to include(Chef::DSL::RestResource) + end + describe "#rest_postprocess" do before do provider.singleton_class.send(:public, :rest_postprocess) diff --git a/spec/unit/resource/rest_resource_spec.rb b/spec/unit/resource/rest_resource_spec.rb deleted file mode 100644 index f21b43f357..0000000000 --- a/spec/unit/resource/rest_resource_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ - -require "spec_helper" - -describe Chef::Resource::RestResource do - let(:resource_instance_name) { "some_name" } - let(:resource_name) { :rest_resource } - - let(:resource) do - run_context = Chef::RunContext.new(Chef::Node.new, nil, nil) - - Chef::Resource::RestResource.new(resource_instance_name, run_context) - end - - it "is a subclass of Chef::Resource" do - expect(resource).to be_a_kind_of(Chef::Resource) - end - - it "sets the default action as :configure" do - expect(resource.action).to eql([:configure]) - end - - it "supports :configure action" do - expect { resource.action :configure }.not_to raise_error - end - - it "supports :delete action" do - expect { resource.action :delete }.not_to raise_error - end - - it "should mixin RestResourceDSL" do - expect(resource.class.included_modules).to include(Chef::DSL::RestResource) - end - - # TODO: how to test for target_mode support? -end |