commit
6d6c990f08
|
@ -21,12 +21,19 @@ module RSpec::Puppet
|
|||
import_str = ""
|
||||
end
|
||||
|
||||
if self.respond_to? :pre_condition
|
||||
pre_cond = pre_condition
|
||||
else
|
||||
pre_cond = ''
|
||||
end
|
||||
|
||||
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}'"
|
||||
}.join(', ') + " }"
|
||||
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]
|
||||
|
||||
nodename = self.respond_to?(:node) ? node : Puppet[:certname]
|
||||
facts_val = self.respond_to?(:facts) ? facts : {}
|
||||
|
|
|
@ -23,13 +23,19 @@ 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 = ""
|
||||
end
|
||||
|
||||
Puppet[:code] = import_str + define_name + " { \"" + title + "\": " + param_str + " }"
|
||||
if self.respond_to? :pre_condition
|
||||
pre_cond = pre_condition
|
||||
else
|
||||
pre_cond = ""
|
||||
end
|
||||
|
||||
Puppet[:code] = pre_cond + "\n" + import_str + define_name + " { \"" + title + "\": " + param_str + " }"
|
||||
|
||||
nodename = self.respond_to?(:node) ? node : Puppet[:certname]
|
||||
facts_val = {
|
||||
|
|
|
@ -15,7 +15,7 @@ module RSpec::Puppet
|
|||
ret = false
|
||||
end
|
||||
|
||||
if @expected_params
|
||||
if @expected_params and resources.length != 0
|
||||
@expected_params.each do |name, value|
|
||||
unless resources.first.send(:parameters)[name.to_sym] == value
|
||||
ret = false
|
||||
|
|
|
@ -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
|
|
@ -5,3 +5,10 @@ describe 'sysctl::common' do
|
|||
.with_command('/sbin/sysctl -p /etc/sysctl.conf').with_returns([0, 2]) }
|
||||
it { should_not create_augeas('foo') }
|
||||
end
|
||||
|
||||
describe 'sysctl::common' do
|
||||
let(:params) { { :test_param => "yes" } }
|
||||
|
||||
it { should create_class("sysctl::common")\
|
||||
.with_test_param("yes") }
|
||||
end
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'sysctl::before' do
|
||||
let(:title) { 'sysctl::before' }
|
||||
let(:params) { { :value => "title" } }
|
||||
|
||||
it "Should raise an error about needing the sysctl::common class" do
|
||||
expect { should create_notify("message-title")\
|
||||
.with_message("This should print if the class is here first.") }\
|
||||
.to raise_error(Puppet::Error, /Could not find resource 'Class\[Sysctl::Common\]/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'sysctl::before' do
|
||||
let(:title) { 'test define' }
|
||||
let(:pre_condition) { 'class {"sysctl::common":}' }
|
||||
let(:params) { { :value => "title" } }
|
||||
|
||||
it { should create_resource("sysctl::before", 'test define')\
|
||||
.with_param(:value, "title") }
|
||||
|
||||
it { should include_class("sysctl::common") }
|
||||
|
||||
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,3 +16,24 @@ 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]
|
||||
|
||||
notify {"message-${name}":
|
||||
message => "This should print if the class is here first."
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue