Skip to content

Commit

Permalink
fix #208 Apply Notification "users" and "user_groups" as variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz committed Jan 24, 2017
1 parent edea244 commit 0514554
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 51 deletions.
4 changes: 2 additions & 2 deletions manifests/object/notification.pp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@

validate_string ($host_name)
if $service_name { validate_string ($service_name)}
if $users { validate_array ($users )}
if $user_groups { validate_array ($user_groups )}
if !is_array($users) { validate_string($users) }
if !is_string($users) { validate_array($users) }
if $times { validate_hash ($times )}
if $command { validate_string ($command )}
if $interval { validate_integer ($interval )}
Expand Down
104 changes: 55 additions & 49 deletions spec/defines/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
end

context "#{os} with all defaults and target => /bar/baz" do
let(:params) { {:target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:target => '/bar/baz'} }

it { is_expected.to contain_concat('/bar/baz') }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
.with_content(/object Notification "bar"/)
.with_content(/host_name = "foohost"/)}
.with_content(/object Notification "bar"/) }

it { is_expected.to contain_icinga2__object('icinga2::object::Notification::bar')
.that_notifies('Class[icinga2::service]') }
Expand All @@ -45,7 +44,7 @@


context "#{os} with service_name => foo" do
let(:params) { {:service_name => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:service_name => 'foo', :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
Expand All @@ -54,7 +53,7 @@


context "#{os} with vars => { foo => 'bar', bar => 'foo' }" do
let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz', :host_name => 'foohost' } }
let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({ 'target' => '/bar/baz' })
Expand All @@ -64,39 +63,43 @@


context "#{os} with users => [foo, bar]" do
let(:params) { {:users => ['foo','bar'], :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:users => ['foo','bar'], :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
.with_content(/users = \[ "foo", "bar", \]/) }
end


context "#{os} with users => foo (not a valid array)" do
let(:params) { {:users => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
context "#{os} with users => host.vars.notification.mail.users" do
let(:params) { {:users => 'host.vars.notification.mail.users', :target => '/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
.with_content(/users = host\.vars\.notification\.mail\.users/) }
end


context "#{os} with user_groups => [foo, bar]" do
let(:params) { {:user_groups => ['foo','bar'], :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:user_groups => ['foo','bar'], :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
.with_content(/user_groups = \[ "foo", "bar", \]/) }
end


context "#{os} with user_groups => foo (not a valid array)" do
let(:params) { {:user_groups => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
context "#{os} with user_groups => host.vars.notification.mail.groups" do
let(:params) { {:user_groups => 'host.vars.notification.mail.groups', :target => '/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
.with_content(/user_groups = host\.vars\.notification\.mail\.groups/) }
end


context "#{os} with times => { foo => 'bar', bar => 'foo' }" do
let(:params) { {:times => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz', :host_name => 'foohost' } }
let(:params) { {:times => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({ 'target' => '/bar/baz' })
Expand All @@ -105,14 +108,14 @@


context "#{os} with times => 'foo' (not a valid hash)" do
let(:params) { {:times => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:times => 'foo', :target => '/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) }
end


context "#{os} with command => foo" do
let(:params) { {:command => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:command => 'foo', :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
Expand All @@ -121,7 +124,7 @@


context "#{os} with interval => 30" do
let(:params) { {:interval => '30', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:interval => '30', :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
Expand All @@ -130,14 +133,14 @@


context "#{os} with interval => foo (not a valid integer)" do
let(:params) { {:interval => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:interval => 'foo', :target => '/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) }
end


context "#{os} with period => foo" do
let(:params) { {:period => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:period => 'foo', :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
Expand All @@ -146,7 +149,7 @@


context "#{os} with zone => foo" do
let(:params) { {:zone => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:zone => 'foo', :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
Expand All @@ -155,7 +158,7 @@


context "#{os} with types => [foo, bar]" do
let(:params) { {:types => ['foo','bar'], :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:types => ['foo','bar'], :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
Expand All @@ -164,14 +167,14 @@


context "#{os} with types => foo (not a valid array)" do
let(:params) { {:types => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:types => 'foo', :target => '/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
end


context "#{os} with states => [foo, bar]" do
let(:params) { {:states => ['foo','bar'], :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:states => ['foo','bar'], :target => '/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => '/bar/baz'})
Expand All @@ -180,7 +183,7 @@


context "#{os} with states => foo (not a valid array)" do
let(:params) { {:states => 'foo', :target => '/bar/baz', :host_name => 'foohost'} }
let(:params) { {:states => 'foo', :target => '/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
end
Expand Down Expand Up @@ -218,14 +221,13 @@


context "Windows 2012 R2 with all defaults and target => C:/bar/baz" do
let(:params) { {:target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:target => 'C:/bar/baz'} }

it { is_expected.to contain_concat('C:/bar/baz') }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
.with_content(/object Notification "bar"/)
.with_content(/host_name = "foohost"/)}
.with_content(/object Notification "bar"/) }

it { is_expected.to contain_icinga2__object('icinga2::object::Notification::bar')
.that_notifies('Class[icinga2::service]') }
Expand All @@ -251,7 +253,7 @@


context "Windows 2012 R2 with service_name => foo" do
let(:params) { {:service_name => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:service_name => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
Expand All @@ -260,7 +262,7 @@


context "Windows 2012 R2 with vars => { foo => 'bar', bar => 'foo' }" do
let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz', :host_name => 'foohost' } }
let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({ 'target' => 'C:/bar/baz' })
Expand All @@ -270,39 +272,43 @@


context "Windows 2012 R2 with users => [foo, bar]" do
let(:params) { {:users => ['foo','bar'], :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:users => ['foo','bar'], :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
.with_content(/users = \[ "foo", "bar", \]/) }
end


context "Windows 2012 R2 with users => foo (not a valid array)" do
let(:params) { {:users => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
context "Windows 2012 R2 with users => host.vars.notification.mail.users" do
let(:params) { {:users => 'host.vars.notification.mail.users', :target => 'C:/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
.with_content(/users = host\.vars\.notification\.mail\.users/) }
end


context "Windows 2012 R2 with user_groups => [foo, bar]" do
let(:params) { {:user_groups => ['foo','bar'], :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:user_groups => ['foo','bar'], :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
.with_content(/user_groups = \[ "foo", "bar", \]/) }
end


context "Windows 2012 R2 with user_groups => foo (not a valid array)" do
let(:params) { {:user_groups => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
context "Windows 2012 R2 with user_groups => host.vars.notification.mail.groups" do
let(:params) { {:user_groups => 'host.vars.notification.mail.groups', :target => 'C:/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
.with_content(/user_groups = host\.vars\.notification\.mail\.groups/) }
end


context "Windows 2012 R2 with times => { foo => 'bar', bar => 'foo' }" do
let(:params) { {:times => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz', :host_name => 'foohost' } }
let(:params) { {:times => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({ 'target' => 'C:/bar/baz' })
Expand All @@ -311,14 +317,14 @@


context "Windows 2012 R2 with times => 'foo' (not a valid hash)" do
let(:params) { {:times => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:times => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) }
end


context "Windows 2012 R2 with command => foo" do
let(:params) { {:command => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:command => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
Expand All @@ -327,7 +333,7 @@


context "Windows 2012 R2 with interval => 30" do
let(:params) { {:interval => '30', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:interval => '30', :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
Expand All @@ -336,14 +342,14 @@


context "Windows 2012 R2 with interval => foo (not a valid integer)" do
let(:params) { {:interval => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:interval => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) }
end


context "Windows 2012 R2 with period => foo" do
let(:params) { {:period => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:period => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
Expand All @@ -352,7 +358,7 @@


context "Windows 2012 R2 with zone => foo" do
let(:params) { {:zone => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:zone => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
Expand All @@ -361,7 +367,7 @@


context "Windows 2012 R2 with types => [foo, bar]" do
let(:params) { {:types => ['foo','bar'], :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:types => ['foo','bar'], :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
Expand All @@ -370,14 +376,14 @@


context "Windows 2012 R2 with types => foo (not a valid array)" do
let(:params) { {:types => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:types => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
end


context "Windows 2012 R2 with states => [foo, bar]" do
let(:params) { {:states => ['foo','bar'], :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:states => ['foo','bar'], :target => 'C:/bar/baz'} }

it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar')
.with({'target' => 'C:/bar/baz'})
Expand All @@ -386,13 +392,13 @@


context "Windows 2012 R2 with states => foo (not a valid array)" do
let(:params) { {:states => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:states => 'foo', :target => 'C:/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) }
end

context "Windows 2012 R2 with assign => [] and ignore => [ foo ]" do
let(:params) { {:assign => [], :ignore => ['foo'], :target => 'C:/bar/baz', :host_name => 'foohost'} }
let(:params) { {:assign => [], :ignore => ['foo'], :target => 'C:/bar/baz'} }

it { is_expected.to raise_error(Puppet::Error, /When attribute ignore is used, assign must be set/) }
end
Expand Down

0 comments on commit 0514554

Please sign in to comment.