| Hi, to my understanding it's common practice to use rspec-puppet-facts for spec tests. The tool iterates on every operating system in the metadata.json and uses matching fact sets from facterdb. We try to use the correct facter version for the puppet version we're testing on:
# getting the correct facter version is tricky. We use facterdb as a source to mock facts |
# see https://github.com/camptocamp/facterdb |
# people might provide a specific facter version. In that case we use it. |
# Otherwise we need to match the correct facter version to the used puppet version. |
# as of 2019-10-31, puppet 5 ships facter 3.11 and puppet 6 ships facter 3.14 |
# https://puppet.com/docs/puppet/5.5/about_agent.html |
# |
# The environment variable `PUPPET_VERSION` is available in our travis environment, but we cannot rely on it |
# if somebody runs the tests locally. For that case we should fallback the the puppet gem version. |
def suggest_facter_version |
puppet_version = ENV['PUPPET_VERSION'] ? ENV['PUPPET_VERSION'] : Gem.loaded_specs['puppet'].version.to_s |
Gem::Dependency.new('', puppet_version).match?('', '5') ? '3.11.0' : '3.14.0' |
end |
|
RSpec.configure do |config| |
config.default_facter_version = ENV['FACTERDB_FACTS_VERSION'] || suggest_facter_version |
end
|
We think this is a good approach. Please correct me if I'm wrong. Do make this work, we need to add new fact sets to facterdb on minor/major release you do. This is tricky, especially since the gem maintainer don't have necessarily access to all the operating systems. This would be way easier if you could provide those fact sets within your release process of facter. This idea came up after a short discussion with Gene Liverman. CC: Ben Ford / David Schmitt |