Skip to content

Commit

Permalink
Use structured $facts hash syntax in spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Friderici committed Apr 3, 2023
1 parent 52576bb commit 3f92dfb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -41,7 +41,7 @@

let(:facts) { facts }

case facts[:osfamily]
case facts[:os]['family']
when 'Gentoo'
package_name = 'zabbix'
service_name = 'zabbix-agentd'
Expand All @@ -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',
Expand All @@ -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

Expand All @@ -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'
Expand Down Expand Up @@ -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') }
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/javagateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}
end

case facts[:osfamily]
case facts[:os]['family']
when 'Archlinux'
it { is_expected.not_to compile }
when 'RedHat'
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down
8 changes: 4 additions & 4 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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') }
Expand Down Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions spec/classes/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/userparameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }
Expand Down

0 comments on commit 3f92dfb

Please sign in to comment.