Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#20548) Allow an array of resource titles to be passed into the ensure_... #152

Conversation

AlexCline
Copy link
Contributor

...resource function

This patch allows an array of resource titles to be passed into
the ensure_resource function. Each item in the array will be
checked for existence and will be created if it doesn't already
exist.

This is associated with feature request #20548

…re_resource function

This patch allows an array of resource titles to be passed into
the ensure_resource function.  Each item in the array will be
checked for existence and will be created if it doesn't already
exist.
items = title.kind_of?(Array) ? title : [].push(title)

items.each do |item|
Puppet::Parser::Functions.function(:defined_with_params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was in the original implementation, but do you know why this is being done? Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why it's being done, but if there is a better way of doing it, I'd be happy to refactor it.

@@ -37,4 +37,39 @@
).and_raise_error(Puppet::Error)
end
end

describe 'when an array of new resources are passed in' do
it do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each one of these expectations should be in a separate it block; this helps isolate test behavior. I've created a branch that provides an example of how this should be done, at https://github.com/adrienthebo/puppetlabs-stdlib/tree/maint-refactor_ensure_resource_expectations

This splits out the ensure_resource expectations into separate
blocks for clarity.  Per adrienthebo's recommendation.
Puppet::Parser::Functions.function(:create_resources)
function_create_resources([type.capitalize, { title => params }])

items = title.kind_of?(Array) ? title : [title]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another slick way to do this is: title = [title].flatten

adrienthebo added a commit that referenced this pull request May 6, 2013
…_ensure_resource

(#20548) Allow an array of resource titles to be passed into the ensure_...
@adrienthebo adrienthebo merged commit 3e59bbd into puppetlabs:master May 6, 2013
@adrienthebo
Copy link
Contributor

summary: merged into master in 3e59bbd. Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants