From 4dbbdf5685919ee6c53e2787f6c53f85cf0c3360 Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Thu, 21 Sep 2017 11:18:57 +0000 Subject: [PATCH] Add spec tests for ssh::config_entry define --- spec/defines/config_entry_spec.rb | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 spec/defines/config_entry_spec.rb diff --git a/spec/defines/config_entry_spec.rb b/spec/defines/config_entry_spec.rb new file mode 100644 index 0000000..eee757e --- /dev/null +++ b/spec/defines/config_entry_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' +describe 'ssh::config_entry' do + mandatory_params = { + :owner => 'test_owner', + :group => 'test_group', + :path => '/test/path', + :host => 'test_host', + } + + let(:title) { 'example' } + let(:params) { mandatory_params } + + context 'with no paramater is provided' do + let(:params) { {} } + it 'should fail' do + expect do + should contain_define(subject) + end.to raise_error(Puppet::Error, /(Must pass|expects a value for parameter)/) # Puppet4/5 + end + end + + context 'with mandatory params set' do + let(:params) { mandatory_params } + it { should compile.with_all_deps } + + it do + should contain_concat('/test/path').with({ + 'ensure' => 'present', + 'owner' => 'test_owner', + 'group' => 'test_group', + 'mode' => '0644', + 'ensure_newline' => true, + }) + end + + it do + should contain_concat__fragment('/test/path Host test_host').with({ + 'target' => '/test/path', + 'content' => 'Host test_host', + 'order' => '10', + 'tag' => 'test_owner_ssh_config', + }) + end + end + + context 'with owner set to valid string ' do + let(:params) { mandatory_params.merge({ :owner => 'other_owner' }) } + it { should contain_concat('/test/path').with_owner('other_owner') } + it { should contain_concat__fragment('/test/path Host test_host').with_tag('other_owner_ssh_config') } + end + + context 'with group set to valid string ' do + let(:params) { mandatory_params.merge({ :group => 'other_group' }) } + it { should contain_concat('/test/path').with_group('other_group') } + end + + context 'with path set to valid string ' do + let(:params) { mandatory_params.merge({ :path => '/other/path' }) } + it { should contain_concat('/other/path') } + it { should contain_concat__fragment('/other/path Host test_host') } + end + + context 'with host set to valid string ' do + let(:params) { mandatory_params.merge({ :host => 'other_host' }) } + it { should contain_concat__fragment('/test/path Host other_host').with_content('Host other_host') } + end + + context 'with order set to valid string <242>' do + let(:params) { mandatory_params.merge({ :order => '242' }) } + it { should contain_concat__fragment('/test/path Host test_host').with_order('242') } + end + +# /!\ no functionality for $ensure implemented yet +# context 'with ensure set to valid string ' do +# let(:params) { mandatory_params.merge({ :ensure => 'absent' }) } +# it { should contain_concat('/test/path').with_ensure('absent') } +# end + + context 'with lines set to valid array [ , ]' do + let(:params) { mandatory_params.merge({ :lines => ['ForwardX11 no', 'StrictHostKeyChecking no'] }) } + it { should contain_concat__fragment('/test/path Host test_host').with_content("Host test_host\nForwardX11 no\nStrictHostKeyChecking no") } + end +end