From ba6260c651279000e6abd6a9934ea6b117a5666a Mon Sep 17 00:00:00 2001 From: William Yardley Date: Thu, 5 Sep 2024 22:09:47 -0700 Subject: [PATCH] Switch to string vs. symbols for facts in spec tests Set `facterdb_string_keys` to `true` and update to string versions of facts in our spec tests. Update `.sync.yml` so that modulesync doesn't override this while the default is still `false` --- .sync.yml | 3 ++- spec/classes/rabbitmq_spec.rb | 48 +++++++++++++++++------------------ spec/spec_helper.rb | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.sync.yml b/.sync.yml index 86466159e..c266ecde2 100644 --- a/.sync.yml +++ b/.sync.yml @@ -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 diff --git a/spec/classes/rabbitmq_spec.rb b/spec/classes/rabbitmq_spec.rb index f2799420d..4e81698ce 100644 --- a/spec/classes/rabbitmq_spec.rb +++ b/spec/classes/rabbitmq_spec.rb @@ -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 @@ -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') } @@ -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'). @@ -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 @@ -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 @@ -82,13 +82,13 @@ 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}' ) @@ -96,13 +96,13 @@ 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}' ) @@ -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'). @@ -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 }) } @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, @@ -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' } } @@ -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' } } @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b5dce9ebf..5ce539df6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,7 +10,7 @@ require 'voxpupuli/test/spec_helper' RSpec.configure do |c| - c.facterdb_string_keys = false + c.facterdb_string_keys = true c.mock_with :mocha end