Skip to content

Commit

Permalink
Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
deric authored and bastelfreak committed Aug 25, 2022
1 parent dbf10b3 commit 1d107ee
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions spec/classes/telegraf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
facts
end

let(:config_dir) do
case facts[:osfamily]
when 'Darwin'
'/usr/local/etc/telegraf'
when 'FreeBSD'
'/usr/local/etc'
when 'windows'
'C:/Program Files/telegraf'
else
'/etc/telegraf'
end
end
let(:main_config) { "#{config_dir}/telegraf.conf" }

context 'default include'
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('telegraf::config') }
Expand Down Expand Up @@ -143,6 +157,7 @@
repo_location: 'https://repos.influxdata.com/'
)
end

it do
is_expected.to contain_class('telegraf').without(
%w[
Expand All @@ -154,33 +169,24 @@
end
end

config_dir = case facts[:kernel]
when 'windows'
'C:/Program Files/telegraf'
when 'Darwin'
'/usr/local/etc/telegraf'
else
'/etc/telegraf'
end
main_config = "#{config_dir}/telegraf.conf"

it { is_expected.to contain_telegraf__processor('rename_processor') }
it { is_expected.to contain_file(main_config).with_ensure('file') }

it {
is_expected.to contain_file("#{config_dir}/telegraf.d").
with_purge(false)
}

it {
is_expected.to contain_file("#{config_dir}/telegraf.d/rename_processor.conf").\
with_content(<<-STRING
[[processors.rename]]
namepass = ["diskio"]
order = 1
[processors.rename.replace]
dest = "bar"
tag = "foo"
STRING
with_content(<<~STRING
[[processors.rename]]
namepass = ["diskio"]
order = 1
[processors.rename.replace]
dest = "bar"
tag = "foo"
STRING
)
}

Expand Down Expand Up @@ -305,22 +311,12 @@
when 'windows'
is_expected.to contain_package('telegraf').with(ensure: 'absent')
end
dir = case facts[:osfamily]
when 'Darwin'
'/usr/local/etc/telegraf'
when 'FreeBSD'
'/usr/local/etc'
when 'windows'
'C:/Program Files/telegraf'
else
'/etc/telegraf'
end

is_expected.to contain_file("#{dir}/telegraf.conf").with(
is_expected.to contain_file(main_config).with(
ensure: 'absent'
)

is_expected.to contain_file("#{dir}/telegraf.d").with(
is_expected.to contain_file("#{config_dir}/telegraf.d").with(
ensure: 'absent',
force: true
)
Expand Down

0 comments on commit 1d107ee

Please sign in to comment.