From 29f9bc723dbb0b57c3eedd3a576c8e8f87470c89 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 28 Jun 2024 18:08:37 +0200 Subject: [PATCH 1/4] README.md: Cleanup trailing whitespace --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18948048..7c3b1288 100644 --- a/README.md +++ b/README.md @@ -475,7 +475,7 @@ fact sets that only make sense in your environment or might contain sensitive in To supply external facts to facterdb just set the `FACTERDB_SEARCH_PATHS` environment variable with one or more paths to your facts. -When separating paths please use the default path separator character supported by your OS. +When separating paths please use the default path separator character supported by your OS. * Unix/Linux/OSX = `:` * Windows = `;` From eb9d229a6b6d073dc2aff1ae7728d904092012c9 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 28 Jun 2024 18:23:12 +0200 Subject: [PATCH 2/4] README.md: fix example, drop Ruby 1.8 examples --- README.md | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 7c3b1288..f59ba067 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ If you're using Bundler to manage gems in your module repository, install `rspec 1. Add the following line to your `Gemfile`: ```ruby -gem 'rspec-puppet-facts', :require => false +gem 'rspec-puppet-facts', require: false ``` 2. Run `bundle install`. @@ -54,38 +54,18 @@ By default, `rspec-puppet-facts` provides the facts only for `x86_64` architectu * `'operatingsystem'` - The name of the operating system, as a string. * `'operatingsystemrelease'` - An array of version numbers, as strings. -This is particularly useful if your module is split into operating system subclasses. For example, if you had a class called `myclass::debian` that you wanted to test against Debian 6 and Debian 7 on both `x86_64` _and_ `i386` architectures, you could write the following test: +This is particularly useful if your module is split into operating system subclasses. For example, if you had a class called `myclass::debian` that you wanted to test against Debian 12 and Debian 11 on both `x86_64` _and_ `i386` architectures, you could write the following test: ```ruby require 'spec_helper' -describe 'myclass::debian' do - test_on = { - :hardwaremodels => ['x86_64', 'i386'], - :supported_os => [ - { - 'operatingsystem' => 'Debian', - 'operatingsystemrelease' => ['6', '7'], - }, - ], - } - - on_supported_os(test_on).each do |os, os_facts| - let (:facts) { os_facts } - it { is_expected.to compile.with_all_deps } - end -end -``` -Ruby 1.9 and later: -```ruby -require 'spec_helper' - describe 'myclass::raspbian' do test_on = { + hardwaremodels: ['x86_64', 'i386'], supported_os: [ { 'operatingsystem' => 'Debian', - 'operatingsystemrelease' => ['10', '9', '8'], + 'operatingsystemrelease' => ['12', '11'], }, ], } From 3ba78cbb2b5d5a0501586793420fe249e840259a Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 28 Jun 2024 18:28:33 +0200 Subject: [PATCH 3/4] README.md: Document facter_version_for_puppet_version() --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f59ba067..7e525632 100644 --- a/README.md +++ b/README.md @@ -78,10 +78,9 @@ end ## Specifying a default Facter version -By default, `on_supported_os` will return the facts for the version of Facter -that it has loaded (usually this is Facter 2.5.1). This behaviour can be -overridden by setting the `default_facter_version` RSpec setting in your -`spec/spec_helper.rb` file. +By default, `on_supported_os` will return the facts for the version of Facter that it has loaded. It will check for the loaded Puppet version and maps that to the Facter version that Perforce released in the matching AIO. +The mapping is stored in `ext/puppet_agent_components.json` (check the [maintenance](#maintenance) section for details) and computated in the `facter_version_for_puppet_version` method. +This behaviour can be overridden by setting the `default_facter_version` RSpec setting in your `spec/spec_helper.rb` file. ```ruby RSpec.configure do |c| From db6cff02075f9ddf1bc99908f316a8d414cd8607 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 28 Jun 2024 18:33:58 +0200 Subject: [PATCH 4/4] Deprecate symbolized facts Co-authored-by: Ewoud Kohl van Wijngaarden --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index 7e525632..eea43882 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,54 @@ RSpec.configure do |c| end ``` +## Symbolized vs stringified facts + +For a long long time, the first level of keys in a factsets were symbols. +This was fine before there were structured facts, but structured facts ended up as nested hashes that always had strings. +This doesn't make sense and easy to get wrong. +The original data contains only strings so conversion actually costs performance. + +The option to switch between symbolized vs stringified facts was introduced in [25634f4481f20f2fc7444e867928ca607234e33e](https://github.com/voxpupuli/rspec-puppet-facts/commit/25634f4481f20f2fc7444e867928ca607234e33e) (Release [1.9.5](https://github.com/voxpupuli/rspec-puppet-facts/blob/master/CHANGELOG.md#2019-07-29---release-195)), but version 5.0.0 has resolved various implementation bugs. + +This can be configured like this: + +```ruby +RSpec.configure do |c| + c.facterdb_string_keys = false +end +``` + +In the 5.x release series of rspec-puppet-facts the default `false` is deprecated. +With the 6.0.0 release we will flip it to `true` (https://github.com/voxpupuli/rspec-puppet-facts/pull/189). + +You may have the following rspec-puppet test using deprecated symbolized facts: + +```ruby +on_supported_os.each do |os, os_facts| + case os_facts[:os]['name'] + when 'Archlinux' + context 'on Archlinux' do + it { is_expected.to contain_package('borg') } + end + when 'Ubuntu' + end +end +``` + +With the string facts, the same test looks like: + +```ruby +on_supported_os.each do |os, os_facts| + case os_facts['os']['name'] + when 'Archlinux' + context 'on Archlinux' do + it { is_expected.to contain_package('borg') } + end + when 'Ubuntu' + end +end +``` + ## Usage Use the `on_supported_os` iterator to loop through all of your module's supported operating systems. This allows you to simplify your tests and remove a lot of duplicate code.