Skip to content

Commit

Permalink
rubocop autocorrect results
Browse files Browse the repository at this point in the history
  • Loading branch information
traylenator committed Sep 1, 2022
1 parent 3fac846 commit 9ea0aed
Show file tree
Hide file tree
Showing 128 changed files with 908 additions and 600 deletions.
4 changes: 3 additions & 1 deletion lib/facter/collectd_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Fact: collectd_version
#
# Purpose: Retrieve collectd version if installed
Expand All @@ -10,7 +12,7 @@
setcode do
if Facter::Util::Resolution.which('collectd')
collectd_help = Facter::Util::Resolution.exec('collectd -h')
%r{^collectd ([\w\.]+), http://collectd\.org/}.match(collectd_help)[1]
%r{^collectd ([\w.]+), http://collectd\.org/}.match(collectd_help)[1]
end
end
end
2 changes: 2 additions & 0 deletions lib/facter/python_dir.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Fact: python_dir
#
# Purpose: Retrieve python package dir used by pip install
Expand Down
19 changes: 9 additions & 10 deletions lib/puppet/parser/functions/collectd_convert_processes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Puppet::Parser::Functions.newfunction(:collectd_convert_processes, type: :rvalue, arity: 1, doc: <<-ENDDOC
Converts the array from the old style to define process or processmatch in the
processes plugin into a create_resources compatible hash which
Expand All @@ -7,27 +9,24 @@
[ { 'name' => 'foo', 'regex' => '.*' } , { 'name' => 'bar', 'regex' => '[0-9]+' }, "alone" ]
will be converted to
{ 'foo' => { 'regex' => '.*' } , 'bar' => { 'regex' => '[0-9]+' }, 'alone' => {} }
ENDDOC
) do |args|
if args.size != 1
raise(Puppet::ParseError, 'convert_process_array(): Needs exactly one argument')
end
ENDDOC
) do |args|
raise(Puppet::ParseError, 'convert_process_array(): Needs exactly one argument') if args.size != 1

if args[0].is_a?(Hash)
return args[0] # Keep normal hiera hash as-is
end

parray = args[0]
unless parray.is_a?(Array)
raise(Puppet::ParseError, 'convert_process_array(): Needs an array as argument')
end
raise(Puppet::ParseError, 'convert_process_array(): Needs an array as argument') unless parray.is_a?(Array)

phash = {}

parray.each do |p|
if p.is_a?(String)
case p
when String
phash[p] = {}
elsif p.is_a?(Hash)
when Hash
name = p.delete('name')
phash[name] = p
else
Expand Down
7 changes: 4 additions & 3 deletions spec/acceptance/class_plugin_disk_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'collectd::plugin::disk class' do
Expand Down Expand Up @@ -38,9 +40,8 @@
# module being loaded is an exercise for the reader.
# For CentOS 7 it works on my laptop but not in travis.
# disk plugin is probably very sensitive to environment.
if fact('os.family') == 'Redhat' && fact('os.release.major') == '8'
its(:stdout) { is_expected.to match %r{disk_time} }
end

its(:stdout) { is_expected.to match %r{disk_time} } if fact('os.family') == 'Redhat' && fact('os.release.major') == '8'
end
end
end
9 changes: 7 additions & 2 deletions spec/acceptance/class_plugin_load_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'collectd::plugin::load class' do
Expand Down Expand Up @@ -38,6 +40,7 @@
its(:stdout) { is_expected.not_to match %r{load/load-relative$} }
end
end

context 'report relative false' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
Expand Down Expand Up @@ -77,6 +80,7 @@
its(:stdout) { is_expected.not_to match %r{load/load-relative$} }
end
end

context 'report relative true' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
Expand Down Expand Up @@ -114,8 +118,9 @@
its(:exit_status) { is_expected.to eq 0 }
# https://github.com/voxpupuli/puppet-collectd/issues/901
# following will fail once 5.9.1 is released in EPEL8
if fact('osfamily') == 'RedHat' && fact('os.release.major') == '8' ||
fact('osfamily') == 'Debian' && fact('os.release.major') == '8'

if (fact('osfamily') == 'RedHat' && fact('os.release.major') == '8') ||
(fact('osfamily') == 'Debian' && fact('os.release.major') == '8')
its(:stdout) { is_expected.not_to match %r{load/load-relative$} }
its(:stdout) { is_expected.to match %r{load/load$} }
else
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/class_plugin_write_http_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'collectd::plugin::write_http class' do
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'collectd class' do
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/curl_json_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'curl_json defined type' do
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/define_plugin_processes_process_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'collectd::plugin::processes::process' do
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/define_plugin_processes_processmatch_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'collectd::plugin::processes::processmatchs' do
Expand Down
29 changes: 11 additions & 18 deletions spec/classes/collectd_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
it { is_expected.to contain_file_line('include_conf_d_dot_conf').with_ensure('present') }
it { is_expected.to contain_package(options[:package]).with_ensure('present') }
it { is_expected.to contain_package(options[:package]).with_install_options(nil) }

it do
is_expected.to contain_service('collectd').with(
ensure: 'running',
name: options[:service]
)
end

if facts[:osfamily] == 'RedHat'
it { is_expected.to contain_class('epel') }
end
it { is_expected.to contain_class('epel') } if facts[:osfamily] == 'RedHat'
end

context 'with collectd::install::package_install_options' do
Expand Down Expand Up @@ -182,11 +181,13 @@
it { is_expected.to contain_file('collectd.conf').with_content(%r{^CollectInternalStats true}) }
end
end

context 'when custom package_name is set' do
let(:params) { { package_name: 'collectd-core' } }

it { is_expected.to contain_package('collectd-core').with_ensure('present') }
end

context 'when manage_package is false' do
let(:params) { { manage_package: false } }

Expand All @@ -209,9 +210,7 @@
context 'and ci_package_repo empty' do
let(:params) { { manage_repo: true } }

if facts[:osfamily] == 'RedHat'
it { is_expected.to contain_class('epel') }
end
it { is_expected.to contain_class('epel') } if facts[:osfamily] == 'RedHat'
end

context 'and manage_package is true' do
Expand All @@ -222,9 +221,7 @@
}
end

