diff --git a/.rubocop.yml b/.rubocop.yml index d6a394882..bb36ef980 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -57,6 +57,9 @@ Style/AndOr: Style/RedundantSelf: Enabled: True +Style/BlockLength: + Enabled: False + # Method length is not necessarily an indicator of code quality Metrics/MethodLength: Enabled: False diff --git a/.sync.yml b/.sync.yml index de5c7ea7f..679c95eb9 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,5 +1,3 @@ --- .travis.yml: secure: "ijm7hKPYWr1eg7151g5oK6MzZL4ojrgWjKlxgoBHXAdXdY88opMgvixfSJK5IMUbtanPfWRkqqABx+MYO78nfQBWDlghUzZ8sQXFeO2Ie0PgWl4nFV0kKWz+ejVaZC4dKSZlWha5pO1ek+sx7KnjIBZY82OXs/GXbjwhHx6d56YugXLuCyvfFxC7mXC9wF58bPwcYRCBSZt9CRl0OMBAFybxjdwsFMloRRhdz7f3hhlqF8Nrs1sxG1HhgiMcnrZqovNfb3Tw9K1RPYATazXxQrjcI7YHvJx0AvtHFUsn+/A0GtpKUuuPbaVdkYgE1Tye0AsAcey6RW4xhJywZglKrzDk7vfyUiU5CObeLh4/dhub3k111rDPL8v6v9t40fteduJoFLziHotQwdl37UALL7PwWZY5HuJvaBqHY2LsGs/ptGMB9ZCzxA85jfDw8lrZQ7P97SAoC34Ihs8D6vkKT9HUKHIXh19O5AAa70jReru0ej179IBjvs8m9nDwDNdY3sIsdhUU8WQ3BftDF6M8OzvgyLKDvjSs1Izag+Asl2Ze7RAQfQ2RvbfkDm9KEFnDQtXtzF4Cu1Ed6io2j1zI71JFQpIf6zb1qeNrhqulbJ15owGkQmHBgD8K+bDd1CCU4kA26axypV00XDsjfwdtFHgtUO3AlUVUim0QTMk9ATc=" -spec/spec_helper.rb: - spec_overrides: "require 'spec_helper_methods'" diff --git a/spec/classes/agent_spec.rb b/spec/classes/agent_spec.rb index 275e3275f..693664220 100644 --- a/spec/classes/agent_spec.rb +++ b/spec/classes/agent_spec.rb @@ -15,17 +15,19 @@ on_supported_os.each do |os, facts| context "on #{os} " do systemd_fact = case facts[:osfamily] - when 'Archlinux' + when 'Archlinux', 'Fedora' { systemd: true } else { systemd: false } end + config_path = case facts[:operatingsystem] + when 'Fedora' + '/etc/zabbix_agentd.conf' + else + '/etc/zabbix/zabbix_agentd.conf' + end let :facts do - facts.merge( - mocked_facts - ).merge( - systemd_fact - ) + facts.merge(systemd_fact) end context 'with all defaults' do @@ -56,6 +58,8 @@ it { should contain_file('/etc/zabbix/zabbix_agentd.d').with_ensure('directory') } it { should contain_zabbix__startup('zabbix-agent').that_requires("Package[#{package}]") } + it { should compile.with_all_deps } + it { should contain_class('zabbix::params') } end context 'when declaring manage_repo is true' do @@ -91,7 +95,19 @@ } end - it { should contain_file('/etc/zabbix/zabbix_agentd.conf').with_content %r{^HostnameItem=system.hostname$} } + it { should contain_file(config_path).with_content %r{^HostnameItem=system.hostname$} } + end + + context 'ignores hostnameitem if hostname is set' do + let :params do + { + hostname: 'test', + hostnameitem: 'system.hostname' + } + end + + it { should contain_file(config_path).without_content %r{^HostnameItem=system.hostname$} } + it { should contain_file(config_path).with_content %r{^Hostname=test$} } end context 'when declaring manage_firewall is true' do @@ -114,6 +130,16 @@ it { should_not contain_firewall('150 zabbix-agent') } end + context 'it creates a startup script' do + case facts[:osfamily] + when 'Archlinux', 'Fedora' + it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') } + it { should contain_file('/etc/systemd/system/zabbix-agent.service').with_ensure('file') } + else + it { should contain_file('/etc/init.d/zabbix-agent').with_ensure('file') } + it { should_not contain_file('/etc/systemd/system/zabbix-agent.service') } + end + end context 'configuration file with full options' do let :params do { diff --git a/spec/classes/database_mysql_spec.rb b/spec/classes/database_mysql_spec.rb index 2dfac61f8..e637c32bc 100644 --- a/spec/classes/database_mysql_spec.rb +++ b/spec/classes/database_mysql_spec.rb @@ -7,9 +7,7 @@ on_supported_os.each do |os, facts| context "on #{os} " do let :facts do - facts.merge( - mocked_facts - ) + facts end context 'with all defaults' do it 'fails' do diff --git a/spec/classes/sender_spec.rb b/spec/classes/sender_spec.rb index 60eb53830..89643925a 100644 --- a/spec/classes/sender_spec.rb +++ b/spec/classes/sender_spec.rb @@ -7,9 +7,7 @@ on_supported_os.each do |os, facts| context "on #{os} " do let :facts do - facts.merge( - mocked_facts - ) + facts end context 'with all defaults' do it { should contain_class('zabbix::sender') } diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 3328e3d4a..896386d27 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -20,11 +20,7 @@ { systemd: false } end let :facts do - facts.merge( - mocked_facts - ).merge( - systemd_fact - ) + facts.merge(systemd_fact) end describe 'with default settings' do diff --git a/spec/classes/userparameter_spec.rb b/spec/classes/userparameter_spec.rb index 3ba200e29..1aab7f7dc 100644 --- a/spec/classes/userparameter_spec.rb +++ b/spec/classes/userparameter_spec.rb @@ -7,9 +7,7 @@ on_supported_os.each do |os, facts| context "on #{os} " do let :facts do - facts.merge( - mocked_facts - ) + facts end context 'with all defaults' do it { should contain_class('zabbix::userparameter') } diff --git a/spec/classes/web_spec.rb b/spec/classes/web_spec.rb index 01c195588..cf078453d 100644 --- a/spec/classes/web_spec.rb +++ b/spec/classes/web_spec.rb @@ -17,9 +17,7 @@ def package_provider_for_gems on_supported_os.each do |os, facts| context "on #{os} " do let :facts do - facts.merge( - mocked_facts - ) + facts end if facts[:osfamily] == 'Archlinux' diff --git a/spec/defines/startup_spec.rb b/spec/defines/startup_spec.rb index b41974f4e..4bef94d5e 100644 --- a/spec/defines/startup_spec.rb +++ b/spec/defines/startup_spec.rb @@ -3,7 +3,7 @@ describe 'zabbix::startup', type: :define do # rubocop:disable RSpec/MultipleDescribes let(:title) { 'zabbix-agent' } - %w(RedHat Debian Gentoo).each do |osfamily| + %w(RedHat Debian Gentoo Archlinux).each do |osfamily| context "on #{osfamily}" do context 'on legacy init systems' do ['false', false].each do |systemd_fact_state| diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0df43ec63..2d8b16588 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,5 +12,4 @@ c.default_facts = default_facts end -require 'spec_helper_methods' # vim: syntax=ruby diff --git a/spec/spec_helper_methods.rb b/spec/spec_helper_methods.rb deleted file mode 100644 index 9d5d59192..000000000 --- a/spec/spec_helper_methods.rb +++ /dev/null @@ -1,7 +0,0 @@ -def mocked_facts - { - concat_basedir: '/tmp', - is_pe: false, - selinux_config_mode: 'disabled' - } -end