Skip to content

Commit

Permalink
Fix rspec tests for Gentoo
Browse files Browse the repository at this point in the history
Due to the release of facterdb 0.6.0 we're now testing against Gentoo as
well. This leads to a couple of errors which this commit fixes.

Strict variable checking was disabled until
puppetlabs/puppetlabs-mysql#1147 got merged.
  • Loading branch information
baurmatt committed Dec 17, 2018
1 parent 1a8808e commit 8ecaf68
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ matrix:
include:
- rvm: 2.1.9
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=12
env: STRICT_VARIABLES=no PUPPET_VERSION="~> 4.0" CHECK=test PARALLEL_TEST_PROCESSORS=12
- rvm: 2.4.4
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 5.0" CHECK=test
env: STRICT_VARIABLES=no PUPPET_VERSION="~> 5.0" CHECK=test
- rvm: 2.5.1
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls
env: STRICT_VARIABLES=no PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls
- rvm: 2.5.1
bundler_args: --without system_tests development release
env: PUPPET_VERSION="~> 6.0" CHECK=rubocop
Expand Down
4 changes: 2 additions & 2 deletions manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@
) inherits zabbix::params {

# check osfamily, Arch is currently not supported for web
if $facts['os']['family'] == 'Archlinux' {
fail('Archlinux is currently not supported for zabbix::web ')
if $facts['os']['family'] in [ 'Archlinux', 'Gentoo', ] {
fail("${facts['os']['family']} is currently not supported for zabbix::web")
}

# Only include the repo class if it has not yet been included
Expand Down
36 changes: 22 additions & 14 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
on_supported_os.each do |os, facts|
context "on #{os} " do
systemd_fact = case facts[:osfamily]
when 'Archlinux', 'Fedora'
when 'Archlinux', 'Fedora', 'Gentoo'
{ systemd: true }
else
{ systemd: false }
Expand All @@ -29,30 +29,38 @@
let :facts do
facts.merge(systemd_fact)
end
if facts[:osfamily] == 'Gentoo'
package_name = 'zabbix'
service_name = 'zabbix-agentd'
else
package_name = 'zabbix-agent'
service_name = 'zabbix-agent'
end
#package = facts[:osfamily] == 'Gentoo' ? 'zabbix' : 'zabbix-agent'
#service = facts[:osfamily] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent'

context 'with all defaults' do
package = 'zabbix-agent'
# Make sure package will be installed, service running and ensure of directory.
it do
is_expected.to contain_package(package).with(
is_expected.to contain_package(package_name).with(
ensure: 'present',
require: 'Class[Zabbix::Repo]',
tag: 'zabbix'
)
end

it do
is_expected.to contain_service('zabbix-agent').with(
is_expected.to contain_service(service_name).with(
ensure: 'running',
enable: true,
hasstatus: true,
hasrestart: true,
require: "Package[#{package}]"
require: "Package[#{package_name}]"
)
end

it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') }
it { is_expected.to contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") }
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('zabbix::params') }
end
Expand Down Expand Up @@ -135,12 +143,12 @@

context 'it creates a startup script' do
case facts[:osfamily]
when 'Archlinux', 'Fedora'
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-agent.service').with_ensure('file') }
when 'Archlinux', 'Fedora', 'Gentoo'
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') }
else
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('file') }
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-agent.service') }
it { is_expected.to contain_file("/etc/init.d/#{service_name}").with_ensure('file') }
it { is_expected.not_to contain_file("/etc/systemd/system/#{service_name}.service") }
end
end

Expand All @@ -151,7 +159,7 @@
}
end

it { is_expected.not_to contain_zabbix__startup('zabbix-agent') }
it { is_expected.not_to contain_zabbix__startup(service_name) }
end

context 'when declaring zabbix_alias' do
Expand Down Expand Up @@ -265,10 +273,10 @@
end

it do
is_expected.to contain_service('zabbix-agent').with(
is_expected.to contain_service(service_name).with(
ensure: 'stopped',
enable: false,
require: "Package[#{package}]"
require: "Package[#{package_name}]"
)
end
end
Expand Down
19 changes: 14 additions & 5 deletions spec/classes/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
'rspec.puppet.com'
end

let :pre_condition do
"include 'postgresql::server'
include 'mysql::server'"
end

on_supported_os.each do |os, facts|
context "on #{os} " do
let :facts do
facts
end

let :pre_condition do
<<-EOS
include 'postgresql::server'
if $::osfamily == 'Gentoo' {
# We don't need the package to be installed as its the same for the server.
class { 'mysql::client':
package_manage => false,
}
}
include 'mysql::server'
EOS
end


describe 'database_type is postgresql, zabbix_type is server and is multiple host setup' do
let :params do
{
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
}
end

if facts[:osfamily] == 'Archlinux'
if ['Archlinux', 'Gentoo'].include?(facts[:osfamily])
it 'fails' do
is_expected.to raise_error(Puppet::Error, %r{Managing a repo on Archlinux is currently not implemented})
is_expected.to raise_error(Puppet::Error, %r{Managing a repo on #{facts[:osfamily]} is currently not implemented})
end
else
it { is_expected.to contain_class('zabbix::repo').with_zabbix_version('3.4') }
Expand Down
10 changes: 8 additions & 2 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
on_supported_os.each do |os, facts|
next if facts[:osfamily] == 'Archlinux' # zabbix server is currently not supported on archlinux
context "on #{os} " do
systemd_fact = case facts[:osfamily]
when 'Archlinux', 'Fedora', 'Gentoo'
{ systemd: true }
else
{ systemd: false }
end
let :facts do
facts
facts.merge(systemd_fact)
end

describe 'with default settings' do
Expand Down Expand Up @@ -128,7 +134,7 @@

context 'it creates a startup script' do
case facts[:osfamily]
when 'Archlinux', 'Fedora'
when 'Archlinux', 'Fedora', 'Gentoo'
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') }
else
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
facts
end

if facts[:osfamily] == 'Archlinux'
if facts[:osfamily] == 'Archlinux' or facts[:osfamily] == 'Gentoo'
context 'with all defaults' do
it { is_expected.not_to compile }
end
Expand Down
12 changes: 7 additions & 5 deletions spec/defines/userparameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
context "on #{os} " do
let :facts do
systemd_fact = case facts[:os]['family']
when 'Archlinux', 'Fedora'
when 'Archlinux', 'Fedora', 'Gentoo'
{ systemd: true }
else
{ systemd: false }
Expand All @@ -14,6 +14,8 @@
end
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'

context 'with an content' do
let(:params) { { content: 'UserParameter=mysql.ping,mysqladmin -uroot ping | grep -c alive' } }
Expand All @@ -23,12 +25,12 @@
it { is_expected.to contain_class('zabbix::params') }
it { is_expected.to contain_class('zabbix::repo') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file('/etc/init.d/zabbix-agent') }
it { is_expected.to contain_file("/etc/init.d/#{service}") }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.conf') }
it { is_expected.to contain_file('/etc/zabbix/zabbix_agentd.d') }
it { is_expected.to contain_package('zabbix-agent') }
it { is_expected.to contain_service('zabbix-agent') }
it { is_expected.to contain_zabbix__startup('zabbix-agent') }
it { is_expected.to contain_package(package) }
it { is_expected.to contain_service(service) }
it { is_expected.to contain_zabbix__startup(service) }
end
end
end
Expand Down

0 comments on commit 8ecaf68

Please sign in to comment.