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

rspec-puppet-facts: Require 4.x; add custom facts as strings #135

Merged
merged 1 commit into from
Jun 12, 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
4 changes: 2 additions & 2 deletions lib/voxpupuli/test/facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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 Down Expand Up @@ -86,7 +86,7 @@ def add_stdlib_facts
when 'openbsd'
'openbsd'
when 'redhat'
os['release']['major'].to_i >= 7 ? 'systemd' : 'redhat'
'systemd'
when 'suse'
os['release']['major'].to_i >= 12 ? 'systemd' : 'redhat'
when 'windows'
Expand Down
3 changes: 3 additions & 0 deletions lib/voxpupuli/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# and 7.12+ and requires rspec-puppet 2.11.0+.
config.facter_implementation = 'rspec'

# In the next major release we will flip this to true
config.facterdb_string_keys = false

config.after(:suite) do
RSpec::Puppet::Coverage.report!
end
Expand Down
20 changes: 6 additions & 14 deletions spec/facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,20 @@
]
end

it 'has systemd on Red Hat 7' do
it 'has systemd on Red Hat 9' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', {
os: { 'family' => 'RedHat', 'release' => { 'major' => '7' } }
facts = RspecPuppetFacts.with_custom_facts('redhat-9-x86_64', {
os: { 'family' => 'RedHat', 'release' => { 'major' => '9' } }
})
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', {
os: {'family' => 'RedHat', 'release' => { 'major' => '6' }}
})
expect(facts['systemd']).to be false
expect(facts[:systemd]).to be true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that those are symbols, because we don't set RSpec.config.facterdb_string_keys = true. But why was it a string in the past? The code adds the custom fact as symbol:

add_custom_fact :service_provider, ->(_os, facts) do

also the stdlib facts below are tested as a symbol and work now and worked before 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this changedin rspec-puppet-facts 3. Previously the custom facts were always strings, now they honour stringify_facts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can switch the custom facts someone back to strings we could make this a minor release. But if we do a major release that's not too bad as well. We don't use the systemd fact at all in our unit tests for facts, it just requires a new modulesync.

Copy link
Member Author

@bastelfreak bastelfreak Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I think we should do a major release

end

it 'has no systemd on openbsd' do
add_facts_for_metadata(metadata)
facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', {
facts = RspecPuppetFacts.with_custom_facts('openbsd-7-x86_64', {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating because openbsd 6.4 is gone from facterdb.

os: { 'family' => 'OpenBSD' }
})
expect(facts['systemd']).to be false
expect(facts[:systemd]).to be false
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions voxpupuli-test.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'rake', '~> 13.0', '>= 13.0.6'

# Testing
s.add_runtime_dependency 'facterdb', '>= 1.4.0', '< 2'
s.add_runtime_dependency 'facterdb', '~> 2.1'
s.add_runtime_dependency 'metadata-json-lint', '~> 4.0'
s.add_runtime_dependency 'parallel_tests', '~> 4.2'
s.add_runtime_dependency 'puppetlabs_spec_helper', '~> 7.3'
# lazy dependency of the `validate` task. Will check the REFERENCE.md
# 3.0.0 and later require Ruby 2.7
s.add_runtime_dependency 'puppet-strings', '~> 4.0'
s.add_runtime_dependency 'rspec-puppet', '~> 4.0'
s.add_runtime_dependency 'rspec-puppet-facts', '~> 2.0', '>= 2.0.5'
s.add_runtime_dependency 'rspec-puppet-facts', '~> 4.0'
s.add_runtime_dependency 'rspec-puppet-utils', '~> 3.4'

# Rubocop
Expand Down
Loading