poise 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Berksfile.lock +1 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +5 -1
- data/lib/poise/helpers.rb +1 -0
- data/lib/poise/helpers/chefspec_matchers.rb +2 -2
- data/lib/poise/helpers/inversion.rb +2 -2
- data/lib/poise/helpers/lwrp_polyfill.rb +16 -9
- data/lib/poise/helpers/resource_cloning.rb +72 -0
- data/lib/poise/helpers/resource_name.rb +12 -6
- data/lib/poise/helpers/subcontext_block.rb +13 -1
- data/lib/poise/helpers/subresources/child.rb +23 -17
- data/lib/poise/helpers/subresources/container.rb +2 -0
- data/lib/poise/resource.rb +1 -0
- data/lib/poise/version.rb +1 -1
- data/test/spec/helpers/lazy_default_spec.rb +1 -1
- data/test/spec/helpers/lwrp_polyfill_spec.rb +7 -3
- data/test/spec/helpers/notifying_block_spec.rb +39 -0
- data/test/spec/helpers/resource_cloning_spec.rb +56 -0
- data/test/spec/helpers/subresources/child_spec.rb +31 -0
- data/test/spec/helpers/{template_context_spec.rb → template_content_spec.rb} +0 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 805b189d8f29b6d7fcdcd5e189a24e525a755f96
|
4
|
+
data.tar.gz: ae33e8ec60d4d947811f35211ce3eecc69712dd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb2351eab975e312a23c039dd12c3b18dd4fc76307cb08c92d10702e317d935fa515d7928e0733188b03be2157779d1be8adf74c62f7f13f766927e96db726c8
|
7
|
+
data.tar.gz: dedd4fe5fdb0f15f0eb50402309ad51513b9663fd38c13dddbdb4891cbb62396d0d04c25201571769531aa638dc87ab7527dbd7a13e05bc2acc6f68f1601dd48
|
data/Berksfile.lock
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v2.2.0
|
4
|
+
|
5
|
+
* Compatibility with Chef 12.4.1 and Chefspec 4.3.0.
|
6
|
+
* New helper `ResourceCloning`: Disables resource cloning between Poise-based
|
7
|
+
resources. This is enabled by default.
|
8
|
+
* Subresource parent references can be set to nil.
|
9
|
+
|
3
10
|
## v2.1.0
|
4
11
|
|
5
12
|
* Compatibility with Chef 12.4.
|
data/Gemfile
CHANGED
@@ -18,12 +18,16 @@ source 'https://rubygems.org/'
|
|
18
18
|
|
19
19
|
gemspec path: File.expand_path('..', __FILE__)
|
20
20
|
|
21
|
-
def dev_gem(name, path: File.join('..', name))
|
21
|
+
def dev_gem(name, path: File.join('..', name), github: nil)
|
22
22
|
path = File.expand_path(File.join('..', path), __FILE__)
|
23
23
|
if File.exist?(path)
|
24
24
|
gem name, path: path
|
25
|
+
elsif github
|
26
|
+
gem name, github: github
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
dev_gem 'halite'
|
29
31
|
dev_gem 'poise-boiler'
|
32
|
+
|
33
|
+
gem 'kitchen-docker', github: 'portertech/kitchen-docker'
|
data/lib/poise/helpers.rb
CHANGED
@@ -26,6 +26,7 @@ module Poise
|
|
26
26
|
autoload :LWRPPolyfill, 'poise/helpers/lwrp_polyfill'
|
27
27
|
autoload :NotifyingBlock, 'poise/helpers/notifying_block'
|
28
28
|
autoload :OptionCollector, 'poise/helpers/option_collector'
|
29
|
+
autoload :ResourceCloning, 'poise/helpers/resource_cloning'
|
29
30
|
autoload :ResourceName, 'poise/helpers/resource_name'
|
30
31
|
autoload :Subresources, 'poise/helpers/subresources'
|
31
32
|
autoload :TemplateContent, 'poise/helpers/template_content'
|
@@ -60,9 +60,9 @@ module Poise
|
|
60
60
|
# Create a resource-level matcher for this resource.
|
61
61
|
#
|
62
62
|
# @see Resource::ResourceName.provides
|
63
|
-
def provides(name)
|
63
|
+
def provides(name, *args, &block)
|
64
64
|
ChefSpec.define_matcher(name) if defined?(ChefSpec)
|
65
|
-
super
|
65
|
+
super(name, *args, &block)
|
66
66
|
end
|
67
67
|
|
68
68
|
# Create matchers for all declared actions.
|
@@ -134,9 +134,9 @@ module Poise
|
|
134
134
|
#
|
135
135
|
# @param name [Symbol] Resource name
|
136
136
|
# return [void]
|
137
|
-
def provides(name)
|
137
|
+
def provides(name, *args, &block)
|
138
138
|
create_inversion_options_resource!(name) if inversion_options_resource
|
139
|
-
super if defined?(super)
|
139
|
+
super(name, *args, &block) if defined?(super)
|
140
140
|
end
|
141
141
|
|
142
142
|
def included(klass)
|
@@ -32,8 +32,9 @@ module Poise
|
|
32
32
|
module Resource
|
33
33
|
def initialize(*args)
|
34
34
|
super
|
35
|
-
# Try to not stomp on stuff if already set in a parent.
|
36
|
-
|
35
|
+
# Try to not stomp on stuff if already set in a parent. Coerce @action
|
36
|
+
# to an array because this behavior may change in the future in Chef.
|
37
|
+
@action = self.class.default_action if Array(@action) == [:nothing]
|
37
38
|
(@allowed_actions << self.class.actions).flatten!.uniq!
|
38
39
|
end
|
39
40
|
|
@@ -42,14 +43,14 @@ module Poise
|
|
42
43
|
# Get the default action for this resource class. If no explicit
|
43
44
|
# default is set, the first action in the list will be used.
|
44
45
|
# @see #actions
|
45
|
-
# @return [Symbol]
|
46
|
+
# @return [Array<Symbol>]
|
46
47
|
# @overload default_action(name)
|
47
48
|
# Set the default action for this resource class. If this action is
|
48
49
|
# not already allowed, it will be added.
|
49
50
|
# @note It is idiomatic to use {#actions} instead, with the first
|
50
51
|
# action specified being the default.
|
51
|
-
# @param name [Symbol] Name of the action.
|
52
|
-
# @return [Symbol]
|
52
|
+
# @param name [Symbol, Array<Symbol>] Name of the action(s).
|
53
|
+
# @return [Array<Symbol>]
|
53
54
|
# @example
|
54
55
|
# class MyApp < Chef::Resource
|
55
56
|
# include Poise
|
@@ -57,10 +58,11 @@ module Poise
|
|
57
58
|
# end
|
58
59
|
def default_action(name=nil)
|
59
60
|
if name
|
61
|
+
name = Array(name).flatten.map(&:to_sym)
|
60
62
|
@default_action = name
|
61
|
-
actions(name)
|
63
|
+
actions(*name)
|
62
64
|
end
|
63
|
-
@default_action || ( respond_to?(:superclass) && superclass != Chef::Resource && superclass.respond_to?(:default_action) && superclass.default_action ) || actions.first || :nothing
|
65
|
+
@default_action || ( respond_to?(:superclass) && superclass != Chef::Resource && superclass.respond_to?(:default_action) && superclass.default_action ) || (actions.first && [actions.first]) || [:nothing]
|
64
66
|
end
|
65
67
|
|
66
68
|
# @overload actions()
|
@@ -79,8 +81,7 @@ module Poise
|
|
79
81
|
# end
|
80
82
|
def actions(*names)
|
81
83
|
@actions ||= ( respond_to?(:superclass) && superclass.respond_to?(:actions) && superclass.actions.dup ) || ( respond_to?(:superclass) && superclass != Chef::Resource && superclass.respond_to?(:allowed_actions) && superclass.allowed_actions.dup ) || []
|
82
|
-
(@actions << names).flatten
|
83
|
-
@actions
|
84
|
+
(@actions << names).tap {|actions| actions.flatten!; actions.uniq! }
|
84
85
|
end
|
85
86
|
|
86
87
|
# Create a resource property (née attribute) on this resource class.
|
@@ -130,6 +131,12 @@ module Poise
|
|
130
131
|
if klass.is_a?(Class) && klass.superclass == Chef::Provider
|
131
132
|
klass.class_exec do
|
132
133
|
def load_current_resource
|
134
|
+
@current_resource = if new_resource
|
135
|
+
new_resource.class.new(new_resource.name, run_context)
|
136
|
+
else
|
137
|
+
# Better than nothing, subclass can overwrite anyway.
|
138
|
+
Chef::Resource.new(nil, run_context)
|
139
|
+
end
|
133
140
|
end
|
134
141
|
end
|
135
142
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2013-2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
|
18
|
+
module Poise
|
19
|
+
module Helpers
|
20
|
+
# A resource mixin to disable resource cloning.
|
21
|
+
#
|
22
|
+
# @since 2.2.0
|
23
|
+
# @example
|
24
|
+
# class MyResource < Chef::Resource
|
25
|
+
# include Poise::Helpers::ResourceCloning
|
26
|
+
# end
|
27
|
+
module ResourceCloning
|
28
|
+
# Override to disable resource cloning on Chef 12.0.
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
def load_prior_resource(*args)
|
32
|
+
# Do nothing.
|
33
|
+
end
|
34
|
+
|
35
|
+
# Override to disable resource cloning on Chef 12.1+.
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
def load_from(*args)
|
39
|
+
# Do nothing.
|
40
|
+
end
|
41
|
+
|
42
|
+
# Monkeypatch for Chef::ResourceBuilder to silence the warning if needed.
|
43
|
+
#
|
44
|
+
# @api private
|
45
|
+
module ResourceBuilderPatch
|
46
|
+
# @api private
|
47
|
+
def self.install!
|
48
|
+
begin
|
49
|
+
require 'chef/resource_builder'
|
50
|
+
Chef::ResourceBuilder.send(:prepend, ResourceBuilderPatch)
|
51
|
+
rescue LoadError
|
52
|
+
# For 12.0, this is already taken care of.
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @api private
|
57
|
+
def emit_cloned_resource_warning
|
58
|
+
super unless resource.is_a?(ResourceCloning)
|
59
|
+
end
|
60
|
+
|
61
|
+
# @api private
|
62
|
+
def emit_harmless_cloning_debug
|
63
|
+
super unless resource.is_a?(ResourceCloning)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Install the patch.
|
68
|
+
ResourceBuilderPatch.install!
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -51,7 +51,7 @@ module Poise
|
|
51
51
|
# include Poise::Resource::ResourceName
|
52
52
|
# provides(:my_resource)
|
53
53
|
# end
|
54
|
-
def provides(name)
|
54
|
+
def provides(name, *args, &block)
|
55
55
|
# Patch self.constantize so this can cope with anonymous classes.
|
56
56
|
# This does require that the anonymous class define self.name though.
|
57
57
|
if self.name && respond_to?(:constantize)
|
@@ -63,7 +63,7 @@ module Poise
|
|
63
63
|
# Store the name for later.
|
64
64
|
@provides_name = name
|
65
65
|
# Call the original if present. The defined? is for old Chef.
|
66
|
-
super if defined?(super)
|
66
|
+
super(name, *args, &block) if defined?(super)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Retreive the DSL name for the resource class. If not set explicitly
|
@@ -75,10 +75,16 @@ module Poise
|
|
75
75
|
# In 12.4+ we need to proxy through the super class for setting.
|
76
76
|
return super(auto) if defined?(super) && (auto.is_a?(Symbol) || auto.is_a?(String))
|
77
77
|
return @provides_name unless auto
|
78
|
-
@provides_name || if name
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
@provides_name || if name
|
79
|
+
mode = if name.start_with?('Chef::Resource')
|
80
|
+
[name, 'Chef::Resource']
|
81
|
+
else
|
82
|
+
[name.split('::').last]
|
83
|
+
end
|
84
|
+
Chef::Mixin::ConvertToClassName.convert_to_snake_case(*mode).to_sym
|
85
|
+
elsif defined?(super)
|
86
|
+
# No name on 12.4+ probably means this is an LWRP, use super().
|
87
|
+
super()
|
82
88
|
end
|
83
89
|
end
|
84
90
|
|
@@ -27,9 +27,21 @@ module Poise
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def subcontext_block(parent_context=nil, &block)
|
30
|
-
# Setup a
|
30
|
+
# Setup a subcontext.
|
31
31
|
parent_context ||= @run_context
|
32
32
|
sub_run_context = parent_context.dup
|
33
|
+
# Reset state for the subcontext. In 12.4+ this uses the built-in
|
34
|
+
# support, otherwise do it manually.
|
35
|
+
if defined?(sub_run_context.initialize_child_state)
|
36
|
+
sub_run_context.initialize_child_state
|
37
|
+
else
|
38
|
+
# Audits was added in 12.1 I thin.
|
39
|
+
sub_run_context.audits = {} if defined?(sub_run_context.audits)
|
40
|
+
# Dup and clear to preserve the default behavior without copy-pasta.
|
41
|
+
sub_run_context.immediate_notification_collection = parent_context.immediate_notification_collection.dup.clear
|
42
|
+
sub_run_context.delayed_notification_collection = parent_context.delayed_notification_collection.dup.clear
|
43
|
+
end
|
44
|
+
# Create the subcollection.
|
33
45
|
sub_run_context.resource_collection = Poise::Subcontext::ResourceCollection.new(parent_context.resource_collection)
|
34
46
|
|
35
47
|
# Declare sub-resources within the sub-run-context. Since they
|
@@ -56,8 +56,8 @@ module Poise
|
|
56
56
|
# string), or a type:name hash.
|
57
57
|
# @param val [String, Hash, Chef::Resource] Parent resource to set.
|
58
58
|
# @return [Chef::Resource, nil]
|
59
|
-
def parent(
|
60
|
-
_parent(:parent, self.class.parent_type, self.class.parent_optional, self.class.parent_auto,
|
59
|
+
def parent(*args)
|
60
|
+
_parent(:parent, self.class.parent_type, self.class.parent_optional, self.class.parent_auto, *args)
|
61
61
|
end
|
62
62
|
|
63
63
|
# Register ourself with parents in case this is not a nested resource.
|
@@ -77,28 +77,34 @@ module Poise
|
|
77
77
|
#
|
78
78
|
# @since 2.0.0
|
79
79
|
# @see #parent
|
80
|
-
def _parent(name, parent_type, parent_optional, parent_auto,
|
80
|
+
def _parent(name, parent_type, parent_optional, parent_auto, *args)
|
81
81
|
# Allow using a DSL symbol as the parent type.
|
82
82
|
if parent_type.is_a?(Symbol)
|
83
83
|
parent_type = Chef::Resource.resource_for_node(parent_type, node)
|
84
84
|
end
|
85
85
|
# Grab the ivar for local use.
|
86
86
|
parent_ref = instance_variable_get(:"@#{name}")
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if val.is_a?(String) || val.is_a?(Hash)
|
93
|
-
parent = @run_context.resource_collection.find(val)
|
87
|
+
if !args.empty?
|
88
|
+
val = args.first
|
89
|
+
if val.nil?
|
90
|
+
# Unsetting the parent.
|
91
|
+
parent = nil
|
94
92
|
else
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
93
|
+
if val.is_a?(String) && !val.include?('[')
|
94
|
+
raise Poise::Error.new('Cannot use a string parent without defining a parent type') if parent_type == Chef::Resource
|
95
|
+
val = "#{parent_type.resource_name}[#{val}]"
|
96
|
+
end
|
97
|
+
if val.is_a?(String) || val.is_a?(Hash)
|
98
|
+
parent = @run_context.resource_collection.find(val)
|
99
|
+
else
|
100
|
+
parent = val
|
101
|
+
end
|
102
|
+
if !parent.is_a?(parent_type)
|
103
|
+
raise Poise::Error.new("Parent resource is not an instance of #{parent_type.name}: #{val.inspect}")
|
104
|
+
end
|
99
105
|
end
|
100
106
|
parent_ref = ParentRef.new(parent)
|
101
|
-
elsif !parent_ref
|
107
|
+
elsif !parent_ref || !parent_ref.resource
|
102
108
|
if parent_auto
|
103
109
|
# Automatic sibling lookup for sequential composition.
|
104
110
|
# Find the last instance of the parent class as the default parent.
|
@@ -181,8 +187,8 @@ module Poise
|
|
181
187
|
def parent_attribute(name, type: Chef::Resource, optional: false, auto: true)
|
182
188
|
name = :"parent_#{name}"
|
183
189
|
(@parent_attributes ||= {})[name] = type
|
184
|
-
define_method(name) do |
|
185
|
-
_parent(name, type, optional, auto,
|
190
|
+
define_method(name) do |*args|
|
191
|
+
_parent(name, type, optional, auto, *args)
|
186
192
|
end
|
187
193
|
end
|
188
194
|
|
@@ -56,7 +56,9 @@ module Poise
|
|
56
56
|
# we need to jump through some hoops to get it swapped into place.
|
57
57
|
self_ = self
|
58
58
|
order_fixer = Chef::Resource::RubyBlock.new('subresource_order_fixer', @run_context)
|
59
|
+
order_fixer.declared_type = 'ruby_block'
|
59
60
|
order_fixer.block do
|
61
|
+
Chef::Log.debug("[#{self_}] Running order fixer")
|
60
62
|
collection = self_.run_context.resource_collection
|
61
63
|
# Delete the current container resource from its current position.
|
62
64
|
collection.all_resources.delete(self_)
|
data/lib/poise/resource.rb
CHANGED
@@ -37,6 +37,7 @@ module Poise
|
|
37
37
|
include Poise::Helpers::LazyDefault if Poise::Helpers::LazyDefault.needs_polyfill?
|
38
38
|
include Poise::Helpers::LWRPPolyfill
|
39
39
|
include Poise::Helpers::OptionCollector
|
40
|
+
include Poise::Helpers::ResourceCloning
|
40
41
|
include Poise::Helpers::ResourceName
|
41
42
|
include Poise::Helpers::TemplateContent
|
42
43
|
|
data/lib/poise/version.rb
CHANGED
@@ -48,7 +48,7 @@ describe Poise::Helpers::LazyDefault do
|
|
48
48
|
poise_sub 'test'
|
49
49
|
end
|
50
50
|
|
51
|
-
it { is_expected.to
|
51
|
+
it { is_expected.to run_poise_sub('test').with(value: 'test_lazy') }
|
52
52
|
end # /context in a subclass
|
53
53
|
|
54
54
|
context 'with an external global' do
|
@@ -107,25 +107,29 @@ describe Poise::Helpers::LWRPPolyfill do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it { is_expected.to one_poise_test('test') }
|
110
|
+
it { expect(resource(:poise_test).default_action).to eq [:one] }
|
110
111
|
end # /describe #default_action
|
111
112
|
end # /describe Poise::Helpers::LWRPPolyfill::Resource
|
112
113
|
|
113
114
|
describe Poise::Helpers::LWRPPolyfill::Provider do
|
114
115
|
describe 'load_current_resource override' do
|
115
|
-
|
116
|
+
resource(:poise_test)
|
117
|
+
let(:test_resource) { resource(:poise_test).new('test', nil) }
|
118
|
+
subject { provider(:poise_test).new(test_resource, nil).load_current_resource }
|
116
119
|
|
117
120
|
context 'with a direct Provider subclass' do
|
118
121
|
provider(:poise_test, auto: false) do
|
119
122
|
include described_class
|
120
123
|
end
|
121
124
|
|
122
|
-
it { is_expected.to
|
125
|
+
it { is_expected.to be_a resource(:poise_test) }
|
126
|
+
its(:name) { is_expected.to eq 'test' }
|
123
127
|
end # /context with a direct Provider subclass
|
124
128
|
|
125
129
|
context 'with an intermediary class' do
|
126
130
|
provider(:poise_parent, auto: false) do
|
127
131
|
def load_current_resource
|
128
|
-
'helper'
|
132
|
+
@current_resource = 'helper'
|
129
133
|
end
|
130
134
|
end
|
131
135
|
provider(:poise_test, auto: false, parent: :poise_parent) do
|
@@ -84,4 +84,43 @@ describe Poise::Helpers::NotifyingBlock do
|
|
84
84
|
|
85
85
|
it { expect { subject }.to raise_error(RuntimeError) }
|
86
86
|
end # /context with an exception raised inside the block
|
87
|
+
|
88
|
+
describe 'regression test for picking up sibling notifications outside the subcontext for resources with matching name' do
|
89
|
+
resource(:poise_inner) do
|
90
|
+
include Poise::Helpers::ResourceCloning
|
91
|
+
attr_accessor :mark_updated
|
92
|
+
end
|
93
|
+
provider(:poise_inner) do
|
94
|
+
def action_run
|
95
|
+
new_resource.updated_by_last_action(new_resource.mark_updated)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
provider(:poise_test) do
|
99
|
+
include Poise::Helpers::LWRPPolyfill
|
100
|
+
include described_class
|
101
|
+
|
102
|
+
def action_run
|
103
|
+
notifying_block do
|
104
|
+
poise_inner 'test' do
|
105
|
+
self.mark_updated = true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
recipe do
|
111
|
+
ruby_block 'test' do
|
112
|
+
block { }
|
113
|
+
action :nothing
|
114
|
+
end
|
115
|
+
|
116
|
+
poise_inner 'test' do
|
117
|
+
self.mark_updated = false
|
118
|
+
notifies :run, 'ruby_block[test]', :immediately
|
119
|
+
end
|
120
|
+
|
121
|
+
poise_test 'test'
|
122
|
+
end
|
123
|
+
|
124
|
+
it { is_expected.to_not run_ruby_block('test') }
|
125
|
+
end # /describe regression test for picking up sibling notifications outside the subcontext for resources with matching name
|
87
126
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe Poise::Helpers::ResourceCloning do
|
20
|
+
resource(:poise_test) do
|
21
|
+
def value(*args)
|
22
|
+
set_or_return(:value, *args, {})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
provider(:poise_test)
|
26
|
+
recipe do
|
27
|
+
poise_test 'test' do
|
28
|
+
value 1
|
29
|
+
end
|
30
|
+
|
31
|
+
poise_test 'test' do
|
32
|
+
value 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with a resource that should be cloned' do
|
37
|
+
# Baseline to make sure my test harness works.
|
38
|
+
it do
|
39
|
+
expect(Chef::Log).to receive(:warn).exactly(3).times
|
40
|
+
run_chef
|
41
|
+
end
|
42
|
+
end # /context with a resource that should be cloned
|
43
|
+
|
44
|
+
context 'a resource using the helper' do
|
45
|
+
resource(:poise_test) do
|
46
|
+
include described_class
|
47
|
+
def value(*args)
|
48
|
+
set_or_return(:value, *args, {})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
it do
|
52
|
+
expect(Chef::Log).to_not receive(:warn)
|
53
|
+
run_chef
|
54
|
+
end
|
55
|
+
end # /context a resource using the helper
|
56
|
+
end
|
@@ -169,6 +169,37 @@ describe Poise::Helpers::Subresources::Child do
|
|
169
169
|
|
170
170
|
it { is_expected.to run_poise_test('test').with(parent: be_nil) }
|
171
171
|
end # /context with no automatic parent but optional
|
172
|
+
|
173
|
+
context 'with a parent but then unset' do
|
174
|
+
recipe do
|
175
|
+
poise_container 'test2'
|
176
|
+
poise_container 'test'
|
177
|
+
poise_test 'test' do
|
178
|
+
parent 'test2'
|
179
|
+
parent nil
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it { is_expected.to run_poise_test('test').with(parent: container) }
|
184
|
+
end # context with a parent but then unset
|
185
|
+
|
186
|
+
context 'with an optional parent but then unset' do
|
187
|
+
resource(:poise_test) do
|
188
|
+
include described_class
|
189
|
+
parent_type :poise_container
|
190
|
+
parent_optional true
|
191
|
+
parent_auto false
|
192
|
+
end
|
193
|
+
recipe do
|
194
|
+
poise_container 'test'
|
195
|
+
poise_test 'test' do
|
196
|
+
parent 'test'
|
197
|
+
parent nil
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it { is_expected.to run_poise_test('test').with(parent: nil) }
|
202
|
+
end # context with an optional parent but then unset
|
172
203
|
end # /describe #parent
|
173
204
|
|
174
205
|
describe '.parent_type' do
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Kantrowitz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: halite
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/poise/helpers/lwrp_polyfill.rb
|
73
73
|
- lib/poise/helpers/notifying_block.rb
|
74
74
|
- lib/poise/helpers/option_collector.rb
|
75
|
+
- lib/poise/helpers/resource_cloning.rb
|
75
76
|
- lib/poise/helpers/resource_name.rb
|
76
77
|
- lib/poise/helpers/subcontext_block.rb
|
77
78
|
- lib/poise/helpers/subresources.rb
|
@@ -115,11 +116,12 @@ files:
|
|
115
116
|
- test/spec/helpers/lwrp_polyfill_spec.rb
|
116
117
|
- test/spec/helpers/notifying_block_spec.rb
|
117
118
|
- test/spec/helpers/option_collector_spec.rb
|
119
|
+
- test/spec/helpers/resource_cloning_spec.rb
|
118
120
|
- test/spec/helpers/resource_name_spec.rb
|
119
121
|
- test/spec/helpers/subcontext_block_spec.rb
|
120
122
|
- test/spec/helpers/subresources/child_spec.rb
|
121
123
|
- test/spec/helpers/subresources/container_spec.rb
|
122
|
-
- test/spec/helpers/
|
124
|
+
- test/spec/helpers/template_content_spec.rb
|
123
125
|
- test/spec/poise_spec.rb
|
124
126
|
- test/spec/provider_spec.rb
|
125
127
|
- test/spec/resource_spec.rb
|
@@ -178,11 +180,12 @@ test_files:
|
|
178
180
|
- test/spec/helpers/lwrp_polyfill_spec.rb
|
179
181
|
- test/spec/helpers/notifying_block_spec.rb
|
180
182
|
- test/spec/helpers/option_collector_spec.rb
|
183
|
+
- test/spec/helpers/resource_cloning_spec.rb
|
181
184
|
- test/spec/helpers/resource_name_spec.rb
|
182
185
|
- test/spec/helpers/subcontext_block_spec.rb
|
183
186
|
- test/spec/helpers/subresources/child_spec.rb
|
184
187
|
- test/spec/helpers/subresources/container_spec.rb
|
185
|
-
- test/spec/helpers/
|
188
|
+
- test/spec/helpers/template_content_spec.rb
|
186
189
|
- test/spec/poise_spec.rb
|
187
190
|
- test/spec/provider_spec.rb
|
188
191
|
- test/spec/resource_spec.rb
|