forked from rodjek/rspec-puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow undef parameter passing with nil
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>
- Loading branch information
Showing
6 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
|
||
describe 'test_undef' do | ||
it { should compile.with_all_deps } | ||
|
||
shared_examples 'exec echo' do | ||
it { should contain_exec('/bin/echo foo').with_user(nil) } | ||
end | ||
|
||
context 'with user => nil' do | ||
let(:params) { { :user => nil } } | ||
include_examples 'exec echo' | ||
end | ||
|
||
context 'with params unset' do | ||
include_examples 'exec echo' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
describe 'test_undef::def' do | ||
let(:title) { '/bin/echo foo' } | ||
|
||
it { should compile.with_all_deps } | ||
|
||
shared_examples 'exec echo' do | ||
it { should contain_exec('/bin/echo foo').with_user(nil) } | ||
end | ||
|
||
context 'with user => nil' do | ||
let(:params) { { :user => nil } } | ||
include_examples 'exec echo' | ||
end | ||
|
||
context 'with params unset' do | ||
include_examples 'exec echo' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define test_undef::def($user = undef) { | ||
exec { '/bin/echo foo' : | ||
user => $user, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class test_undef($user = undef) { | ||
exec { '/bin/echo foo': | ||
user => $user, | ||
} | ||
} |