Skip to content

Commit

Permalink
fix rubocop errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Feb 9, 2023
1 parent 7f5825b commit 2075929
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
9 changes: 6 additions & 3 deletions lib/voxpupuli/test/facts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec-puppet-facts'
include RspecPuppetFacts

Expand Down Expand Up @@ -51,7 +53,7 @@ def add_facts_for_metadata(metadata)
metadata['dependencies'].each do |dependency|
case normalize_module_name(dependency['name'])
when 'camptocamp/systemd', 'puppet/systemd'
add_custom_fact :systemd, ->(os, facts) { facts['service_provider'] == 'systemd' }
add_custom_fact :systemd, ->(_os, facts) { facts['service_provider'] == 'systemd' }
when 'puppetlabs/stdlib'
add_stdlib_facts
end
Expand All @@ -60,6 +62,7 @@ def add_facts_for_metadata(metadata)

def normalize_module_name(name)
return unless name

name.sub('-', '/')
end

Expand All @@ -70,7 +73,7 @@ def add_stdlib_facts

# Rough conversion of grepping in the puppet source:
# grep defaultfor lib/puppet/provider/service/*.rb
add_custom_fact :service_provider, ->(os, facts) do
add_custom_fact :service_provider, lambda { |_os, facts|
case facts[:osfamily].downcase
when 'archlinux'
'systemd'
Expand All @@ -93,5 +96,5 @@ def add_stdlib_facts
else
'init'
end
end
}
end
3 changes: 3 additions & 0 deletions lib/voxpupuli/test/rake.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppetlabs_spec_helper/rake_tasks'

PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}'
Expand All @@ -14,6 +16,7 @@
task :trailing_whitespace do
Dir.glob('**/*.md', File::FNM_DOTMATCH).sort.each do |filename|
next if filename =~ %r{^((modules|acceptance|\.?vendor|spec/fixtures|pkg)/|REFERENCE.md)}

File.foreach(filename).each_with_index do |line, index|
if line =~ %r{\s\n$}
puts "#{filename} has trailing whitespace on line #{index + 1}"
Expand Down
6 changes: 3 additions & 3 deletions lib/voxpupuli/test/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

RSpec.configure do |config|
# puppetlabs_spec_helper defaults to mocha but emits a deprecation warning
# Vox Pupuli prefers rspec to avoid the deprecation warning unless explicitly
# set
if config.instance_variable_get(:@mock_framework).nil?
config.mock_with :rspec
end
config.mock_with :rspec if config.instance_variable_get(:@mock_framework).nil?
end

require 'voxpupuli/test/facts'
Expand Down
47 changes: 25 additions & 22 deletions spec/facts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'voxpupuli/test/facts'

Expand All @@ -10,9 +12,9 @@
'release' => {
'full' => '7.7.1908',
'major' => '7',
'minor' => '7'
'minor' => '7',
},
}
},
}
end

Expand All @@ -25,9 +27,9 @@
'release' => {
'full' => '7.7.1908',
'major' => '7',
'minor' => '7'
'minor' => '7',
},
}
},
}
end

Expand All @@ -43,16 +45,16 @@
'release' => {
'full' => '7.7.1908',
'major' => '7',
'minor' => '7'
'minor' => '7',
},
},
ruby: {
'sitedir' => '/usr/local/share/ruby/site_ruby',
}
},
}
end

it { expect(override_facts(base_facts, ruby: {sitedir: '/usr/local/share/ruby/site_ruby'})).to eq(expected) }
it { expect(override_facts(base_facts, ruby: { sitedir: '/usr/local/share/ruby/site_ruby' })).to eq(expected) }
end

describe 'with deep merging' do
Expand All @@ -64,13 +66,13 @@
'release' => {
'full' => '7.7.1908',
'major' => '7',
'minor' => '8'
'minor' => '8',
},
}
},
}
end

it { expect(override_facts(base_facts, os: {release: {minor: '8'}})).to eq(expected) }
it { expect(override_facts(base_facts, os: { release: { minor: '8' } })).to eq(expected) }
end

describe 'with strings' do
Expand All @@ -82,19 +84,20 @@
'release' => {
'full' => '7.7.1908',
'major' => '7',
'minor' => '8'
'minor' => '8',
},
}
},
}
end

it { expect(override_facts(base_facts, os: {'release' => {minor: '8'}})).to eq(expected) }
it { expect(override_facts(base_facts, os: { 'release' => { minor: '8' } })).to eq(expected) }
end
end

describe 'add_facts_for_metadata' do
before(:each) { RspecPuppetFacts.reset }
after(:each) { RspecPuppetFacts.reset }
before { RspecPuppetFacts.reset }

after { RspecPuppetFacts.reset }

let(:metadata) do
{ 'dependencies' => dependencies }
Expand All @@ -112,7 +115,7 @@
context 'with systemd' do
let(:dependencies) do
[
{'name' => 'puppet/systemd'},
{ 'name' => 'puppet/systemd' },
]
end

Expand All @@ -124,26 +127,26 @@
context 'and stdlib' do
let(:dependencies) do
[
{'name' => 'puppetlabs/stdlib'},
{'name' => 'puppet/systemd'},
{ 'name' => 'puppetlabs/stdlib' },
{ 'name' => 'puppet/systemd' },
]
end

it 'has systemd on Red Hat 7' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', {osfamily: 'RedHat', operatingsystemmajrelease: '7'})
facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', { osfamily: 'RedHat', operatingsystemmajrelease: '7' })
expect(facts['systemd']).to be true
end

it 'has no systemd on Red Hat 6' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', {osfamily: 'RedHat', operatingsystemmajrelease: '6'})
facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', { osfamily: 'RedHat', operatingsystemmajrelease: '6' })
expect(facts['systemd']).to be false
end

it 'has no systemd on openbsd' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', {osfamily: 'OpenBSD'})
facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', { osfamily: 'OpenBSD' })
expect(facts['systemd']).to be false
end
end
Expand All @@ -152,7 +155,7 @@
context 'with stdlib' do
let(:dependencies) do
[
{'name' => 'puppetlabs/stdlib'},
{ 'name' => 'puppetlabs/stdlib' },
]
end

Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'simplecov'
require 'simplecov-console'
Expand Down

0 comments on commit 2075929

Please sign in to comment.