Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unit tests for Windows #370

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions manifests/forwarder/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
}
}

Expand Down
83 changes: 51 additions & 32 deletions spec/classes/forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,54 @@
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') }
it { is_expected.to contain_class('splunk::forwarder::install') }
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 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/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 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/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
'include splunk::enterprise'
Expand Down Expand Up @@ -245,15 +260,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

Expand All @@ -273,14 +290,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
Expand Down