Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to string vs. symbols for facts in spec tests #1014

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .sync.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
spec/spec_helper.rb:
spec_overrides: "require 'spec_helper_local'"
facterdb_string_keys: true
mock_with: ':mocha'
spec_overrides: "require 'spec_helper_local'"
.puppet-lint.rc:
enabled_lint_checks:
- parameter_documentation
Expand Down
48 changes: 24 additions & 24 deletions spec/classes/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
os_facts
end

name = case os_facts[:os]['family']
name = case os_facts['os']['family']
when 'Archlinux', 'OpenBSD', 'FreeBSD'
'rabbitmq'
else
'rabbitmq-server'
end

rabbitmq_home = case os_facts[:os]['family']
rabbitmq_home = case os_facts['os']['family']
when 'FreeBSD'
'/var/db/rabbitmq'
else
Expand All @@ -30,7 +30,7 @@

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

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

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

if os_facts[:os]['family'] == 'Debian'
if os_facts['os']['family'] == 'Debian'
it 'includes rabbitmq::repo::apt' do
is_expected.to contain_class('rabbitmq::repo::apt').
with_key_source('https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey').
Expand All @@ -58,7 +58,7 @@
it 'adds a repo with default values' do
is_expected.to contain_apt__source('rabbitmq').
with_ensure('present').
with_location("https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts[:os]['name'].downcase}").
with_location("https://packagecloud.io/rabbitmq/rabbitmq-server/#{os_facts['os']['name'].downcase}").
with_release(nil).
with_repos('main')
end
Expand All @@ -67,7 +67,7 @@
it { is_expected.not_to contain_apt__souce('rabbitmq') }
end

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

it 'the repo should be present, and contain the expected values' do
Expand All @@ -82,27 +82,27 @@
end
end

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

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

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

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

selinux_ignore_defaults = os_facts[:os]['family'] == 'RedHat'
selinux_ignore_defaults = os_facts['os']['family'] == 'RedHat'

it do
is_expected.to contain_systemd__manage_dropin('service-90-limits.conf').
Expand All @@ -143,7 +143,7 @@
end

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

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

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

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

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

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

context 'with manage_python false' do
Expand All @@ -205,7 +205,7 @@
end
end

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

it 'we enable the admin interface by default' do
Expand All @@ -217,7 +217,7 @@
end
end

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

it 'we use the correct URL to rabbitmqadmin' do
Expand All @@ -229,7 +229,7 @@
end
end

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

it 'we use the correct URL to rabbitmqadmin' do
Expand All @@ -241,7 +241,7 @@
end
end

context 'with service_manage set to true and archive_options set', unless: os_facts[:os]['family'] == 'Archlinux' do
context 'with service_manage set to true and archive_options set', unless: os_facts['os']['family'] == 'Archlinux' do
let(:params) do
{
admin_enable: true,
Expand All @@ -258,7 +258,7 @@
end
end

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

Expand All @@ -271,7 +271,7 @@
end
end

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

Expand Down Expand Up @@ -476,7 +476,7 @@
describe 'rabbitmq-env configuration' do
context 'with default params' do
it 'sets environment variables' do
if %w[FreeBSD OpenBSD].include?(os_facts[:os]['family'])
if %w[FreeBSD OpenBSD].include?(os_facts['os']['family'])
is_expected.to contain_file('rabbitmq-env.config'). \
with_content(%r{ERL_INETRC=/usr/local/etc/rabbitmq/inetrc})
else
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'voxpupuli/test/spec_helper'

RSpec.configure do |c|
c.facterdb_string_keys = false
wyardley marked this conversation as resolved.
Show resolved Hide resolved
c.facterdb_string_keys = true
c.mock_with :mocha
end

Expand Down
Loading