From 9c9b7c76bef8d43384ff7199336742ed3b1c8224 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Tue, 20 May 2014 17:07:53 -0700 Subject: [PATCH] add unit tests of mdadm's service_{ensure,enable} params --- README.md | 5 ++- spec/unit/classes/mdadm_spec.rb | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5bdda3b..3b49b97 100644 --- a/README.md +++ b/README.md @@ -88,12 +88,15 @@ unless the `$::mdadm_arrays` fact lists `md` arrays. If this parameter is set t `String` defaults to 'running' -Valid strings are: 'running', 'stopped' +Sets the state of the `mdmonitor` service. Valid strings are: 'running', +'stopped' ##### `service_enable` `Bool` defaults to 'true' +Enables/disables the `mdmonitor` service on boot. + ##### `raid_check_manage` `Bool` defaults to `true` diff --git a/spec/unit/classes/mdadm_spec.rb b/spec/unit/classes/mdadm_spec.rb index fff6b8c..659bf34 100644 --- a/spec/unit/classes/mdadm_spec.rb +++ b/spec/unit/classes/mdadm_spec.rb @@ -77,6 +77,82 @@ end end # service_force + context 'service_ensure =>' do + # we need to set service_force => true to disable the automatic service + # setup based on the existance of the ::mdadm_arrays fact + context 'running' do + let(:params) {{ :service_force => true, :service_ensure => 'running' }} + + it do + should contain_service('mdmonitor').with({ + :ensure => 'running', + :hasrestart => true, + :hasstatus => true, + :enable => true, + }) + end + end + + context 'stopped' do + let(:params) {{:service_force => true, :service_ensure => 'stopped' }} + + it do + should contain_service('mdmonitor').with({ + :ensure => 'stopped', + :hasrestart => true, + :hasstatus => true, + :enable => true, + }) + end + end + + context 'foo' do + let(:params) {{ :service_ensure => 'foo' }} + + it 'should fail' do + expect { should }.to raise_error(/does not match/) + end + end + end # service_ensure + + context 'service_enable =>' do + # we need to set service_force => true to disable the automatic service + # setup based on the existance of the ::mdadm_arrays fact + context 'true' do + let(:params) {{ :service_force => true, :service_enable => true }} + + it do + should contain_service('mdmonitor').with({ + :ensure => 'running', + :hasrestart => true, + :hasstatus => true, + :enable => true, + }) + end + end + + context 'false' do + let(:params) {{:service_force => true, :service_enable => false }} + + it do + should contain_service('mdmonitor').with({ + :ensure => 'running', + :hasrestart => true, + :hasstatus => true, + :enable => false, + }) + end + end + + context 'foo' do + let(:params) {{ :service_enable => 'foo' }} + + it 'should fail' do + expect { should }.to raise_error(/is not a boolean/) + end + end + end # service_enable + context 'raid_check_manage =>' do context 'true' do let(:params) {{ :raid_check_manage => true }}