summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2021-08-10 16:17:51 -0400
committerMarc A. Paradise <marc.paradise@gmail.com>2021-08-11 14:54:12 -0400
commitbe626aa3636b772b68521ee19862c548c4442ea8 (patch)
tree54e8bd141824c20becccc5bd459f1d8d6b8f7558 /spec/unit
parenta9a073b0a3e5bc9f73ac57e95393c0060cbe7809 (diff)
downloadchef-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/unit')
-rw-r--r--spec/unit/provider_spec.rb23
-rw-r--r--spec/unit/resource_spec.rb27
2 files changed, 42 insertions, 8 deletions
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