Debian Codegraph @

spec/defines/instance_service_spec.rb

raw
1 # frozen_string_literal: true
2
3 require 'spec_helper'
4
5 describe 'haproxy::instance_service' do
6 let(:facts) do
7 {
8 concat_basedir: '/dne',
9 networking: {
10 ip: '10.10.10.10'
11 },
12 os: {
13 family: 'Debian'
14 }
15 }
16 end
17 let(:params) do
18 {
19 'haproxy_init_source' => 'foo'
20 }
21 end
22
23 context 'when on any platform' do
24 # haproxy::instance 'haproxy' with defaults
25
26 context 'with title haproxy and defaults params' do
27 let(:title) { 'haproxy' }
28 let(:params) do
29 {
30 'haproxy_init_source' => '/foo/bar'
31 }
32 end
33
34 it 'installs the haproxy package' do
35 subject.should contain_package('haproxy').with(
36 'ensure' => 'present',
37 )
38 end
39
40 it 'creates the exec directory' do
41 subject.should contain_file('/opt/haproxy/bin').with(
42 'ensure' => 'directory', 'owner' => 'root',
43 'group' => 'root', 'mode' => '0744'
44 )
45 end
46
47 it 'creates a link to the exec' do
48 subject.should contain_file('/opt/haproxy/bin/haproxy-haproxy').with(
49 'ensure' => 'link',
50 'target' => '/usr/sbin/haproxy',
51 )
52 end
53
54 it 'does not create an init.d file' do
55 subject.should_not contain_file('/etc/init.d/haproxy-haproxy').with(
56 'ensure' => 'file',
57 )
58 end
59 end
60
61 # haproxy::instance 'haproxy' with custom settings
62
63 context 'with title group1 and custom settings' do
64 let(:title) { 'haproxy' }
65 let(:pre_condition) do
66 <<-PUPPETCODE
67 service {'haproxy-#{title}': }
68 PUPPETCODE
69 end
70 let(:params) do
71 {
72 'haproxy_package' => 'customhaproxy',
73 'bindir' => '/weird/place',
74 'haproxy_init_source' => '/foo/bar'
75 }
76 end
77
78 it 'installs the customhaproxy package' do
79 subject.should contain_package('customhaproxy').with(
80 'ensure' => 'present',
81 )
82 end
83
84 it 'creates the exec directory' do
85 subject.should contain_file('/weird/place').with(
86 'ensure' => 'directory', 'owner' => 'root',
87 'group' => 'root', 'mode' => '0744'
88 )
89 end
90
91 it 'creates a link to the exec' do
92 subject.should contain_file('/weird/place/haproxy-haproxy').with(
93 'ensure' => 'link',
94 'target' => '/opt/customhaproxy/sbin/haproxy',
95 )
96 end
97
98 it 'does not create an init.d file' do
99 subject.should_not contain_file('/etc/init.d/haproxy-haproxy').with(
100 'ensure' => 'file',
101 )
102 end
103
104 it 'does not manage the default init.d file' do
105 subject.should_not contain_file('/etc/init.d/haproxy').with(
106 'ensure' => 'file',
107 )
108 end
109 end
110
111 # haproxy::instance 'group1' with defaults
112
113 context 'with title group1 and defaults params' do
114 let(:title) { 'group1' }
115 let(:pre_condition) do
116 <<-PUPPETCODE
117 service {'haproxy-#{title}': }
118 PUPPETCODE
119 end
120 let(:params) do
121 {
122 'haproxy_init_source' => '/foo/bar'
123 }
124 end
125
126 it 'installs the haproxy package' do
127 subject.should contain_package('haproxy').with(
128 'ensure' => 'present',
129 )
130 end
131
132 it 'creates the exec directory' do
133 subject.should contain_file('/opt/haproxy/bin').with(
134 'ensure' => 'directory', 'owner' => 'root',
135 'group' => 'root', 'mode' => '0744'
136 )
137 end
138
139 it 'creates a link to the exec' do
140 subject.should contain_file('/opt/haproxy/bin/haproxy-group1').with(
141 'ensure' => 'link',
142 'target' => '/usr/sbin/haproxy',
143 )
144 end
145
146 it 'does not create an init.d file' do
147 subject.should_not contain_file('/etc/init.d/haproxy-haproxy').with(
148 'ensure' => 'file',
149 )
150 end
151 end
152 end
153
154 # haproxy::instance 'group1' with custom settings
155
156 context 'with title group1 and defaults params' do
157 let(:title) { 'group1' }
158 let(:pre_condition) do
159 <<-PUPPETCODE
160 service {'haproxy-#{title}': }
161 PUPPETCODE
162 end
163 let(:params) do
164 {
165 'haproxy_package' => 'customhaproxy',
166 'bindir' => '/weird/place',
167 'haproxy_init_source' => '/init/source/haproxy'
168 }
169 end
170
171 it 'installs the customhaproxy package' do
172 subject.should contain_package('customhaproxy').with(
173 'ensure' => 'present',
174 )
175 end
176
177 it 'creates the exec directory' do
178 subject.should contain_file('/weird/place').with(
179 'ensure' => 'directory', 'owner' => 'root',
180 'group' => 'root', 'mode' => '0744'
181 )
182 end
183
184 it 'creates a link to the exec' do
185 subject.should contain_file('/weird/place/haproxy-group1').with(
186 'ensure' => 'link',
187 'target' => '/opt/customhaproxy/sbin/haproxy',
188 )
189 end
190
191 it 'removes any obsolete init.d file' do
192 subject.should contain_file('/etc/init.d/haproxy-group1').with(
193 'ensure' => 'absent',
194 )
195 end
196 end
197 end