diff --git a/manifests/client.pp b/manifests/client.pp index 3b614dfc45..b35926287b 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -6,43 +6,22 @@ # class sensu::client( - $rabbitmq_password, - $rabbitmq_ssl_private_key = '', - $rabbitmq_ssl_cert_chain = '', - $rabbitmq_port = '5671', - $rabbitmq_host = 'localhost', - $rabbitmq_user = 'sensu', - $rabbitmq_vhost = '/sensu', - $address = $::ipaddress, - $subscriptions = [], - $client_name = $::fqdn - ) { + $address = $::ipaddress, + $subscriptions = [], + $client_name = $::fqdn, + $enabled = true +) { - include sensu::package - - class { 'sensu::rabbitmq': - ssl_cert_chain => $rabbitmq_ssl_cert_chain, - ssl_private_key => $rabbitmq_ssl_private_key, - port => $rabbitmq_port, - host => $rabbitmq_host, - user => $rabbitmq_user, - vhost => $rabbitmq_vhost, - password => $rabbitmq_password, + $ensure = $enabled ? { + true => 'present', + default => 'absent' } sensu_client_config { $::fqdn: client_name => $client_name, address => $address, subscriptions => $subscriptions, + ensure => $ensure } - service { 'sensu-client': - ensure => running, - enable => true, - hasrestart => true, - require => [ - Sensu_rabbitmq_config[$::fqdn], - Sensu_client_config[$::fqdn], - ], - } } diff --git a/manifests/handler.pp b/manifests/handler.pp index 218caaae9e..ebe8592263 100644 --- a/manifests/handler.pp +++ b/manifests/handler.pp @@ -6,13 +6,15 @@ # define sensu::handler( - $type, - $command - ) { + $type, + $command, + $ensure = 'present' +) { sensu_handler_config { $name: type => $type, command => $command, - before => Service['sensu-server'], + ensure => $ensure, + notify => Class['sensu::service::server'] } } diff --git a/manifests/init.pp b/manifests/init.pp index 0139764735..02ba52bccb 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -7,6 +7,87 @@ # None. # -class sensu { +class sensu ( + $rabbitmq_password, + $server = false, + $client = true, + $rabbitmq_port = '5671', + $rabbitmq_host = 'localhost', + $rabbitmq_user = 'sensu', + $rabbitmq_vhost = '/sensu', + $rabbitmq_ssl_private_key = '', + $rabbitmq_ssl_cert_chain = '', + $redis_host = 'localhost', + $redis_port = '6379', + $api_host = 'localhost', + $api_port = '4567', + $dashboard_host = $::ipaddress, + $dashboard_port = '8080', + $dashboard_user = 'admin', + $dashboard_password = 'secret', + $subscriptions = [], + $client_address = $::ipaddress, + $client_name = $::fqdn +){ + + Class['sensu::package'] -> + Class['sensu::rabbitmq'] + + Class['sensu::rabbitmq'] -> + Class['sensu::server'] ~> + Class['sensu::service::server'] -> + Class['sensu'] + + Class['sensu::rabbitmq'] -> + Class['sensu::client'] ~> + Class['sensu::service::client'] -> + Class['sensu'] + + if $server == true { + if $client == true { + $notify_services = [ Class['sensu::service::client'], Class['sensu::service::server'] ] + } else { + $notify_services = Class['sensu::service::server'] + } + } elsif $client == true { + $notify_services = Class['sensu::service::client'] + } else { + $notify_services = [] + } + + class { 'sensu::package': } + class { 'sensu::rabbitmq': + ssl_cert_chain => $rabbitmq_ssl_cert_chain, + ssl_private_key => $rabbitmq_ssl_private_key, + port => $rabbitmq_port, + host => $rabbitmq_host, + user => $rabbitmq_user, + password => $rabbitmq_password, + vhost => $rabbitmq_vhost, + notify_services => $notify_services + } + + class { 'sensu::server': + redis_host => $redis_host, + redis_port => $redis_port, + api_host => $api_host, + api_port => $api_port, + dashboard_host => $dashboard_host, + dashboard_port => $dashboard_port, + dashboard_user => $dashboard_user, + dashboard_password => $dashboard_password, + enabled => $server + } + + class { 'sensu::service::server': enabled => $server } + + class { 'sensu::client': + address => $client_address, + subscriptions => $subscriptions, + client_name => $client_name, + enabled => $client + } + + class { 'sensu::service::client': enabled => $client } } diff --git a/manifests/rabbitmq.pp b/manifests/rabbitmq.pp index 6451959291..28532ac96a 100644 --- a/manifests/rabbitmq.pp +++ b/manifests/rabbitmq.pp @@ -12,7 +12,8 @@ $host, $user, $password, - $vhost + $vhost, + $notify_services ) { if !defined(Sensu_rabbitmq_config[$::fqdn]) { @@ -71,6 +72,7 @@ user => $user, password => $password, vhost => $vhost, + notify => $notify_services } } } diff --git a/manifests/server.pp b/manifests/server.pp index a738bc8b49..a5bff7af86 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -6,43 +6,32 @@ # class sensu::server( - $rabbitmq_password, - $rabbitmq_port = '5671', - $rabbitmq_host = 'localhost', - $rabbitmq_user = 'sensu', - $rabbitmq_vhost = '/sensu', - $rabbitmq_ssl_private_key = '', - $rabbitmq_ssl_cert_chain = '', - $redis_host = 'localhost', - $redis_port = '6379', - $api_host = 'localhost', - $api_port = '4567', - $dashboard_host = $::ipaddress, - $dashboard_port = '8080', - $dashboard_user = 'admin', - $dashboard_password = 'secret', - $ensure = 'present' - ) { - include sensu::package - - class { 'sensu::rabbitmq': - ssl_cert_chain => $rabbitmq_ssl_cert_chain, - ssl_private_key => $rabbitmq_ssl_private_key, - port => $rabbitmq_port, - host => $rabbitmq_host, - user => $rabbitmq_user, - password => $rabbitmq_password, - vhost => $rabbitmq_vhost, + $redis_host = 'localhost', + $redis_port = '6379', + $api_host = 'localhost', + $api_port = '4567', + $dashboard_host = $::ipaddress, + $dashboard_port = '8080', + $dashboard_user = 'admin', + $dashboard_password = 'secret', + $enabled = false +) { + + $ensure = $enabled ? { + true => 'present', + false => 'absent' } sensu_redis_config { $::fqdn: - host => $redis_host, - port => $redis_port, + host => $redis_host, + port => $redis_port, + ensure => $ensure, } sensu_api_config { $::fqdn: - host => $api_host, - port => $api_port, + host => $api_host, + port => $api_port, + ensure => $ensure, } sensu_dashboard_config { $::fqdn: @@ -50,37 +39,12 @@ port => $dashboard_port, user => $dashboard_user, password => $dashboard_password, - } - - Service { - ensure => running, - enable => true, - hasrestart => true, - } - - service { - 'sensu-server': - require => [ - Sensu_rabbitmq_config[$::fqdn], - Sensu_redis_config[$::fqdn], - ]; - 'sensu-api': - require => [ - Sensu_rabbitmq_config[$::fqdn], - Sensu_api_config[$::fqdn], - Service['sensu-server'], - ]; - 'sensu-dashboard': - require => [ - Sensu_rabbitmq_config[$::fqdn], - Sensu_dashboard_config[$::fqdn], - Service['sensu-api'], - ]; + ensure => $ensure, } sensu::handler { 'default': type => 'pipe', command => '/etc/sensu/handlers/default', + ensure => $ensure } - } diff --git a/manifests/service/client.pp b/manifests/service/client.pp new file mode 100644 index 0000000000..ad69712ea3 --- /dev/null +++ b/manifests/service/client.pp @@ -0,0 +1,16 @@ +class sensu::service::client ( + $enabled +) { + + $real_ensure = $enabled ? { + true => 'running', + false => 'stopped', + } + + service { 'sensu-client': + ensure => $real_ensure, + enable => $enabled, + hasrestart => true, + } + +} diff --git a/manifests/service/server.pp b/manifests/service/server.pp new file mode 100644 index 0000000000..2b0ac9f204 --- /dev/null +++ b/manifests/service/server.pp @@ -0,0 +1,19 @@ +class sensu::service::server( + $enabled +) { + + $real_ensure = $enabled ? { + true => 'running', + false => 'stopped', + } + + Service { + ensure => $real_enabled, + enable => $enabled, + hasrestart => true, + } + + service { 'sensu-server': } + service { 'sensu-api': } + service { 'sensu-dashboard': } +} diff --git a/spec/classes/sensu_client_spec.rb b/spec/classes/sensu_client_spec.rb index 418958b235..a722ebca89 100644 --- a/spec/classes/sensu_client_spec.rb +++ b/spec/classes/sensu_client_spec.rb @@ -5,71 +5,37 @@ context 'defaults' do let(:facts) { { :ipaddress => '2.3.4.5', :fqdn => 'host.domain.com' } } - let(:params) { { :rabbitmq_password => 'asdfjkl' } } - - it { should include_class('sensu::package') } - it { should contain_class('sensu::rabbitmq').with( - 'ssl_cert_chain' => '', - 'ssl_private_key' => '', - 'port' => '5671', - 'host' => 'localhost', - 'user' => 'sensu', - 'vhost' => '/sensu', - 'password' => 'asdfjkl' - ) } it { should contain_sensu_client_config('host.domain.com').with( 'client_name' => 'host.domain.com', 'address' => '2.3.4.5', - 'subscriptions' => [] + 'subscriptions' => [], + 'ensure' => 'present' ) } - it { should contain_service('sensu-client').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[host.domain.com]', 'Sensu_client_config[host.domain.com]'] - ) } end - context 'setting params' do + context 'setting params (enabled)' do let(:facts) { { :fqdn => 'host.domain.com' } } let(:params) { { - :rabbitmq_password => 'asdfjkl', - :rabbitmq_ssl_private_key => '/etc/sensu/ssl/key.pem', - :rabbitmq_ssl_cert_chain => '/etc/sensu/ssl/chain.pem', - :rabbitmq_port => '1234', - :rabbitmq_host => 'rabbithost', - :rabbitmq_user => 'sensuuser', - :rabbitmq_vhost => '/myvhost', :address => '1.2.3.4', :subscriptions => ['all'], :client_name => 'myclient' } } - it { should include_class('sensu::package') } - it { should contain_class('sensu::rabbitmq').with( - 'ssl_cert_chain' => '/etc/sensu/ssl/chain.pem', - 'ssl_private_key' => '/etc/sensu/ssl/key.pem', - 'port' => '1234', - 'host' => 'rabbithost', - 'user' => 'sensuuser', - 'vhost' => '/myvhost', - 'password' => 'asdfjkl' - ) } - it { should contain_sensu_client_config('host.domain.com').with( 'client_name' => 'myclient', 'address' => '1.2.3.4', - 'subscriptions' => ['all'] + 'subscriptions' => ['all'], + 'ensure' => 'present' ) } - it { should contain_service('sensu-client').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[host.domain.com]', 'Sensu_client_config[host.domain.com]'] - ) } + end + + context 'disabled' do + let(:facts) { { :fqdn => 'host.domain.com' } } + let(:params) { { :enabled => false } } + it { should contain_sensu_client_config('host.domain.com').with_ensure('absent') } end end diff --git a/spec/classes/sensu_init_spec.rb b/spec/classes/sensu_init_spec.rb index 9cd5d02670..2dc3a39444 100644 --- a/spec/classes/sensu_init_spec.rb +++ b/spec/classes/sensu_init_spec.rb @@ -2,7 +2,122 @@ describe 'sensu', :type => :class do - it { should create_class('sensu') } + context 'defaults' do + let(:params) { { :rabbitmq_password => 'asdfjkl' } } + let(:facts) { { :fqdn => 'myhost.domain.com', :ipaddress => '1.2.3.4' } } + + it { should contain_class('sensu::rabbitmq').with( + 'ssl_cert_chain' => '', + 'ssl_private_key' => '', + 'port' => '5671', + 'host' => 'localhost', + 'user' => 'sensu', + 'password' => 'asdfjkl', + 'vhost' => '/sensu', + 'notify_services' => 'Class[Sensu::Service::Client]' + )} + + it { should contain_class('sensu::server').with( + 'redis_host' => 'localhost', + 'redis_port' => '6379', + 'api_host' => 'localhost', + 'api_port' => '4567', + 'dashboard_host' => '1.2.3.4', + 'dashboard_port' => '8080', + 'dashboard_user' => 'admin', + 'dashboard_password' => 'secret', + 'enabled' => false + )} + + it { should contain_class('sensu::client').with( + 'address' => '1.2.3.4', + 'subscriptions' => [], + 'client_name' => 'myhost.domain.com', + 'enabled' => true + )} + + it { should contain_class('sensu::service::server').with_enabled(false) } + it { should contain_class('sensu::service::client').with_enabled(true) } + end + + + context 'setting all params' do + let(:params) { { + :rabbitmq_password => 'asdfjkl', + :server => true, + :client => false, + :rabbitmq_port => '1234', + :rabbitmq_host => 'rabbithost', + :rabbitmq_user => 'sensuuser', + :rabbitmq_vhost => '/vhost', + :rabbitmq_ssl_private_key => '/etc/sensu/ssl/key.pem', + :rabbitmq_ssl_cert_chain => '/etc/sensu/ssl/cert.pem', + :redis_host => 'redishost', + :redis_port => '2345', + :api_host => 'apihost', + :api_port => '3456', + :dashboard_host => 'dashhost', + :dashboard_port => '5678', + :dashboard_user => 'dashuser', + :dashboard_password => 'dashpass', + :subscriptions => ['all'], + :client_address => '127.0.0.1', + :client_name => 'myhost' + } } + + it { should contain_class('sensu::rabbitmq').with( + 'ssl_cert_chain' => '/etc/sensu/ssl/cert.pem', + 'ssl_private_key' => '/etc/sensu/ssl/key.pem', + 'port' => '1234', + 'host' => 'rabbithost', + 'user' => 'sensuuser', + 'password' => 'asdfjkl', + 'vhost' => '/vhost', + 'notify_services' => 'Class[Sensu::Service::Server]' + )} + + it { should contain_class('sensu::server').with( + 'redis_host' => 'redishost', + 'redis_port' => '2345', + 'api_host' => 'apihost', + 'api_port' => '3456', + 'dashboard_host' => 'dashhost', + 'dashboard_port' => '5678', + 'dashboard_user' => 'dashuser', + 'dashboard_password' => 'dashpass', + 'enabled' => true + )} + + it { should contain_class('sensu::client').with( + 'address' => '127.0.0.1', + 'subscriptions' => ['all'], + 'client_name' => 'myhost', + 'enabled' => false + )} + + it { should contain_class('sensu::service::server').with_enabled(true) } + it { should contain_class('sensu::service::client').with_enabled(false) } + end + + context 'server and client' do + let(:params) { { :rabbitmq_password => 'asdfjkl', :server => true, :client => true } } + let(:facts) { { :fqdn => 'myhost.domain.com', :ipaddress => '1.2.3.4' } } + + it { should contain_class('sensu::rabbitmq').with( + 'notify_services' => ['Class[Sensu::Service::Client]', 'Class[Sensu::Service::Server]'] + )} + end + + context 'neither server nor client' do + let(:params) { { :rabbitmq_password => 'asdfjkl', :server => false, :client => false } } + let(:facts) { { :fqdn => 'myhost.domain.com', :ipaddress => '1.2.3.4' } } + + it { should contain_class('sensu::rabbitmq').with( + 'notify_services' => '' + )} + end end + + diff --git a/spec/classes/sensu_rabbitmq_spec.rb b/spec/classes/sensu_rabbitmq_spec.rb index afcc5e35d0..12d4482ada 100644 --- a/spec/classes/sensu_rabbitmq_spec.rb +++ b/spec/classes/sensu_rabbitmq_spec.rb @@ -11,7 +11,8 @@ :host => 'myhost', :user => 'sensuuser', :password => 'sensupass', - :vhost => '/myvhost' + :vhost => '/myvhost', + :notify_services => [] } } pending "it should test cert installs" do diff --git a/spec/classes/sensu_server_spec.rb b/spec/classes/sensu_server_spec.rb index d5f596776e..82a852fca0 100644 --- a/spec/classes/sensu_server_spec.rb +++ b/spec/classes/sensu_server_spec.rb @@ -4,72 +4,48 @@ let(:title) { 'sensu::server' } context 'defaults' do - let(:params) { { :rabbitmq_password => 'asdfjkl' } } + let(:facts) { { :fqdn => 'testhost.domain.com' } } + it { should contain_sensu_redis_config('testhost.domain.com').with_ensure('absent') } + it { should contain_sensu_api_config('testhost.domain.com').with_ensure('absent') } + it { should contain_sensu_dashboard_config('testhost.domain.com').with_ensure('absent') } + it { should contain_sensu__handler('default').with_ensure('absent') } + end + + context 'defaults (enabled)' do let(:facts) { { :fqdn => 'testhost.domain.com', :ipaddress => '1.2.3.4' } } - - it { should include_class('sensu::package') } - - it { should contain_class('sensu::rabbitmq').with( - 'ssl_cert_chain' => '', - 'ssl_private_key' => '', - 'port' => '5671', - 'host' => 'localhost', - 'user' => 'sensu', - 'password' => 'asdfjkl', - 'vhost' => '/sensu' - ) } + let(:params) { { :enabled => true } } it { should contain_sensu_redis_config('testhost.domain.com').with( - 'host' => 'localhost', - 'port' => '6379' + 'host' => 'localhost', + 'port' => '6379', + 'ensure' => 'present' ) } it { should contain_sensu_api_config('testhost.domain.com').with( - 'host' => 'localhost', - 'port' => '4567' + 'host' => 'localhost', + 'port' => '4567', + 'ensure' => 'present' ) } it { should contain_sensu_dashboard_config('testhost.domain.com').with( 'host' => '1.2.3.4', 'port' => '8080', 'user' => 'admin', - 'password' => 'secret' - ) } - - it { should contain_service('sensu-server').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[testhost.domain.com]', 'Sensu_redis_config[testhost.domain.com]'] - ) } - - it { should contain_service('sensu-api').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[testhost.domain.com]', 'Sensu_api_config[testhost.domain.com]', 'Service[sensu-server]'] + 'password' => 'secret', + 'ensure' => 'present' ) } - it { should contain_service('sensu-dashboard').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[testhost.domain.com]', 'Sensu_dashboard_config[testhost.domain.com]', 'Service[sensu-api]'] + it { should contain_sensu__handler('default').with( + 'type' => 'pipe', + 'command' => '/etc/sensu/handlers/default', + 'ensure' => 'present' ) } - it { should contain_sensu__handler('default').with_type('pipe').with_command('/etc/sensu/handlers/default') } end # Defaults - context 'setting params' do + context 'setting params (enabled)' do let(:facts) { { :fqdn => 'testhost.domain.com', :ipaddress => '1.2.3.4' } } let(:params) { { - :rabbitmq_password => 'asdfjkl', - :rabbitmq_port => '1234', - :rabbitmq_host => 'rabbithost', - :rabbitmq_user => 'sensuuser', - :rabbitmq_vhost => '/myvhost', - :rabbitmq_ssl_private_key => '/etc/rabbitmq/ssl/key.pem', - :rabbitmq_ssl_cert_chain => '/etc/rabbitmq/ssl/chain.pem', :redis_host => 'redishost', :redis_port => '2345', :api_host => 'apihost', @@ -77,60 +53,35 @@ :dashboard_host => 'dashhost', :dashboard_port => '5678', :dashboard_user => 'user', - :dashboard_password => 'mypass' + :dashboard_password => 'mypass', + :enabled => true } } - it { should include_class('sensu::package') } - - it { should contain_class('sensu::rabbitmq').with( - 'ssl_cert_chain' => '/etc/rabbitmq/ssl/chain.pem', - 'ssl_private_key' => '/etc/rabbitmq/ssl/key.pem', - 'port' => '1234', - 'host' => 'rabbithost', - 'user' => 'sensuuser', - 'password' => 'asdfjkl', - 'vhost' => '/myvhost' - ) } - it { should contain_sensu_redis_config('testhost.domain.com').with( - 'host' => 'redishost', - 'port' => '2345' + 'host' => 'redishost', + 'port' => '2345', + 'ensure' => 'present' ) } it { should contain_sensu_api_config('testhost.domain.com').with( - 'host' => 'apihost', - 'port' => '3456' + 'host' => 'apihost', + 'port' => '3456', + 'ensure' => 'present' ) } it { should contain_sensu_dashboard_config('testhost.domain.com').with( 'host' => 'dashhost', 'port' => '5678', 'user' => 'user', - 'password' => 'mypass' - ) } - - it { should contain_service('sensu-server').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[testhost.domain.com]', 'Sensu_redis_config[testhost.domain.com]'] + 'password' => 'mypass', + 'ensure' => 'present' ) } - it { should contain_service('sensu-api').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[testhost.domain.com]', 'Sensu_api_config[testhost.domain.com]', 'Service[sensu-server]'] + it { should contain_sensu__handler('default').with( + 'type' => 'pipe', + 'command' => '/etc/sensu/handlers/default', + 'ensure' => 'present' ) } - - it { should contain_service('sensu-dashboard').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true, - 'require' => ['Sensu_rabbitmq_config[testhost.domain.com]', 'Sensu_dashboard_config[testhost.domain.com]', 'Service[sensu-api]'] - ) } - - it { should contain_sensu__handler('default').with_type('pipe').with_command('/etc/sensu/handlers/default') } end # setting params end diff --git a/spec/classes/sensu_service_client.pp b/spec/classes/sensu_service_client.pp new file mode 100644 index 0000000000..4e8d647055 --- /dev/null +++ b/spec/classes/sensu_service_client.pp @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe 'sensu::service::client', :type => :class do + + context 'enabled' do + let(:params) { { :enabled => true } } + + it { should contain_service('sensu-client').with( + 'ensure' => 'running', + 'enable' => true, + 'hasrestart' => true + ) } + + end + + context 'disabled' do + let(:params) { { :enabled => false } } + + it { should contain_service('sensu-client').with( + 'ensure' => 'stopped', + 'enable' => false, + 'hasrestart' => true + ) } + + end + +end diff --git a/spec/classes/sensu_service_server.pp b/spec/classes/sensu_service_server.pp new file mode 100644 index 0000000000..f957d6a163 --- /dev/null +++ b/spec/classes/sensu_service_server.pp @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'sensu::service::server', :type => :class do + + context 'enabled' do + let(:params) { { :enabled => true } } + + it { should contain_service('sensu-server').with( + 'ensure' => 'running', + 'enable' => true, + 'hasrestart' => true + ) } + + it { should contain_service('sensu-api').with( + 'ensure' => 'running', + 'enable' => true, + 'hasrestart' => true + ) } + + it { should contain_service('sensu-dashboard').with( + 'ensure' => 'running', + 'enable' => true, + 'hasrestart' => true + ) } + end + + context 'disabled' do + let(:params) { { :enabled => false } } + + it { should contain_service('sensu-server').with( + 'ensure' => 'stopped', + 'enable' => false, + 'hasrestart' => true + ) } + + it { should contain_service('sensu-api').with( + 'ensure' => 'stopped', + 'enable' => false, + 'hasrestart' => true + ) } + + it { should contain_service('sensu-dashboard').with( + 'ensure' => 'stopped', + 'enable' => false, + 'hasrestart' => true + ) } + + end + +end diff --git a/spec/defines/sensu_handler_spec.rb b/spec/defines/sensu_handler_spec.rb index 2460b66874..47ddf1d97d 100644 --- a/spec/defines/sensu_handler_spec.rb +++ b/spec/defines/sensu_handler_spec.rb @@ -2,11 +2,23 @@ describe 'sensu::handler', :type => :define do let(:title) { 'myhandler' } - let(:params) { { :type => 'pipe', :command => '/etc/sensu/mycommand.rb' } } - it { should contain_sensu_handler_config('myhandler').with( - 'type' => 'pipe', - 'command' => '/etc/sensu/mycommand.rb', - 'before' => 'Service[sensu-server]' - ) } + context 'default (present)' do + + let(:params) { { :type => 'pipe', :command => '/etc/sensu/mycommand.rb' } } + it { should contain_sensu_handler_config('myhandler').with( + 'type' => 'pipe', + 'command' => '/etc/sensu/mycommand.rb', + 'ensure' => 'present' + ) } + + end + + context 'absent' do + + let(:params) { { :type => 'pipe', :command => '/etc/sensu/mycommand.rb', :ensure => 'absent' } } + it { should contain_sensu_handler_config('myhandler').with_ensure('absent') } + + end + end