From 3f92dfb365c46a81d673866c6baf98309ccec49d Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Mon, 3 Apr 2023 14:27:03 +0000 Subject: [PATCH] Use structured $facts hash syntax in spec tests --- spec/classes/agent_spec.rb | 22 +++++++++++----------- spec/classes/database_spec.rb | 2 +- spec/classes/javagateway_spec.rb | 2 +- spec/classes/sender_spec.rb | 2 +- spec/classes/server_spec.rb | 8 ++++---- spec/classes/web_spec.rb | 6 +++--- spec/defines/userparameters_spec.rb | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index 0f9b77c29..4169e08b7 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -16,7 +16,7 @@ on_supported_os(baseline_os_hash).each do |os, facts| context "on #{os}" do - config_path = case facts[:operatingsystem] + config_path = case facts[:os]['name'] when 'Fedora' '/etc/zabbix_agentd.conf' when 'windows' @@ -25,13 +25,13 @@ '/etc/zabbix/zabbix_agentd.conf' end - log_path = case facts[:operatingsystem] + log_path = case facts[:os]['name'] when 'windows' 'C:/ProgramData/zabbix/zabbix_agentd.log' else '/var/log/zabbix/zabbix_agentd.log' end - include_dir = case facts[:operatingsystem] + include_dir = case facts[:os]['name'] when 'windows' 'C:/ProgramData/zabbix/zabbix_agentd.d' else @@ -41,7 +41,7 @@ let(:facts) { facts } - case facts[:osfamily] + case facts[:os]['family'] when 'Gentoo' package_name = 'zabbix' service_name = 'zabbix-agentd' @@ -52,12 +52,12 @@ package_name = 'zabbix-agent' service_name = 'zabbix-agent' end - # package = facts[:osfamily] == 'Gentoo' ? 'zabbix' : 'zabbix-agent' - # service = facts[:osfamily] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent' + # package = facts[:os]['family'] == 'Gentoo' ? 'zabbix' : 'zabbix-agent' + # service = facts[:os]['family'] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent' context 'with all defaults' do # Make sure package will be installed, service running and ensure of directory. - if facts[:kernel] == 'windows' + if facts[:os]['name'] == 'windows' it do is_expected.to contain_package(package_name).with( ensure: '4.4.5', @@ -77,7 +77,7 @@ is_expected.to contain_service(service_name). with_ensure('running'). with_enable(true). - with_service_provider(facts[:osfamily] == 'AIX' ? 'init' : nil). + with_service_provider(facts[:os]['family'] == 'AIX' ? 'init' : nil). that_requires(["Package[#{package_name}]", "Zabbix::Startup[#{service_name}]"]) end @@ -95,7 +95,7 @@ } end - case facts[:osfamily] + case facts[:os]['family'] when 'Archlinux' it { is_expected.not_to compile.with_all_deps } when 'Debian' @@ -212,7 +212,7 @@ context 'it creates a startup script' do if facts[:kernel] == 'Linux' - case facts[:osfamily] + case facts[:os]['family'] when 'Archlinux', 'Debian', 'Gentoo', 'RedHat' it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('absent') } it { is_expected.to contain_file("/etc/systemd/system/#{service_name}.service").with_ensure('file') } @@ -409,7 +409,7 @@ end context 'when declaring manage_choco is false with zabbix_package_source specified' do - if facts[:kernel] == 'windows' + if facts[:os]['name'] == 'windows' let :params do { manage_choco: false, diff --git a/spec/classes/database_spec.rb b/spec/classes/database_spec.rb index 25349fba7..9fa476c1d 100644 --- a/spec/classes/database_spec.rb +++ b/spec/classes/database_spec.rb @@ -18,7 +18,7 @@ let :pre_condition do <<-EOS include 'postgresql::server' - if $::osfamily == 'Gentoo' { + if $facts['os']['family'] == 'Gentoo' { # We don't need the package to be installed as its the same for the server. class { 'mysql::client': package_manage => false, diff --git a/spec/classes/javagateway_spec.rb b/spec/classes/javagateway_spec.rb index 64c975980..096147ef3 100644 --- a/spec/classes/javagateway_spec.rb +++ b/spec/classes/javagateway_spec.rb @@ -35,7 +35,7 @@ } end - case facts[:osfamily] + case facts[:os]['family'] when 'Archlinux' it { is_expected.not_to compile } when 'RedHat' diff --git a/spec/classes/sender_spec.rb b/spec/classes/sender_spec.rb index e7ac5493b..772cfaeaa 100644 --- a/spec/classes/sender_spec.rb +++ b/spec/classes/sender_spec.rb @@ -31,7 +31,7 @@ } end - if %w[Archlinux Gentoo].include?(facts[:osfamily]) + if %w[Archlinux Gentoo].include?(facts[:os]['family']) it { is_expected.not_to compile.with_all_deps } else it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('5.0') } diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 5da1b15e7..641f11298 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -9,7 +9,7 @@ end on_supported_os(baseline_os_hash).each do |os, facts| - next if facts[:osfamily] == 'Archlinux' # zabbix server is currently not supported on archlinux + next if facts[:os]['family'] == 'Archlinux' # zabbix server is currently not supported on archlinux next if facts[:os]['name'] == 'windows' context "on #{os}" do @@ -24,7 +24,7 @@ it { is_expected.to contain_zabbix__startup('zabbix-server') } end - if facts[:osfamily] == 'RedHat' + if facts[:os]['family'] == 'RedHat' describe 'with enabled selinux' do let :params do { @@ -146,7 +146,7 @@ end context 'it creates a startup script' do - case facts[:osfamily] + case facts[:os]['family'] when 'Archlinux', 'Debian', 'Gentoo', 'RedHat' it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') } it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') } @@ -394,7 +394,7 @@ end # Zabbix Server 5.2 is not supported on RedHat family and Debian 11 - if facts[:osfamily] != 'RedHat' && facts[:os]['release']['major'] != '11' + if facts[:os]['family'] != 'RedHat' && facts[:os]['release']['major'] != '11' describe 'with zabbix_version 5.2 and Vault parameters defined' do let :params do { diff --git a/spec/classes/web_spec.rb b/spec/classes/web_spec.rb index fca7b2ed2..b23126b80 100644 --- a/spec/classes/web_spec.rb +++ b/spec/classes/web_spec.rb @@ -64,8 +64,8 @@ pgsqlpackage = 'php-pgsql' - packages = if facts[:osfamily] == 'RedHat' - if facts[:operatingsystemmajrelease].to_i == 7 && + packages = if facts[:os]['family'] == 'RedHat' + if facts[:os]['release']['major'].to_i == 7 && !%w[VirtuozzoLinux OracleLinux Scientific].include?(facts[:os]['name']) && Puppet::Util::Package.versioncmp(zabbix_version, '5.0') >= 0 %w[zabbix-web-pgsql-scl zabbix-web] @@ -89,7 +89,7 @@ mysqlpackage = 'php-mysql' - packages = facts[:osfamily] == 'RedHat' ? %w[zabbix-web-mysql zabbix-web] : ['zabbix-frontend-php', mysqlpackage] + packages = facts[:os]['family'] == 'RedHat' ? %w[zabbix-web-mysql zabbix-web] : ['zabbix-frontend-php', mysqlpackage] packages.each do |package| it { is_expected.to contain_package(package) } end diff --git a/spec/defines/userparameters_spec.rb b/spec/defines/userparameters_spec.rb index 9e8f66c52..8baef3f1c 100644 --- a/spec/defines/userparameters_spec.rb +++ b/spec/defines/userparameters_spec.rb @@ -11,8 +11,8 @@ let(:title) { 'mysqld' } let(:pre_condition) { 'class { "zabbix::agent": include_dir => "/etc/zabbix/zabbix_agentd.d" }' } - package = facts[:osfamily] == 'Gentoo' ? 'zabbix' : 'zabbix-agent' - service = facts[:osfamily] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent' + package = facts[:os]['family'] == 'Gentoo' ? 'zabbix' : 'zabbix-agent' + service = facts[:os]['family'] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent' context 'with an content' do let(:params) { { content: 'UserParameter=mysql.ping,mysqladmin -uroot ping | grep -c alive' } }