summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-05 14:01:01 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-08 09:01:55 -0700
commitc65de79dbd662d895c8a10ef496d7eb9c69376c2 (patch)
treec0d171b5e87bd103660369a7497972e695379d1b /spec
parent01f575ce28a55dcdc7b3945c5f49ebb652a1fff3 (diff)
downloadchef-c65de79dbd662d895c8a10ef496d7eb9c69376c2.tar.gz
Overwrite resource_name with provides
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb250
-rw-r--r--spec/support/lib/chef/resource/cat.rb1
-rw-r--r--spec/support/lib/chef/resource/one_two_three_four.rb1
-rw-r--r--spec/support/lib/chef/resource/openldap_includer.rb1
-rw-r--r--spec/support/lib/chef/resource/with_state.rb2
-rw-r--r--spec/support/lib/chef/resource/zen_follower.rb1
-rw-r--r--spec/support/lib/chef/resource/zen_master.rb1
-rw-r--r--spec/unit/recipe_spec.rb4
-rw-r--r--spec/unit/resource_spec.rb14
9 files changed, 234 insertions, 41 deletions
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 45239a0b17..403c879e74 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -116,10 +116,10 @@ describe "Recipe DSL methods" do
end
end
- context "With a resource named Chef::Resource::NoNameThingy with resource_name nil" do
+ context "With a resource named NoNameThingy with resource_name nil" do
before(:context) {
- class Chef::Resource::NoNameThingy < BaseThingy
+ class NoNameThingy < BaseThingy
resource_name nil
end
@@ -132,10 +132,10 @@ describe "Recipe DSL methods" do
end
end
- context "With a resource named Chef::Resource::AnotherNoNameThingy with resource_name :another_thingy_name" do
+ context "With a resource named AnotherNoNameThingy with resource_name :another_thingy_name" do
before(:context) {
- class Chef::Resource::AnotherNoNameThingy < BaseThingy
+ class AnotherNoNameThingy < BaseThingy
resource_name :another_thingy_name
end
@@ -152,38 +152,256 @@ describe "Recipe DSL methods" do
another_thingy_name 'blah' do; end
}
expect(recipe.logged_warnings).to eq ''
- expect(BaseThingy.created_resource).to eq(Chef::Resource::AnotherNoNameThingy)
+ expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy)
end
end
- context "With a resource named Chef::Resource::YetAnotherNoNameThingy with resource_name :yet_another_thingy_name; resource_name :yet_another_thingy_name_2" do
+ context "With a resource named AnotherNoNameThingy2 with resource_name :another_thingy_name2; resource_name :another_thingy_name3" do
before(:context) {
- class Chef::Resource::YetAnotherNoNameThingy < BaseThingy
- resource_name :yet_another_thingy_name
- resource_name :yet_another_thingy_name_2
+ class AnotherNoNameThingy2 < BaseThingy
+ resource_name :another_thingy_name2
+ resource_name :another_thingy_name3
end
}
- it "yet_another_no_name_thingy does not work" do
+ it "another_no_name_thingy does not work" do
expect_converge {
- yet_another_no_name_thingy 'blah' do; end
+ another_no_name_thingy2 'blah' do; end
}.to raise_error(NoMethodError)
end
- it "yet_another_thingy_name does not work" do
+ it "another_thingy_name2 does not work" do
expect_converge {
- yet_another_thingy_name 'blah' do; end
+ another_thingy_name2 'blah' do; end
}.to raise_error(NoMethodError)
end
- it "yet_another_thingy_name_2 works" do
+ it "yet_another_thingy_name3 works" do
recipe = converge {
- yet_another_thingy_name_2 'blah' do; end
+ another_thingy_name3 'blah' do; end
}
expect(recipe.logged_warnings).to eq ''
- expect(BaseThingy.created_resource).to eq(Chef::Resource::YetAnotherNoNameThingy)
+ expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy2)
+ end
+ end
+
+ context "provides overriding resource_name" do
+ context "With a resource named AnotherNoNameThingy3 with provides :another_no_name_thingy3, os: 'blarghle'" do
+ before(:context) {
+
+ class AnotherNoNameThingy3 < BaseThingy
+ provides :another_no_name_thingy3, os: 'blarghle'
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy3 does not work" do
+ expect_converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy3 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy3 works" do
+ recipe = converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy3 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy3)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy4 with two provides" do
+ before(:context) {
+
+ class AnotherNoNameThingy4 < BaseThingy
+ provides :another_no_name_thingy4, os: 'blarghle'
+ provides :another_no_name_thingy4, platform_family: 'foo'
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy4 does not work" do
+ expect_converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy4 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy4 works" do
+ recipe = converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy4 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4)
+ end
+
+ it "and platform_family = foo, another_no_name_thingy4 works" do
+ recipe = converge {
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:platform_family] = 'foo'
+ another_no_name_thingy4 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy5, a different resource_name, and a provides with the original resource_name" do
+ before(:context) {
+
+ class AnotherNoNameThingy5 < BaseThingy
+ resource_name :another_thingy_name_for_another_no_name_thingy5
+ provides :another_no_name_thingy5, os: 'blarghle'
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy5 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy5 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy5 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy5 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5)
+ end
+
+ it "the new resource name can be used in a recipe" do
+ recipe = converge {
+ another_thingy_name_for_another_no_name_thingy5 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy6, a provides with the original resource name, and a different resource_name" do
+ before(:context) {
+
+ class AnotherNoNameThingy6 < BaseThingy
+ provides :another_no_name_thingy6, os: 'blarghle'
+ resource_name :another_thingy_name_for_another_no_name_thingy6
+ end
+
+ }
+
+ it "and os = linux, another_no_name_thingy6 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy6 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_no_name_thingy6 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_no_name_thingy6 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6)
+ end
+
+ it "the new resource name can be used in a recipe" do
+ recipe = converge {
+ another_thingy_name_for_another_no_name_thingy6 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6)
+ end
+ end
+
+ context "With a resource named AnotherNoNameThingy7, a new resource_name, and provides with that new resource name" do
+ before(:context) {
+
+ class AnotherNoNameThingy7 < BaseThingy
+ resource_name :another_thingy_name_for_another_no_name_thingy7
+ provides :another_thingy_name_for_another_no_name_thingy7, os: 'blarghle'
+ end
+
+ }
+
+ it "and os = linux, another_thingy_name_for_another_no_name_thingy7 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_thingy_name_for_another_no_name_thingy7 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_thingy_name_for_another_no_name_thingy7 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_thingy_name_for_another_no_name_thingy7 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy7)
+ end
+
+ it "the old resource name does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_no_name_thingy_7 'blah' do; end
+ }.to raise_error(NoMethodError)
+ end
+ end
+
+ # opposite order from the previous test (provides, then resource_name)
+ context "With a resource named AnotherNoNameThingy8, a provides with a new resource name, and resource_name with that new resource name" do
+ before(:context) {
+
+ class AnotherNoNameThingy8 < BaseThingy
+ provides :another_thingy_name_for_another_no_name_thingy8, os: 'blarghle'
+ resource_name :another_thingy_name_for_another_no_name_thingy8
+ end
+
+ }
+
+ it "and os = linux, another_thingy_name_for_another_no_name_thingy8 does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_thingy_name_for_another_no_name_thingy8 'blah' do; end
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "and os = blarghle, another_thingy_name_for_another_no_name_thingy8 works" do
+ recipe = converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'blarghle'
+ another_thingy_name_for_another_no_name_thingy8 'blah' do; end
+ }
+ expect(recipe.logged_warnings).to eq ''
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy8)
+ end
+
+ it "the old resource name does not work" do
+ expect_converge {
+ # this is an ugly way to test, make Cheffish expose node attrs
+ run_context.node.automatic[:os] = 'linux'
+ another_thingy_name8 'blah' do; end
+ }.to raise_error(NoMethodError)
+ end
end
end
end
diff --git a/spec/support/lib/chef/resource/cat.rb b/spec/support/lib/chef/resource/cat.rb
index 9bfaebf07b..efc78aa59c 100644
--- a/spec/support/lib/chef/resource/cat.rb
+++ b/spec/support/lib/chef/resource/cat.rb
@@ -19,7 +19,6 @@
class Chef
class Resource
class Cat < Chef::Resource
- use_automatic_resource_name
attr_accessor :action
diff --git a/spec/support/lib/chef/resource/one_two_three_four.rb b/spec/support/lib/chef/resource/one_two_three_four.rb
index 4543744a28..8f273a0cda 100644
--- a/spec/support/lib/chef/resource/one_two_three_four.rb
+++ b/spec/support/lib/chef/resource/one_two_three_four.rb
@@ -19,7 +19,6 @@
class Chef
class Resource
class OneTwoThreeFour < Chef::Resource
- use_automatic_resource_name
attr_reader :i_can_count
diff --git a/spec/support/lib/chef/resource/openldap_includer.rb b/spec/support/lib/chef/resource/openldap_includer.rb
index 421c95532d..6f443b4c7c 100644
--- a/spec/support/lib/chef/resource/openldap_includer.rb
+++ b/spec/support/lib/chef/resource/openldap_includer.rb
@@ -20,7 +20,6 @@
class Chef
class Resource
class OpenldapIncluder < Chef::Resource::LWRPBase
- use_automatic_resource_name
allowed_actions :run
default_action :run
end
diff --git a/spec/support/lib/chef/resource/with_state.rb b/spec/support/lib/chef/resource/with_state.rb
index efff2e7c12..773ae7ddb8 100644
--- a/spec/support/lib/chef/resource/with_state.rb
+++ b/spec/support/lib/chef/resource/with_state.rb
@@ -22,8 +22,6 @@ require 'chef/json_compat'
class Chef
class Resource
class WithState < Chef::Resource
- use_automatic_resource_name
-
attr_accessor :state
end
end
diff --git a/spec/support/lib/chef/resource/zen_follower.rb b/spec/support/lib/chef/resource/zen_follower.rb
index 90d33e6039..155e6ae729 100644
--- a/spec/support/lib/chef/resource/zen_follower.rb
+++ b/spec/support/lib/chef/resource/zen_follower.rb
@@ -21,7 +21,6 @@ require 'chef/json_compat'
class Chef
class Resource
class ZenFollower < Chef::Resource
- use_automatic_resource_name
provides :follower, platform: "zen"
diff --git a/spec/support/lib/chef/resource/zen_master.rb b/spec/support/lib/chef/resource/zen_master.rb
index 82cef0bb50..4106549d79 100644
--- a/spec/support/lib/chef/resource/zen_master.rb
+++ b/spec/support/lib/chef/resource/zen_master.rb
@@ -22,7 +22,6 @@ require 'chef/json_compat'
class Chef
class Resource
class ZenMaster < Chef::Resource
- use_automatic_resource_name
allowed_actions :win, :score
attr_reader :peace
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index 72d5cc6f63..ee98e63c1f 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -121,7 +121,6 @@ describe Chef::Recipe do
it "locate resource for particular platform" do
ShaunTheSheep = Class.new(Chef::Resource)
- ShaunTheSheep.use_automatic_resource_name
ShaunTheSheep.provides :laughter, :platform => ["television"]
node.automatic[:platform] = "television"
node.automatic[:platform_version] = "123"
@@ -132,7 +131,6 @@ describe Chef::Recipe do
it "locate a resource for all platforms" do
YourMom = Class.new(Chef::Resource)
- YourMom.use_automatic_resource_name
YourMom.provides :love_and_caring
res = recipe.love_and_caring "mommy"
expect(res.name).to eql("mommy")
@@ -143,9 +141,7 @@ describe Chef::Recipe do
before do
node.automatic[:platform] = "nbc_sports"
Sounders = Class.new(Chef::Resource)
- Sounders.use_automatic_resource_name
TottenhamHotspur = Class.new(Chef::Resource)
- TottenhamHotspur.use_automatic_resource_name
end
after do
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 1d20fcf604..8ba45d9350 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -395,20 +395,6 @@ describe Chef::Resource do
expect(r.resource_name).to eq :blah
expect(r.declared_type).to eq :d
end
- it "use_automatic_resource_name yields a resource name from the class name" do
- class SelfResourceNameTestBlahDBlah4 < Chef::Resource
- use_automatic_resource_name
- end
-
- c = SelfResourceNameTestBlahDBlah4
-
- r = c.new('hi')
- r.declared_type = :d
- expect(c.resource_name).to eq :self_resource_name_test_blah_d_blah4
- expect(r.resource_name).to eq :self_resource_name_test_blah_d_blah4
- expect(r.declared_type).to eq :d
-
- end
end
describe "is" do