Skip to content

Commit c3898be

Browse files
authored
Merge pull request #871 from Phil-Friderici/coverage
Add unit tests to reach 100% resource coverage
2 parents 5ebefbd + 060bc62 commit c3898be

File tree

7 files changed

+65
-1
lines changed

7 files changed

+65
-1
lines changed

spec/classes/agent_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
# service = facts[:os]['family'] == 'Gentoo' ? 'zabbix-agentd' : 'zabbix-agent'
6161

6262
context 'with all defaults' do
63+
it { is_expected.to contain_selinux__module('zabbix-agent') } if facts[:os]['family'] == 'RedHat'
64+
it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
65+
it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
66+
it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian'
67+
it { is_expected.to contain_apt__key('zabbix-FBABD5F') } if facts[:os]['family'] == 'Debian'
68+
it { is_expected.to contain_file(include_dir).with_ensure('directory') }
69+
6370
# Make sure package will be installed, service running and ensure of directory.
6471
if facts[:os]['name'] == 'windows'
6572
it do
@@ -85,7 +92,6 @@
8592
that_requires(["Package[#{package_name}]", "Zabbix::Startup[#{service_name}]"])
8693
end
8794

88-
it { is_expected.to contain_file(include_dir).with_ensure('directory') }
8995
it { is_expected.to contain_zabbix__startup(service_name).that_requires("Package[#{package_name}]") }
9096
it { is_expected.to compile.with_all_deps }
9197
it { is_expected.to contain_class('zabbix::params') }
@@ -431,6 +437,16 @@
431437
end
432438
end
433439
end
440+
441+
describe 'with systemd active' do
442+
if facts[:kernel] == 'Linux'
443+
let :facts do
444+
super().merge(systemd: true)
445+
end
446+
447+
it { is_expected.to contain_systemd__unit_file('zabbix-agent.service') }
448+
end
449+
end
434450
end
435451
end
436452
end

spec/classes/database_mysql_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
}
5555
end
5656

57+
it { is_expected.to contain_class('zabbix::params') }
5758
it { is_expected.to contain_class('zabbix::database::mysql') }
5859
it { is_expected.to compile.with_all_deps }
5960
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f #{sql_server}.gz ]; then gunzip -f #{sql_server}.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -P 3306 -D 'zabbix-server' < #{sql_server} && touch /etc/zabbix/.schema.done") }
@@ -73,6 +74,7 @@
7374
}
7475
end
7576

77+
it { is_expected.to contain_class('zabbix::params') }
7678
it { is_expected.to contain_class('zabbix::database::mysql') }
7779
it { is_expected.to compile.with_all_deps }
7880
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f #{sql_server}.gz ]; then gunzip -f #{sql_server}.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < #{sql_server} && touch /etc/zabbix/.schema.done") }
@@ -95,6 +97,7 @@
9597
}
9698
end
9799

100+
it { is_expected.to contain_class('zabbix::params') }
98101
it { is_expected.to contain_class('zabbix::database::mysql') }
99102
it { is_expected.to compile.with_all_deps }
100103

@@ -117,6 +120,7 @@
117120
}
118121
end
119122

123+
it { is_expected.to contain_class('zabbix::params') }
120124
it { is_expected.to contain_class('zabbix::database::mysql') }
121125
it { is_expected.to compile.with_all_deps }
122126

spec/classes/javagateway_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
it { is_expected.to contain_service('zabbix-java-gateway').with_ensure('running') }
2727
it { is_expected.to contain_service('zabbix-java-gateway').with_enable('true') }
2828
it { is_expected.to contain_service('zabbix-java-gateway').with_require(['Package[zabbix-java-gateway]', 'File[/etc/zabbix/zabbix_java_gateway.conf]']) }
29+
30+
it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
31+
it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
32+
it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian'
33+
it { is_expected.to contain_apt__key('zabbix-FBABD5F') } if facts[:os]['family'] == 'Debian'
2934
end
3035

3136
context 'when declaring manage_repo is true' do

spec/classes/repo_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
it { is_expected.to contain_class('zabbix::params') }
2020
it { is_expected.to contain_class('zabbix::repo') }
2121