if facts[:osfamily] == 'Debian'
it { is_expected.to contain_package(options[:package]).that_requires('Class[Apt::Update]') }
end
it { is_expected.to contain_package(options[:package]).that_requires('Class[Apt::Update]') } if facts[:osfamily] == 'Debian'
end

context 'and manage_package is false' do
Expand All @@ -235,9 +232,7 @@
}
end

if facts[:osfamily] == 'Debian'
it { is_expected.not_to contain_class('Class[Apt::Update]').that_comes_before('Package[collectd]') }
end
it { is_expected.not_to contain_class('Class[Apt::Update]').that_comes_before('Package[collectd]') } if facts[:osfamily] == 'Debian'
end

context 'and ci_package_repo set to a version' do
Expand All @@ -249,9 +244,7 @@
}
end

if facts[:osfamily] == 'RedHat'
it { is_expected.to contain_yumrepo('collectd-ci').with_gpgkey('https://pkg.ci.collectd.org/pubkey.asc').with_baseurl("https://pkg.ci.collectd.org/rpm/collectd-5.6/epel-#{facts[:operatingsystemmajrelease]}-x86_64") }
end
it { is_expected.to contain_yumrepo('collectd-ci').with_gpgkey('https://pkg.ci.collectd.org/pubkey.asc').with_baseurl("https://pkg.ci.collectd.org/rpm/collectd-5.6/epel-#{facts[:operatingsystemmajrelease]}-x86_64") } if facts[:osfamily] == 'RedHat'
if facts[:osfamily] == 'Debian'
it do
is_expected.to contain_apt__source('collectd-ci').
Expand All @@ -264,6 +257,7 @@
end
end
end

context 'and package_keyserver is set' do
let(:params) do
{
Expand All @@ -273,9 +267,7 @@
}
end

