comparison modules/ssh/spec/defines/config_entry_spec.rb @ 385:d9009f54eb23

Migrate to a fully-fledged SSH module This handles lots of the server path differences for us
author IBBoard <dev@ibboard.co.uk>
date Mon, 03 Jan 2022 17:05:54 +0000
parents
children
comparison
equal deleted inserted replaced
384:22e45bb5ea97 385:d9009f54eb23
1 require 'spec_helper'
2 describe 'ssh::config_entry' do
3 mandatory_params = {
4 :owner => 'test_owner',
5 :group => 'test_group',
6 :path => '/test/path',
7 :host => 'test_host',
8 }
9
10 let(:title) { 'example' }
11 let(:params) { mandatory_params }
12
13 context 'with no paramater is provided' do
14 let(:params) { {} }
15 it 'should fail' do
16 expect do
17 should contain_define(subject)
18 end.to raise_error(Puppet::Error, /(Must pass|expects a value for parameter)/) # Puppet4/5
19 end
20 end
21
22 context 'with mandatory params set' do
23 let(:params) { mandatory_params }
24 it { should compile.with_all_deps }
25
26 it do
27 should contain_concat('/test/path').with({
28 'ensure' => 'present',
29 'owner' => 'test_owner',
30 'group' => 'test_group',
31 'mode' => '0644',
32 'ensure_newline' => true,
33 })
34 end
35
36 it do
37 should contain_concat__fragment('/test/path Host test_host').with({
38 'target' => '/test/path',
39 'content' => 'Host test_host',
40 'order' => '10',
41 'tag' => 'test_owner_ssh_config',
42 })
43 end
44 end
45
46 context 'with owner set to valid string <other_owner>' do
47 let(:params) { mandatory_params.merge({ :owner => 'other_owner' }) }
48 it { should contain_concat('/test/path').with_owner('other_owner') }
49 it { should contain_concat__fragment('/test/path Host test_host').with_tag('other_owner_ssh_config') }
50 end
51
52 context 'with group set to valid string <other_group>' do
53 let(:params) { mandatory_params.merge({ :group => 'other_group' }) }
54 it { should contain_concat('/test/path').with_group('other_group') }
55 end
56
57 context 'with path set to valid string </other/path>' do
58 let(:params) { mandatory_params.merge({ :path => '/other/path' }) }
59 it { should contain_concat('/other/path') }
60 it { should contain_concat__fragment('/other/path Host test_host') }
61 end
62
63 context 'with host set to valid string <other_host>' do
64 let(:params) { mandatory_params.merge({ :host => 'other_host' }) }
65 it { should contain_concat__fragment('/test/path Host other_host').with_content('Host other_host') }
66 end
67
68 context 'with order set to valid string <242>' do
69 let(:params) { mandatory_params.merge({ :order => '242' }) }
70 it { should contain_concat__fragment('/test/path Host test_host').with_order('242') }
71 end
72
73 # /!\ no functionality for $ensure implemented yet
74 # context 'with ensure set to valid string <absent>' do
75 # let(:params) { mandatory_params.merge({ :ensure => 'absent' }) }
76 # it { should contain_concat('/test/path').with_ensure('absent') }
77 # end
78
79 context 'with lines set to valid array [ <ForwardX11 no>, <StrictHostKeyChecking no> ]' do
80 let(:params) { mandatory_params.merge({ :lines => ['ForwardX11 no', 'StrictHostKeyChecking no'] }) }
81 it { should contain_concat__fragment('/test/path Host test_host').with_content("Host test_host\nForwardX11 no\nStrictHostKeyChecking no") }
82 end
83 end