diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2021-08-10 16:17:51 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2021-08-11 14:54:12 -0400 |
commit | be626aa3636b772b68521ee19862c548c4442ea8 (patch) | |
tree | 54e8bd141824c20becccc5bd459f1d8d6b8f7558 /spec | |
parent | a9a073b0a3e5bc9f73ac57e95393c0060cbe7809 (diff) | |
download | chef-be626aa3636b772b68521ee19862c548c4442ea8.tar.gz |
Add support for provider action description
Often actions are defined on the provider and not on the resource. This
change updates Provider to support a description opt when declaring the
action, which lets us improve our generated documentation.
This also updates ResourceInspector to look at the provider if the
resource itself does not offer an action description for a given action.
Example:
action :foo, description: "bar" do
...
end
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/integration/recipes/resource_action_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider_spec.rb | 23 | ||||
-rw-r--r-- | spec/unit/resource_spec.rb | 27 |
3 files changed, 44 insertions, 10 deletions
diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index 009a78a24a..fc22a3c9d2 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -354,8 +354,8 @@ module ResourceActionSpec end it "allows overridden action to have a description separate from the action defined in the base resource" do - expect(ActionJackson.action_description(:test1)).to eql "Original description" - expect(ActionJackalope.action_description(:test1)).to eql "An old action with a new description" + expect(ActionJackson.new("ActionJackson", nil).action_description(:test1)).to eql "Original description" + expect(ActionJackalope.new("ActionJackalope", nil).action_description(:test1)).to eql "An old action with a new description" end it "non-overridden actions run and can access overridden and non-overridden variables (but not necessarily new ones)" do diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb index 28874bc0f3..88262dd33a 100644 --- a/spec/unit/provider_spec.rb +++ b/spec/unit/provider_spec.rb @@ -32,6 +32,21 @@ class NoWhyrunDemonstrator < Chef::Provider end end +class ActionDescriptionDemonstrator < Chef::Provider + def load_current_resource; end + + action :foo, description: "foo described" do + true + end + + action :foo2 do + true + end + +end + +context "blah" do +end class ConvergeActionDemonstrator < Chef::Provider attr_reader :system_state_altered @@ -98,6 +113,14 @@ describe Chef::Provider do expect(@provider.action_nothing).to eql(true) end + it "should return an action description for action_description when one is available" do + expect(ActionDescriptionDemonstrator.action_description(:foo)).to eq "foo described" + end + + it "should return nil for action_description when no description is available" do + expect(ActionDescriptionDemonstrator.action_description(:none)).to eq nil + end + it "evals embedded recipes with a pristine resource collection" do @provider.run_context.instance_variable_set(:@resource_collection, "doesn't matter what this is") temporary_collection = nil diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index f7109cc680..5f662dea60 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -1172,21 +1172,23 @@ describe Chef::Resource do action :base_action3, description: "unmodified base action 3 desc" do; end end + let(:resource_inst) { TestResource.new("TestResource", nil) } + it "returns nil when no description was provided for the action" do - expect(TestResource.action_description(:base_action0)).to eql(nil) + expect(resource_inst.action_description(:base_action0)).to eql(nil) end context "when action definition is a string" do it "returns the description whether a symbol or string is used to look it up" do - expect(TestResource.action_description("string_action")).to eql("a string test") - expect(TestResource.action_description(:string_action)).to eql("a string test") + expect(resource_inst.action_description("string_action")).to eql("a string test") + expect(resource_inst.action_description(:string_action)).to eql("a string test") end end context "when action definition is a symbol" do it "returns the description whether a symbol or string is used to look up" do - expect(TestResource.action_description("symbol_action")).to eql("a symbol test") - expect(TestResource.action_description(:symbol_action)).to eql("a symbol test") + expect(resource_inst.action_description("symbol_action")).to eql("a symbol test") + expect(resource_inst.action_description(:symbol_action)).to eql("a symbol test") end end @@ -1196,14 +1198,23 @@ describe Chef::Resource do action :base_action3 do; end end + class TestResourceChild2 < TestResource + # We should never see this description + action :base_action2, description: "if you see this in an error, TestResourceChild was polluted with this description" do; end + end + let(:resource_inst) { TestResourceChild.new("TestResource", nil) } + it "returns original description when a described action is not overridden in child resource" do - expect(TestResourceChild.action_description(:base_action1)).to eq "unmodified base action 1 desc" + expect(resource_inst.action_description(:base_action1)).to eq "unmodified base action 1 desc" end it "returns original description when the child resource overrides an inherited action but NOT its description" do - expect(TestResourceChild.action_description(:base_action3)).to eq "unmodified base action 3 desc" + expect(resource_inst.action_description(:base_action3)).to eq "unmodified base action 3 desc" + end + it "returns new description when the child resource overrides an inherited action and its description" do + expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc" end it "returns new description when the child resource overrides an inherited action and its description" do - expect(TestResourceChild.action_description(:base_action2)).to eq "modified base action 2 desc" + expect(resource_inst.action_description(:base_action2)).to eq "modified base action 2 desc" end end end |