if facts[:osfamily] == 'RedHat'
it { is_expected.to contain_yumrepo('collectd-ci').with_gpgkey('https://pkg.ci.collectd.org/pubkey.asc').with_baseurl("https://pkg.ci.collectd.org/rpm/collectd-5.6/epel-#{facts[:operatingsystemmajrelease]}-x86_64") }
end
it { is_expected.to contain_yumrepo('collectd-ci').with_gpgkey('https://pkg.ci.collectd.org/pubkey.asc').with_baseurl("https://pkg.ci.collectd.org/rpm/collectd-5.6/epel-#{facts[:operatingsystemmajrelease]}-x86_64") } if facts[:osfamily] == 'RedHat'
if facts[:osfamily] == 'Debian'
it do
is_expected.to contain_apt__source('collectd-ci').
Expand Down Expand Up @@ -314,6 +306,7 @@

it { is_expected.to contain_file('collectd.conf').with_content(%r{Hello World}) }
end

context 'on non supported operating systems' do
let(:facts) { { os: { family: 'foo' } } }

Expand Down
6 changes: 5 additions & 1 deletion spec/classes/collectd_plugin_amqp1_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'collectd::plugin::amqp1', type: :class do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
context "on #{os}" do
let :facts do
facts
end
Expand All @@ -21,12 +23,14 @@
it { is_expected.to contain_collectd__plugin('amqp1') }
it { is_expected.to contain_file('old_amqp1.load').with_ensure('absent') }
it { is_expected.to contain_file('older_amqp1.load').with_ensure('absent') }

it 'Will create 10-amqp1.conf' do
is_expected.to contain_file('amqp1.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-amqp1.conf"
)
end

it { is_expected.to contain_file('amqp1.load').with(content: %r{<Transport "metrics">}) }
it { is_expected.to contain_file('amqp1.load').with(content: %r{Host "localhost"}) }
it { is_expected.to contain_file('amqp1.load').with(content: %r{Port "5672"}) }
Expand Down
8 changes: 7 additions & 1 deletion spec/classes/collectd_plugin_amqp_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'collectd::plugin::amqp', type: :class do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
context "on #{os}" do
let :facts do
facts
end
Expand All @@ -20,12 +22,14 @@
it { is_expected.to contain_collectd__plugin('amqp') }
it { is_expected.to contain_file('old_amqp.load').with_ensure('absent') }
it { is_expected.to contain_file('older_amqp.load').with_ensure('absent') }

it 'Will create 10-amqp.conf' do
is_expected.to contain_file('amqp.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-amqp.conf"
)
end

it { is_expected.to contain_file('amqp.load').with(content: %r{<Publish "graphite">}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Host "localhost"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{Port "5672"}) }
Expand All @@ -40,6 +44,7 @@
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphiteEscapeChar "_"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{</Publish>}) }
end

context 'overriding default parameters' do
let(:params) do
{ amqphost: 'myhost',
Expand Down Expand Up @@ -70,6 +75,7 @@
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphitePrefix "prefix"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{GraphiteEscapeChar "\|"}) }
it { is_expected.to contain_file('amqp.load').with(content: %r{</Publish>}) }

context 'with collectd 5.5+' do
let :facts do
facts.merge(collectd_version: '5.6.0')
Expand Down
32 changes: 17 additions & 15 deletions spec/classes/collectd_plugin_apache_instance_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'collectd::plugin::apache::instance', type: :define do
on_supported_os(baseline_os_hash).each do |os, facts|
context "on #{os} " do
context "on #{os}" do
let :facts do
facts
end
Expand All @@ -27,20 +29,20 @@
end

it 'creates an apache instance' do
content_instance_file = <<EOS
<Plugin "apache">
<Instance "site2">
URL "https://another.example.com"
User "nobody"
Password "secrets"
VerifyPeer false
VerifyHost true
CACert "/etc/foobar/ca.crt"
SSLCiphers "TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"
Timeout 120
</Instance>
</Plugin>
EOS
content_instance_file = <<~EOS
<Plugin "apache">
<Instance "site2">
URL "https://another.example.com"
User "nobody"
Password "secrets"
VerifyPeer false
VerifyHost true
CACert "/etc/foobar/ca.crt"
SSLCiphers "TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"
Timeout 120
</Instance>
</Plugin>
EOS
is_expected.to compile.with_all_deps
is_expected.to contain_class('collectd')
is_expected.to contain_class('collectd::plugin::apache')
Expand Down
Loading

0 comments on commit 9ea0aed

Please sign in to comment.