From 08b4310e98b28df9c95e578035a9c4132601d5ed Mon Sep 17 00:00:00 2001 From: Tames McTigue Date: Fri, 29 Mar 2024 12:32:58 +0300 Subject: [PATCH 1/2] Enable unit tests for Windows --- manifests/forwarder/config.pp | 8 ++-- spec/classes/forwarder_spec.rb | 85 +++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/manifests/forwarder/config.pp b/manifests/forwarder/config.pp index 9b5eb63a..5c145a2b 100644 --- a/manifests/forwarder/config.pp +++ b/manifests/forwarder/config.pp @@ -31,9 +31,11 @@ } # Remove init.d file if the service provider is systemd - if $facts['service_provider'] == 'systemd' and versioncmp($splunk::forwarder::version, '7.2.2') >= 0 { - file { '/etc/init.d/splunk': - ensure => 'absent', + if $facts['os']['name'] != 'windows' { + if $facts['service_provider'] == 'systemd' and versioncmp($splunk::forwarder::version, '7.2.2') >= 0 { + file { '/etc/init.d/splunk': + ensure => 'absent', + } } } diff --git a/spec/classes/forwarder_spec.rb b/spec/classes/forwarder_spec.rb index fe763296..e85b5fac 100644 --- a/spec/classes/forwarder_spec.rb +++ b/spec/classes/forwarder_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' shared_examples_for 'splunk forwarder' do - it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('splunk') } it { is_expected.to contain_class('splunk::params') } it { is_expected.to contain_class('splunk::forwarder') } @@ -11,31 +10,51 @@ it { is_expected.to contain_class('splunk::forwarder::config') } it { is_expected.to contain_class('splunk::forwarder::service') } it { is_expected.to contain_splunk_config('splunk') } - it { is_expected.to contain_package('splunkforwarder').with(ensure: 'installed') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/deploymentclient.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/outputs.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/inputs.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/limits.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/props.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/transforms.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/web.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/limits.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/server.conf') } it { is_expected.to contain_splunkforwarder_web('forwarder_splunkd_port').with(value: '127.0.0.1:8089') } - it { is_expected.not_to contain_file('/opt/splunkforwarder/etc/splunk.secret') } - it { is_expected.not_to contain_file('/opt/splunkforwarder/etc/passwd') } end describe 'splunk::forwarder' do context 'supported operating systems' do on_supported_os.each do |os, facts| - next if facts[:os]['name'] == 'windows' # Splunk Server not used supported on windows context "on #{os}" do let(:facts) do facts end + if facts[:os]['name'] == 'windows' + let(:facts) do + facts.merge(facts.merge(archive_windir: 'C:\\ProgramData\\Staging')) + end + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_package('UniversalForwarder').with(ensure: 'installed') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/deploymentclient.conf')} + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/outputs.conf') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/inputs.conf') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/limits.conf') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/props.conf') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/transforms.conf') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/web.conf') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/limits.conf') } + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/server.conf') } + it { is_expected.not_to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/splunk.secret') } + it { is_expected.not_to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/passwd') } + else + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_package('splunkforwarder').with(ensure: 'installed') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/deploymentclient.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/outputs.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/inputs.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/limits.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/props.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/transforms.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/web.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/limits.conf') } + it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/server.conf') } + it { is_expected.not_to contain_file('/opt/splunkforwarder/etc/splunk.secret') } + it { is_expected.not_to contain_file('/opt/splunkforwarder/etc/passwd') } + end + context 'splunk when including forwarder and enterprise' do let(:pre_condition) do 'include splunk::enterprise' @@ -245,15 +264,17 @@ end it_behaves_like 'splunk forwarder' - it do - is_expected.to contain_exec('splunk-forwarder-accept-tos').with( - command: accept_tos_command, - user: 'root', - before: "Service[#{service_name}]", - subscribe: nil, - require: 'Exec[enable_splunkforwarder]', - refreshonly: 'true' - ) + if facts[:os]['name'] != 'windows' + it do + is_expected.to contain_exec('splunk-forwarder-accept-tos').with( + command: accept_tos_command, + user: 'root', + before: "Service[#{service_name}]", + subscribe: nil, + require: 'Exec[enable_splunkforwarder]', + refreshonly: 'true' + ) + end end end @@ -273,14 +294,16 @@ it_behaves_like 'splunk forwarder' it do - is_expected.to contain_exec('splunk-forwarder-accept-tos').with( - command: accept_tos_command, - user: 'root', - before: "Service[#{service_name}]", - subscribe: 'Package[splunkforwarder]', - require: 'Exec[enable_splunkforwarder]', - refreshonly: 'true' - ) + if facts[:os]['name'] != 'windows' + is_expected.to contain_exec('splunk-forwarder-accept-tos').with( + command: accept_tos_command, + user: 'root', + before: "Service[#{service_name}]", + subscribe: 'Package[splunkforwarder]', + require: 'Exec[enable_splunkforwarder]', + refreshonly: 'true' + ) + end end context 'when $splunk::params::manage_net_tools == false' do From a1ec0164df56b22387287867d13aa8f1e9416cd2 Mon Sep 17 00:00:00 2001 From: Tames McTigue Date: Fri, 29 Mar 2024 12:44:54 +0300 Subject: [PATCH 2/2] Fixed linting warnings and errors --- spec/classes/forwarder_spec.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/spec/classes/forwarder_spec.rb b/spec/classes/forwarder_spec.rb index e85b5fac..f7be0aa3 100644 --- a/spec/classes/forwarder_spec.rb +++ b/spec/classes/forwarder_spec.rb @@ -16,7 +16,6 @@ describe 'splunk::forwarder' do context 'supported operating systems' do on_supported_os.each do |os, facts| - context "on #{os}" do let(:facts) do facts @@ -26,21 +25,18 @@ let(:facts) do facts.merge(facts.merge(archive_windir: 'C:\\ProgramData\\Staging')) end - it { is_expected.to compile.with_all_deps } it { is_expected.to contain_package('UniversalForwarder').with(ensure: 'installed') } - it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/deploymentclient.conf')} + it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/deploymentclient.conf') } it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/outputs.conf') } it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/inputs.conf') } it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/limits.conf') } it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/props.conf') } it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/transforms.conf') } it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/web.conf') } - it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/limits.conf') } it { is_expected.to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/system/local/server.conf') } it { is_expected.not_to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/splunk.secret') } it { is_expected.not_to contain_file('C:\\Program Files\\SplunkUniversalForwarder/etc/passwd') } else - it { is_expected.to compile.with_all_deps } it { is_expected.to contain_package('splunkforwarder').with(ensure: 'installed') } it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/deploymentclient.conf') } it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/outputs.conf') } @@ -49,11 +45,11 @@ it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/props.conf') } it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/transforms.conf') } it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/web.conf') } - it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/limits.conf') } it { is_expected.to contain_file('/opt/splunkforwarder/etc/system/local/server.conf') } it { is_expected.not_to contain_file('/opt/splunkforwarder/etc/splunk.secret') } it { is_expected.not_to contain_file('/opt/splunkforwarder/etc/passwd') } end + it { is_expected.to compile.with_all_deps } context 'splunk when including forwarder and enterprise' do let(:pre_condition) do