Skip to content

Commit fd96b69

Browse files
authored
Merge pull request #1014 from wyardley/wyardley/test_facts
Switch to string vs. symbols for facts in spec tests
2 parents 5d7f7dd + ba6260c commit fd96b69

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

.sync.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
spec/spec_helper.rb:
3-
spec_overrides: "require 'spec_helper_local'"
3+
facterdb_string_keys: true
44
mock_with: ':mocha'
5+
spec_overrides: "require 'spec_helper_local'"
56
.puppet-lint.rc:
67
enabled_lint_checks:
78
- parameter_documentation

spec/classes/rabbitmq_spec.rb

+24-24
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
os_facts
1010
end
1111

12-
name = case os_facts[:os]['family']
12+
name = case os_facts['os']['family']
1313
when 'Archlinux', 'OpenBSD', 'FreeBSD'
1414
'rabbitmq'
1515
else
1616
'rabbitmq-server'
1717
end
1818

19-
rabbitmq_home = case os_facts[:os]['family']
19+
rabbitmq_home = case os_facts['os']['family']
2020
when 'FreeBSD'
2121
'/var/db/rabbitmq'
2222
else
@@ -30,7 +30,7 @@
3030

3131
it { is_expected.to contain_package(name).with_ensure('installed').with_name(name) }
3232

33-
it { is_expected.to contain_package('rabbitmq-server-plugins') } if os_facts[:os]['family'] == 'Suse'
33+
it { is_expected.to contain_package('rabbitmq-server-plugins') } if os_facts['os']['family'] == 'Suse'
3434

3535
context 'with default params' do
3636
it { is_expected.not_to contain_class('rabbitmq::repo::apt') }
@@ -48,7 +48,7 @@
4848
context 'with repos_ensure => true' do
4949
let(:params) { { repos_ensure: true } }
5050

51-
if os_facts[:os]['family'] == 'Debian'
51+
if os_facts['os']['family'] == 'Debian'
5252
it 'includes rabbitmq::repo::apt' do
5353
is_expected.to contain_class('rabbitmq::repo::apt').
5454
with_key_source('https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey').
@@ -58,7 +58,7 @@
5858
it 'adds a repo with default values' do
5959
is_expected.to contain_apt__source('rabbitmq').
6060
with_ensure('present').
61-
with_location("https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts[:os]['name'].downcase}").
61+
with_location("https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts['os']['name'].downcase}").
6262
with_release(nil).
6363
with_repos('main')
6464
end
@@ -67,7 +67,7 @@
6767
it { is_expected.not_to contain_apt__souce('rabbitmq') }
6868
end
6969

70-
if os_facts[:os]['family'] == 'RedHat'
70+
if os_facts['os']['family'] == 'RedHat'
7171
it { is_expected.to contain_class('rabbitmq::repo::rhel') }
7272

7373
it 'the repo should be present, and contain the expected values' do
@@ -82,27 +82,27 @@
8282
end
8383
end
8484

85-
context 'with no pin', if: os_facts[:os]['family'] == 'Debian' do
85+
context 'with no pin', if: os_facts['os']['family'] == 'Debian' do
8686
let(:params) { { repos_ensure: true, package_apt_pin: '' } }
8787

8888
describe 'it sets up an apt::source' do
8989
it {
9090
is_expected.to contain_apt__source('rabbitmq').with(
91-
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts[:os]['name'].downcase}",
91+
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts['os']['name'].downcase}",
9292
'repos' => 'main',
9393
'key' => '{"id"=>"8C695B0219AFDEB04A058ED8F4E789204D206F89", "source"=>"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey", "content"=>nil}'
9494
)
9595
}
9696
end
9797
end
9898

99-
context 'with pin', if: os_facts[:os]['family'] == 'Debian' do
99+
context 'with pin', if: os_facts['os']['family'] == 'Debian' do
100100
let(:params) { { repos_ensure: true, package_apt_pin: '700' } }
101101

102102
describe 'it sets up an apt::source and pin' do
103103
it {
104104
is_expected.to contain_apt__source('rabbitmq').with(
105-
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts[:os]['name'].downcase}",
105+
'location' => "https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts['os']['name'].downcase}",
106106
'repos' => 'main',
107107
'key' => '{"id"=>"8C695B0219AFDEB04A058ED8F4E789204D206F89", "source"=>"https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey", "content"=>nil}'
108108
)
@@ -122,7 +122,7 @@
122122
context "with file_limit => '#{value}'", if: os_facts['kernel'] == 'Linux' do
123123
let(:params) { { file_limit: value } }
124124

125-
selinux_ignore_defaults = os_facts[:os]['family'] == 'RedHat'
125+
selinux_ignore_defaults = os_facts['os']['family'] == 'RedHat'
126126

127127
it do
128128
is_expected.to contain_systemd__manage_dropin('service-90-limits.conf').
@@ -143,7 +143,7 @@
143143
end
144144

145145
[-1000, 0, 1000].each do |value|
146-
context "with oom_score_adj => '#{value}'", if: os_facts[:kernel] == 'Linux' do
146+
context "with oom_score_adj => '#{value}'", if: os_facts['kernel'] == 'Linux' do
147147
let(:params) { { oom_score_adj: value } }
148148

