Skip to content

Commit

Permalink
(GH-701) Stop using scope.lookupvar() in templates
Browse files Browse the repository at this point in the history
Add tests for existing functionality as preparation.
  • Loading branch information
Phil-Friderici committed Jul 9, 2017
1 parent b759184 commit d86f921
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion spec/classes/sensu_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

it 'should compile' do should create_class('sensu') end
it { should contain_user('sensu') }
it { should contain_file('/etc/default/sensu').with_content(%r{^EMBEDDED_RUBY=true$}) }
it { should contain_file('/etc/default/sensu').with_content(%r{^LOG_LEVEL=info$}) }
it { should contain_file('/etc/default/sensu').with_content(%r{^LOG_DIR=/var/log/sensu$}) }

it { should contain_file('/etc/default/sensu').without_content(%r{^RUBYOPT=.*$}) }
it { should contain_file('/etc/default/sensu').without_content(%r{^GEM_PATH=.*$}) }
it { should contain_file('/etc/default/sensu').without_content(%r{^CLIENT_DEREGISTER_ON_STOP=true\nCLIENT_DEREGISTER_HANDLER=.*$}) }
it { should contain_file('/etc/default/sensu').with_content(%r{^SERVICE_MAX_WAIT="10"$}) }
it { should contain_file('/etc/default/sensu').with_content(%r{^PATH=\$PATH$}) }

context 'osfamily windows' do
let(:facts) do
Expand All @@ -33,11 +39,57 @@
end
end

context 'with use_embedded_ruby => false' do
let(:params) { {:use_embedded_ruby => false } }
it { should contain_file('/etc/default/sensu').with_content(%r{^EMBEDDED_RUBY=false$}) }
end

context 'with log_level => debug' do
let(:params) { {:log_level => 'debug' } }
it { should contain_file('/etc/default/sensu').with_content(%r{^LOG_LEVEL=debug$}) }
end

context 'with log_dir => /var/log/tests' do
let(:params) { {:log_dir => '/var/log/tests' } }
it { should contain_file('/etc/default/sensu').with_content(%r{^LOG_DIR=/var/log/tests$}) }
end

context 'rubyopt => -rbundler/test' do
let(:params) { {:rubyopt => '-rbundler/test' } }
it { should contain_file('/etc/default/sensu').with_content(%r{^RUBYOPT="-rbundler/test"$}) }
end

context 'gem_path => /path/to/gems' do
let(:params) { {:gem_path => '/path/to/gems' } }
it { should contain_file('/etc/default/sensu').with_content(%r{^GEM_PATH="/path/to/gems"$}) }
end

context 'deregister_on_stop => true' do
let(:params) { {:deregister_on_stop => true } }
it { should contain_file('/etc/default/sensu').with_content(%r{^CLIENT_DEREGISTER_ON_STOP=true\nCLIENT_DEREGISTER_HANDLER=""$}) }
end

# without deregister_on_stop == true deregister_handler will be ignored
context 'deregister_handler => testing' do
let(:params) { {:deregister_handler => 'testing' } }
it { should contain_file('/etc/default/sensu').without_content(%r{^CLIENT_DEREGISTER_ON_STOP=true\nCLIENT_DEREGISTER_HANDLER=.*$}) }
end

context 'deregister_on_stop => true & deregister_handler => testing' do
let(:params) { {:deregister_on_stop => true, :deregister_handler => 'testing' } }
it { should contain_file('/etc/default/sensu').with_content(%r{^CLIENT_DEREGISTER_ON_STOP=true\nCLIENT_DEREGISTER_HANDLER="testing"$}) }
end

context 'init_stop_max_wait => 242' do
let(:params) { {:init_stop_max_wait => 242 } }
it { should contain_file('/etc/default/sensu').with_content(%r{^SERVICE_MAX_WAIT="242"$}) }
end

context 'path => /spec/tests' do
let(:params) { {:path => '/spec/tests' } }
it { should contain_file('/etc/default/sensu').with_content(%r{^PATH=/spec/tests$}) }
end

context 'with plugins => puppet:///data/sensu/plugins/teststring.rb' do
let(:params) { {:plugins => 'puppet:///data/sensu/plugins/teststring.rb' } }
it { should contain_sensu__plugin('puppet:///data/sensu/plugins/teststring.rb').with_install_path('/etc/sensu/plugins') }
Expand Down Expand Up @@ -243,12 +295,30 @@
:invalid => ['./relative/path', %w(array), { 'ha' => 'sh' }, 3, 2.42, true, false, nil],
:message => 'is not an absolute path',
},
'boolean' => {
:name => %w(deregister_on_stop),
:valid => [true, false],
:invalid => ['false', %w(array), { 'ha' => 'sh' }, 3, 2.42, nil],
:message => 'is not a boolean',
},
'integer' => {
:name => %w(init_stop_max_wait),
:valid => [3, '242'],
:invalid => ['string', %w(array), { 'ha' => 'sh' }, 2.42, true, nil],
:message => 'must be an integer',
},
'plugins' => {
:name => %w[plugins],
:valid => ['/string', %w(/array), { '/hash' => {} }],
:invalid => [3, 2.42, true],
:message => 'Invalid data type',
},
'validate_re log_level' => {
:name => %w[log_level],
:valid => %w[debug info warn error fatal],
:invalid => ['string', %w(array), { 'ha' => 'sh' }, 3, 2.42, true, nil],
:message => 'validate_re()',
},
}

validations.sort.each do |type, var|
Expand Down

0 comments on commit d86f921

Please sign in to comment.