Debian Codegraph @

spec/acceptance/basic_spec.rb

raw
1 # frozen_string_literal: true
2
3 require 'spec_helper_acceptance'
4
5 # C9708 C9709 WONTFIX
6 describe 'configuring haproxy' do
7 # C9961
8 describe 'not managing the service' do
9 pp_one = <<-PUPPETCODE
10 class { 'haproxy':
11 service_manage => false,
12 }
13 haproxy::listen { 'stats':
14 ipaddress => '127.0.0.1',
15 ports => ['9090','9091'],
16 options => {
17 'mode' => 'http',
18 'stats' => ['uri /','auth puppet:puppet'],
19 },
20 }
21 haproxy::listen { 'test00':
22 ipaddress => '127.0.0.1',
23 ports => '80',
24 }
25 PUPPETCODE
26 it 'does not listen on any ports' do
27 retry_on_error_matching do
28 apply_manifest(pp_one, catch_failures: true)
29 end
30 end
31
32 ['9090', '9091'].each do |port|
33 describe port(port) do
34 it { is_expected.not_to be_listening }
35 end
36 end
37 end
38
39 describe 'configuring haproxy load balancing' do
40 describe 'multiple ports' do
41 pp_two = <<-PUPPETCODE
42 class { 'haproxy': }
43 haproxy::listen { 'stats':
44 ipaddress => '127.0.0.1',
45 ports => [9090, 9091],
46 mode => 'http',
47 options => { 'stats' => ['uri /','auth puppet:puppet'], },
48 }
49 PUPPETCODE
50 it 'is able to listen on an array of ports' do
51 retry_on_error_matching do
52 apply_manifest(pp_two, catch_failures: true)
53 end
54 end
55
56 ['9090', '9091'].each do |port|
57 it "port #{port} has stats listening on each port" do
58 run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
59 expect(r.stdout).to contain %r{HAProxy}
60 expect(r.exit_code).to eq 0
61 end
62 end
63 end
64 end
65
66 describe 'multiple ports as strings' do
67 pp_two = <<-PUPPETCODE
68 class { 'haproxy': }
69 haproxy::listen { 'stats':
70 ipaddress => '127.0.0.1',
71 ports => ['9090','9091'],
72 mode => 'http',
73 options => { 'stats' => ['uri /','auth puppet:puppet'], },
74 }
75 PUPPETCODE
76 it 'is able to listen on an array of ports' do
77 retry_on_error_matching do
78 apply_manifest(pp_two, catch_failures: true)
79 end
80 end
81
82 ['9090', '9091'].each do |port|
83 it "port #{port} has stats listening on each port" do
84 run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
85 expect(r.stdout).to contain %r{HAProxy}
86 expect(r.exit_code).to eq 0
87 end
88 end
89 end
90 end
91
92 describe 'with sort_options_alphabetic false' do
93 pp_three = <<-PUPPETCODE
94 class { 'haproxy::globals':
95 sort_options_alphabetic => false,
96 }
97 class { 'haproxy': }
98 haproxy::listen { 'stats':
99 ipaddress => '127.0.0.1',
100 ports => [9090,9091],
101 mode => 'http',
102 options => { 'stats' => ['uri /','auth puppet:puppet'], },
103 }
104 PUPPETCODE
105
106 it 'starts' do
107 retry_on_error_matching do
108 apply_manifest(pp_three, catch_failures: true)
109 end
110 end
111
112 ['9090', '9091'].each do |port|
113 it "port #{port} has stats listening on each port" do
114 run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r|
115 expect(r.stdout).to contain %r{HAProxy}
116 expect(r.exit_code).to eq 0
117 end
118 end
119 end
120 end
121
122 describe 'when "httpchk" option is defined and $sort_options_aphabetic => true' do
123 pp_httpchk_option = <<-PUPPETCODE
124 class { 'haproxy::globals':
125 sort_options_alphabetic => true,
126 }
127 class { 'haproxy': }
128 haproxy::listen { 'stats':
129 ipaddress => '127.0.0.1',
130 ports => [9091],
131 mode => 'http',
132 }
133 haproxy::backend { 'servers':
134 mode => 'http',
135 sort_options_alphabetic => true,
136 options => {
137 'option' => [
138 'httpchk',
139 ],
140 'http-check' => 'disable-on-404',
141 'server' => [
142 'srv1 127.0.0.1:9091 check',
143 ],
144 },
145 }
146 PUPPETCODE
147
148 it 'overrides $sort_options_aphabetic to false and warn' do
149 apply_manifest(pp_httpchk_option, catch_failures: true) do |r|
150 expect(r.stderr).to contain %r{Overriding\sthe\svalue\sof\s\$sort_options_alphabetic\sto\s"false"\sdue\sto\s"httpchk"\soption\sdefined}
151 end
152 end
153
154 describe file('/etc/haproxy/haproxy.cfg') do
155 its(:content) do
156 is_expected.to match %r{backend\sservers\n\s+mode\shttp\n\s+option\shttpchk\n\s+http-check\s+disable-on-404}
157 end
158 end
159 end
160 end
161
162 # C9934
163 describe 'uninstalling haproxy' do
164 pp_four = <<-PUPPETCODE
165 class { 'haproxy':
166 package_ensure => 'absent',
167 service_ensure => 'stopped',
168 }
169 PUPPETCODE
170 it 'removes it' do
171 retry_on_error_matching do
172 apply_manifest(pp_four, catch_failures: true)
173 end
174 end
175
176 describe package('haproxy') do
177 it { is_expected.not_to be_installed }
178 end
179 end
180
181 # C9935 C9939
182 describe 'disabling haproxy' do
183 pp_five = <<-PUPPETCODE
184 class { 'haproxy':
185 service_ensure => 'stopped',
186 }
187 haproxy::listen { 'stats':
188 ipaddress => '127.0.0.1',
189 ports => '9090',
190 }
191 PUPPETCODE
192 it 'stops the service' do
193 retry_on_error_matching do
194 apply_manifest(pp_five, catch_failures: true)
195 end
196 end
197
198 describe service('haproxy') do
199 it { is_expected.not_to be_running }
200 it { is_expected.not_to be_enabled }
201 end
202 end
203 end