149149
it { is_expected.to contain_systemd__manage_dropin('service-90-limits.conf').with_service_entry({ 'LimitNOFILE' => 16_384, 'OOMScoreAdjust' => value }) }
@@ -160,11 +160,11 @@
160160
end
161161
end
162162

163-
context 'on Linux', if: os_facts[:kernel] == 'Linux' do
163+
context 'on Linux', if: os_facts['kernel'] == 'Linux' do
164164
it { is_expected.to contain_systemd__manage_dropin('service-90-limits.conf') }
165165
end
166166

167-
context 'on non-Linux', unless: os_facts[:kernel] == 'Linux' do
167+
context 'on non-Linux', unless: os_facts['kernel'] == 'Linux' do
168168
it { is_expected.not_to contain_systemd__manage_dropin('service-90-limits.conf') }
169169
end
170170

@@ -190,9 +190,9 @@
190190
is_expected.to contain_archive('rabbitmqadmin').with_source('http://1.1.1.1:15672/cli/rabbitmqadmin')
191191
end
192192

193-
it { is_expected.to contain_package('python') } if %w[RedHat SUSE Archlinux].include?(os_facts[:os]['family'])
194-
it { is_expected.to contain_package('python3') } if %w[Debian].include?(os_facts[:os]['family'])
195-
it { is_expected.to contain_package('python38') } if %w[FreeBSD].include?(os_facts[:os]['family'])
193+
it { is_expected.to contain_package('python') } if %w[RedHat SUSE Archlinux].include?(os_facts['os']['family'])
194+
it { is_expected.to contain_package('python3') } if %w[Debian].include?(os_facts['os']['family'])
195+
it { is_expected.to contain_package('python38') } if %w[FreeBSD].include?(os_facts['os']['family'])
196196
end
197197

198198
context 'with manage_python false' do
@@ -205,7 +205,7 @@
205205
end
206206
end
207207

208-
context 'with $management_ip_address undef and service_manage set to true', unless: os_facts[:os]['family'] == 'Archlinux' do
208+
context 'with $management_ip_address undef and service_manage set to true', unless: os_facts['os']['family'] == 'Archlinux' do
209209
let(:params) { { admin_enable: true, management_ip_address: :undef } }
210210

211211
it 'we enable the admin interface by default' do
@@ -217,7 +217,7 @@
217217
end
218218
end
219219

220-
context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified', unless: os_facts[:os]['family'] == 'Archlinux' do
220+
context 'with service_manage set to true, node_ip_address = undef, and default user/pass specified', unless: os_facts['os']['family'] == 'Archlinux' do
221221
let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', node_ip_address: :undef } }
222222

223223
it 'we use the correct URL to rabbitmqadmin' do
@@ -229,7 +229,7 @@
229229
end
230230
end
231231

232-
context 'with service_manage set to true and default user/pass specified', unless: os_facts[:os]['family'] == 'Archlinux' do
232+
context 'with service_manage set to true and default user/pass specified', unless: os_facts['os']['family'] == 'Archlinux' do
233233
let(:params) { { admin_enable: true, default_user: 'foobar', default_pass: 'hunter2', management_ip_address: '1.1.1.1' } }
234234

235235
it 'we use the correct URL to rabbitmqadmin' do
@@ -241,7 +241,7 @@
241241
end
242242
end
243243

244-
context 'with service_manage set to true and archive_options set', unless: os_facts[:os]['family'] == 'Archlinux' do
244+
context 'with service_manage set to true and archive_options set', unless: os_facts['os']['family'] == 'Archlinux' do
245245
let(:params) do
246246
{
247247
admin_enable: true,
@@ -258,7 +258,7 @@
258258
end
259259
end
260260

261-
context 'with service_manage set to true and management port specified', unless: os_facts[:os]['family'] == 'Archlinux' do
261+
context 'with service_manage set to true and management port specified', unless: os_facts['os']['family'] == 'Archlinux' do
262262
# NOTE: that the 2.x management port is 55672 not 15672
263263
let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '1.1.1.1' } }
264264

@@ -271,7 +271,7 @@
271271
end
272272
end
273273

274-
context 'with ipv6, service_manage set to true and management port specified', unless: os_facts[:os]['family'] == 'Archlinux' do
274+
context 'with ipv6, service_manage set to true and management port specified', unless: os_facts['os']['family'] == 'Archlinux' do
275275
# NOTE: that the 2.x management port is 55672 not 15672
276276
let(:params) { { admin_enable: true, management_port: 55_672, management_ip_address: '::1' } }
277277

@@ -476,7 +476,7 @@
476476
describe 'rabbitmq-env configuration' do
477477
context 'with default params' do
478478
it 'sets environment variables' do
479-
if %w[FreeBSD OpenBSD].include?(os_facts[:os]['family'])
479+
if %w[FreeBSD OpenBSD].include?(os_facts['os']['family'])
480480
is_expected.to contain_file('rabbitmq-env.config'). \
481481
with_content(%r{ERL_INETRC=/usr/local/etc/rabbitmq/inetrc})
482482
else

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require 'voxpupuli/test/spec_helper'
1111

1212
RSpec.configure do |c|
13-
c.facterdb_string_keys = false
13+
c.facterdb_string_keys = true
1414
c.mock_with :mocha
1515
end
1616

0 commit comments

Comments
 (0)