Support non-string types as param values
Previously boolean, hash, and array param values were not supported for defined or classes. Now, we are using inspect instead of to_s so they will be returned as the correct reprentation of their type to Puppet. Reviewed-by: Matthaus Litteken <matthaus@puppetlabs.com> Signed-off-by: Dan Bode <dan@puppetlabs.com>
This commit is contained in:
parent
7d46c1e999
commit
0888e0e4f4
|
@ -30,7 +30,7 @@ module RSpec::Puppet
|
|||
if !self.respond_to?(:params) || params == {}
|
||||
Puppet[:code] = import_str + "include #{klass_name}"
|
||||
else
|
||||
Puppet[:code] = import_str + 'class' + " { \"" + klass_name + "\": " + params.keys.map { |r| "#{r.to_s} => '#{params[r].to_s}'"
|
||||
Puppet[:code] = import_str + 'class' + " { \"" + klass_name + "\": " + params.keys.map { |r| "#{r.to_s} => #{params[r].inspect}"
|
||||
}.join(',' ) + " }"
|
||||
end
|
||||
Puppet[:code] = pre_cond + "\n" + Puppet[:code]
|
||||
|
|
|
@ -23,7 +23,7 @@ module RSpec::Puppet
|
|||
|
||||
if self.respond_to? :params
|
||||
param_str = params.keys.map { |r|
|
||||
"#{r.to_s} => \"#{params[r].to_s}\""
|
||||
"#{r.to_s} => #{params[r].inspect}"
|
||||
}.join(', ')
|
||||
else
|
||||
param_str = ""
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'boolean' do
|
||||
let(:title) { 'bool.testing' }
|
||||
let(:params) { { :bool => false } }
|
||||
|
||||
it { should create_notify("bool testing")\
|
||||
.with_message("This will print when \$bool is false.") }
|
||||
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
class boolean($bool) {
|
||||
$real_bool = $bool ? {
|
||||
true => false,
|
||||
false => true,
|
||||
}
|
||||
|
||||
if ($real_bool) {
|
||||
notify {"bool testing":
|
||||
message => "This will print when \$bool is false."
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
class sysctl::common {
|
||||
class sysctl::common ($test_param = 'yes') {
|
||||
exec { 'sysctl/reload':
|
||||
command => '/sbin/sysctl -p /etc/sysctl.conf',
|
||||
refreshonly => true,
|
||||
|
@ -16,6 +16,20 @@ define sysctl($value) {
|
|||
notify => Exec['sysctl/reload'],
|
||||
}
|
||||
}
|
||||
|
||||
class boolean($bool) {
|
||||
$real_bool = $bool ? {
|
||||
true => false,
|
||||
false => true,
|
||||
}
|
||||
|
||||
if ($real_bool) {
|
||||
notify {"bool testing":
|
||||
message => "This will print when \$bool is false."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define sysctl::before($value) {
|
||||
Class['sysctl::common'] -> Sysctl::Before[$name]
|
||||
|
||||
|
|
Loading…
Reference in New Issue