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

Can't pass undef as a param value #279

Closed
jmoldow opened this issue Apr 30, 2015 · 0 comments
Closed

Can't pass undef as a param value #279

jmoldow opened this issue Apr 30, 2015 · 0 comments
Labels

Comments

@jmoldow
Copy link
Contributor

jmoldow commented Apr 30, 2015

When testing a definition or parametrized class, it isn't possible to use let(:params) to set one of the values to Puppet's undef value.

One might try doing something like let(:params) { { :foo => nil } }, but this doesn't work. When constructing the declaration, the value is inspected to a string, which in this case is 'nil'. The resource declaration that is constructed is class { 'test': foo => nil }, which is not valid Puppet and caused an error to be raised.

Doing something like let(:params) { { :foo => :undef } } is similarly invalid. And doing something like let(:params) { { :foo => 'undef' } } leads to the resource declaration class { 'test': foo => "undef" }, which is valid but doesn't actually use the special undef value.

When nil is used as a param value, it should not be inspected, but should instead lead to the string 'undef' being used in the generated resource declaration.

Another solution, proposed at the end of [1], would be to define a special Undef class whose inspect method returns the unquoted string 'undef'. Then let(:params) { { :foo => Undef.new } } leads to the desired resource declaration class { 'test': foo => undef }.

I believe the first solution is better and more developer friendly, because it uses the Ruby native nil value and doesn't introduce any extra types that developers need to know about. And after all, Puppet undef is nearly equivalent to Ruby nil, so it makes sense to do this translation.

[1] https://groups.google.com/forum/#!topic/puppet-users/6nL2eROH8is

jmoldow added a commit to jmoldow/rspec-puppet that referenced this issue Apr 30, 2015
Now, when `nil` is used as a param value, its `inspect` method is not
called to construct the Puppet parameter value. Instead, the unquoted
string `'undef'` is used in the generated resource declaration. So now
`let(:params) { { :foo => nil } }` leads to the desired resource
declaration `class { 'test': foo => undef }`.

Puppet `undef` is nearly equivalent to Ruby `nil`, and there is no `nil`
in Puppet, so it makes sense to do this translation.

Before this change, it was impossible to pass `undef` as a parameter.
Using `nil`, `:undef`, or `'undef'` all failed for various reasons.

Credit to the discussion at [1] for identifying the issue and proposing
an alternate solution.

Fixes rodjek#279.

[1] <https://groups.google.com/forum/#!topic/puppet-users/6nL2eROH8is>
jmoldow added a commit to jmoldow/rspec-puppet that referenced this issue Apr 30, 2015
Now, when `nil` is used as a param value, its `inspect` method is not
called to construct the Puppet parameter value. Instead, the unquoted
string `'undef'` is used in the generated resource declaration. So now
`let(:params) { { :foo => nil } }` leads to the desired resource
declaration `class { 'test': foo => undef }`.

Puppet `undef` is nearly equivalent to Ruby `nil`, and there is no `nil`
in Puppet, so it makes sense to do this translation.

Before this change, it was impossible to pass `undef` as a parameter.
Using `nil`, `:undef`, or `'undef'` all failed for various reasons.

Credit to the discussion at [1] for identifying the issue and proposing
an alternate solution.

Fixes rodjek#279.

[1] <https://groups.google.com/forum/#!topic/puppet-users/6nL2eROH8is>
@DavidS DavidS added the feature label Jun 30, 2015
domcleal pushed a commit to domcleal/rspec-puppet that referenced this issue Nov 29, 2015
Now, when a symbol is used as a param value, its `inspect` method is not
called to construct the Puppet parameter value. Instead, the unquoted
string, e.g. `undef` is used in the generated resource declaration. So now
`let(:params) { { :foo => :undef } }` leads to the desired resource
declaration `class { 'test': foo => undef }`.

Before this change, it was impossible to pass `undef` as a parameter.
Using `nil`, `:undef`, or `'undef'` all failed for various reasons.

Credit to the discussion at [1] for identifying the issue and proposing
an alternate solution.

Fixes rodjek#279.

[1] <https://groups.google.com/forum/#!topic/puppet-users/6nL2eROH8is>

Adapted by Dominic Cleal from rodjek#280
to use symbols instead of nil.
domcleal pushed a commit to domcleal/rspec-puppet that referenced this issue Nov 30, 2015
Now, when a symbol is used as a param value, its `inspect` method is not
called to construct the Puppet parameter value. Instead, the unquoted
string, e.g. `undef` is used in the generated resource declaration. So now
`let(:params) { { :foo => :undef } }` leads to the desired resource
declaration `class { 'test': foo => undef }`.

Before this change, it was impossible to pass `undef` as a parameter.
Using `nil`, `:undef`, or `'undef'` all failed for various reasons.

Credit to the discussion at [1] for identifying the issue and proposing
an alternate solution.

Fixes rodjek#279.

[1] <https://groups.google.com/forum/#!topic/puppet-users/6nL2eROH8is>

Adapted by Dominic Cleal from rodjek#280
to use symbols instead of nil.
domcleal pushed a commit to domcleal/rspec-puppet that referenced this issue Dec 10, 2015
Now, when a symbol is used as a param value, its `inspect` method is not
called to construct the Puppet parameter value. Instead, the unquoted
string, e.g. `undef` is used in the generated resource declaration. So now
`let(:params) { { :foo => :undef } }` leads to the desired resource
declaration `class { 'test': foo => undef }`.

Before this change, it was impossible to pass `undef` as a parameter.
Using `nil`, `:undef`, or `'undef'` all failed for various reasons.

Credit to the discussion at [1] for identifying the issue and proposing
an alternate solution.

Fixes rodjek#279.

[1] <https://groups.google.com/forum/#!topic/puppet-users/6nL2eROH8is>

Adapted by Dominic Cleal from rodjek#280
to use symbols instead of nil.
jmoldow added a commit to jmoldow/rspec-puppet that referenced this issue Dec 13, 2019
Now, when `nil` is used as a param value, its `inspect` method is not
called to construct the Puppet parameter value. Instead, the unquoted
string `'undef'` is used in the generated resource declaration. So now
`let(:params) { { :foo => nil } }` leads to the desired resource
declaration `class { 'test': foo => undef }`.

Puppet `undef` is nearly equivalent to Ruby `nil`, and there is no `nil`
in Puppet, so it makes sense to do this translation.

Before this change, it was impossible to pass `undef` as a parameter.
Using `nil`, `:undef`, or `'undef'` all failed for various reasons.

Credit to the discussion at [1] for identifying the issue and proposing
an alternate solution.

Fixes rodjek#279.

[1] <https://groups.google.com/forum/#!topic/puppet-users/6nL2eROH8is>
thejambavan added a commit to thejambavan/puppet-redis that referenced this issue Nov 16, 2023
thejambavan added a commit to thejambavan/puppet-redis that referenced this issue Nov 16, 2023
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 a pull request may close this issue.

2 participants