22+
it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian'
23+
it { is_expected.to contain_apt__key('zabbix-FBABD5F') } if facts[:os]['family'] == 'Debian'
24+
2225
context 'when repo_location is "https://example.com/foo"' do
2326
let :params do
2427
{
@@ -83,6 +86,7 @@
8386
it { is_expected.to contain_yumrepo('zabbix').with_gpgkey('https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-A14FE591') }
8487
it { is_expected.to contain_yumrepo('zabbix-nonsupported').with_baseurl('https://repo.zabbix.com/non-supported/rhel/7/$basearch/') }
8588
it { is_expected.to contain_yumrepo('zabbix-nonsupported').with_gpgkey('https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-79EA5ED4') }
89+
it { is_expected.to contain_yumrepo('zabbix-frontend') }
8690

8791
it { is_expected.to contain_package('zabbix-required-scl-repo').with_ensure('latest').with_name('centos-release-scl') } if facts[:os]['name'] == 'CentOS'
8892
it { is_expected.to contain_package('zabbix-required-scl-repo').with_ensure('latest').with_name('oracle-softwarecollection-release-el7') } if facts[:os]['name'] == 'OracleLinux'

spec/classes/sender_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
when 'RedHat'
4949
it { is_expected.to contain_yumrepo('zabbix-nonsupported') }
5050
it { is_expected.to contain_yumrepo('zabbix') }
51+
52+
it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['release']['major'] == '7'
53+
it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['release']['major'] == '7'
5154
when 'Debian'
5255
it { is_expected.to contain_apt__source('zabbix') }
5356
it { is_expected.to contain_apt__key('zabbix-A1848F5') }

spec/classes/server_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
it { is_expected.to contain_class('zabbix::params') }
2727
it { is_expected.to contain_service('zabbix-server').with_ensure('running') }
2828
it { is_expected.to contain_zabbix__startup('zabbix-server') }
29+
30+
it { is_expected.to contain_apt__source('zabbix') } if facts[:os]['family'] == 'Debian'
31+
it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian'
32+
it { is_expected.to contain_apt__key('zabbix-FBABD5F') } if facts[:os]['family'] == 'Debian'
2933
end
3034

3135
if facts[:os]['family'] == 'RedHat'
@@ -41,11 +45,16 @@
4145
end
4246

4347
it { is_expected.to contain_selboolean('zabbix_can_network').with('value' => 'on', 'persistent' => true) }
48+
it { is_expected.to contain_selinux__module('zabbix-server').with_ensure('present') }
49+
it { is_expected.to contain_selinux__module('zabbix-server-ipc').with_ensure('present') }
4450
end
4551

4652
describe 'with defaults' do
4753
it { is_expected.to contain_yumrepo('zabbix-nonsupported') }
4854
it { is_expected.to contain_yumrepo('zabbix') }
55+
56+
it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['release']['major'] == '7'
57+
it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['release']['major'] == '7'
4958
end
5059
end
5160

@@ -71,6 +80,8 @@
7180
it { is_expected.to contain_package('zabbix-server-pgsql').with_ensure('present') }
7281
it { is_expected.to contain_package('zabbix-server-pgsql').with_name('zabbix-server-pgsql') }
7382
it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-pgsql]') }
83+
it { is_expected.to contain_exec('update_pgpass') }
84+
it { is_expected.to contain_file('/root/.pgpass') }
7485
end
7586

7687
describe 'with database_type as mysql' do
@@ -83,6 +94,9 @@
8394
it { is_expected.to contain_package('zabbix-server-mysql').with_ensure('present') }
8495
it { is_expected.to contain_package('zabbix-server-mysql').with_name('zabbix-server-mysql') }
8596
it { is_expected.to contain_file('/etc/zabbix/zabbix_server.conf').with_require('Package[zabbix-server-mysql]') }
97+
it { is_expected.to contain_exec('zabbix_server_create.sql') }
98+
it { is_expected.to contain_exec('zabbix_server_data.sql') }
99+
it { is_expected.to contain_exec('zabbix_server_images.sql') }
86100
end
87101

88102
# Include directory should be available.
@@ -154,6 +168,7 @@
154168
when 'Archlinux', 'Debian', 'Gentoo', 'RedHat'
155169
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') }
156170
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') }
171+
it { is_expected.to contain_systemd__unit_file('zabbix-server.service') }
157172
else
158173
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('file') }
159174
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-server.service') }

spec/classes/web_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,22 @@
2727

2828
context 'with all defaults' do
2929
it { is_expected.to compile.with_all_deps }
30+
it { is_expected.to contain_class('Zabbix::Params') }
31+
it { is_expected.to contain_class('Zabbix::Repo') }
3032
it { is_expected.to contain_file('/etc/zabbix/web').with_ensure('directory') }
33+
34+
it { is_expected.to contain_apt__key('zabbix-A1848F5') } if facts[:os]['family'] == 'Debian'
35+
it { is_expected.to contain_apt__key('zabbix-FBABD5F') } if facts[:os]['family'] == 'Debian'
36+
it { is_expected.to contain_apt__source('zabbix') } if facts[:os]['family'] == 'Debian'
37+
it { is_expected.to contain_yumrepo('zabbix') } if facts[:os]['family'] == 'RedHat'
38+
it { is_expected.to contain_yumrepo('zabbix-nonsupported') } if facts[:os]['family'] == 'RedHat'
39+
it { is_expected.to contain_yumrepo('zabbix-frontend') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
40+
it { is_expected.to contain_package('zabbix-required-scl-repo') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
41+
it { is_expected.to contain_service('rh-php72-php-fpm') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
42+
it { is_expected.to contain_file('/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
43+
it { is_expected.to contain_file('/etc/zabbix/zabbix.conf.php') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7' && Puppet::Util::Package.versioncmp(zabbix_version, '5.0') >= 0
44+
it { is_expected.to contain_service('php-fpm') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] >= '8'
45+
it { is_expected.to contain_file('/etc/php-fpm.d/zabbix.conf') } if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] >= '8'
3146
end
3247

3348
describe 'with enforcing selinux' do
@@ -42,6 +57,8 @@
4257
end
4358

4459
it { is_expected.to contain_selboolean('httpd_can_connect_zabbix').with('value' => 'on', 'persistent' => true) }
60+
it { is_expected.to contain_selboolean('httpd_can_network_connect_db').with('value' => 'on', 'persistent' => true) }
61+
it { is_expected.to contain_apache__vhost('localhost') }
4562
end
4663

4764
describe 'with false selinux' do

0 commit comments

Comments
 (0)