From 239bed66ea55e7e4f4314d3d2d459932790559ef Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 24 May 2024 22:18:15 +0200 Subject: [PATCH 1/3] Use our spec_helper for tests Previously our tests didn't honour our spec/spec_helper.rb. This configures some rspec defaults for our Puppet modules. It makes sense that our tests use the same settings. This revealed some problems in other PRs: https://github.com/voxpupuli/voxpupuli-test/pull/125 --- spec/facts_spec.rb | 1 - spec/spec_helper.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/facts_spec.rb b/spec/facts_spec.rb index 0b29bd7..4be8735 100644 --- a/spec/facts_spec.rb +++ b/spec/facts_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'voxpupuli/test/facts' describe 'override_facts' do let(:base_facts) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 73fb578..f1b254d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,3 +23,4 @@ end require 'rspec/core' +require 'voxpupuli/test/spec_helper' From b80d4f745c90c84eaea25a374ea6a1a3ffef3aa8 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 24 May 2024 22:08:24 +0200 Subject: [PATCH 2/3] switch to stringified facts; use rspec-puppet-facts 3 --- Gemfile | 2 ++ lib/voxpupuli/test/spec_helper.rb | 2 ++ voxpupuli-test.gemspec | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5b2c938..89dffcb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,7 @@ source 'https://rubygems.org' +gem 'rspec-puppet-facts', git: 'https://github.com/bastelfreak/rspec-puppet-facts', branch: 'foobaz' + gemspec group :release do diff --git a/lib/voxpupuli/test/spec_helper.rb b/lib/voxpupuli/test/spec_helper.rb index 6022b13..d654d31 100644 --- a/lib/voxpupuli/test/spec_helper.rb +++ b/lib/voxpupuli/test/spec_helper.rb @@ -17,6 +17,8 @@ # and 7.12+ and requires rspec-puppet 2.11.0+. config.facter_implementation = 'rspec' + config.facterdb_string_keys = true + config.after(:suite) do RSpec::Puppet::Coverage.report! end diff --git a/voxpupuli-test.gemspec b/voxpupuli-test.gemspec index 98d11f1..b6381ba 100644 --- a/voxpupuli-test.gemspec +++ b/voxpupuli-test.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |s| # 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', '~> 3.0' s.add_runtime_dependency 'rspec-puppet-utils', '~> 3.4' # Rubocop From c4d48b038ea989bede17204fa7526ce8ef333370 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 24 May 2024 23:26:25 +0200 Subject: [PATCH 3/3] Update tests for stringified facts --- spec/facts_spec.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/facts_spec.rb b/spec/facts_spec.rb index 4be8735..6e3d9c6 100644 --- a/spec/facts_spec.rb +++ b/spec/facts_spec.rb @@ -3,7 +3,7 @@ describe 'override_facts' do let(:base_facts) do { - os: { + 'os' => { 'family' => 'RedHat', 'name' => 'CentOS', 'release' => { @@ -18,7 +18,7 @@ describe 'no overrides' do let(:expected) do { - os: { + 'os' => { 'family' => 'RedHat', 'name' => 'CentOS', 'release' => { @@ -36,7 +36,7 @@ describe 'with addition at the top level' do let(:expected) do { - os: { + 'os' => { 'family' => 'RedHat', 'name' => 'CentOS', 'release' => { @@ -45,19 +45,19 @@ 'minor' => '7' }, }, - ruby: { + '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 let(:expected) do { - os: { + 'os' => { 'family' => 'RedHat', 'name' => 'CentOS', 'release' => { @@ -69,13 +69,13 @@ } 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 let(:expected) do { - os: { + 'os' => { 'family' => 'RedHat', 'name' => 'CentOS', 'release' => { @@ -87,7 +87,7 @@ } 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 @@ -131,7 +131,7 @@ it 'has systemd on Red Hat 7' do add_facts_for_metadata(metadata) facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', { - os: { 'family' => 'RedHat', 'release' => { 'major' => '7' } } + 'os' => { 'family' => 'RedHat', 'release' => { 'major' => '7' } } }) expect(facts['systemd']).to be true end @@ -139,7 +139,7 @@ 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' }} + 'os' => {'family' => 'RedHat', 'release' => { 'major' => '6' }} }) expect(facts['systemd']).to be false end @@ -147,7 +147,7 @@ it 'has no systemd on openbsd' do add_facts_for_metadata(metadata) facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', { - os: { 'family' => 'OpenBSD' } + 'os' => { 'family' => 'OpenBSD' } }) expect(facts['systemd']).to be false end