From 450023235728eab560fb02d86fe682c7e94bfff7 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 21 Apr 2023 15:59:18 +0100 Subject: [PATCH] (PUP-11752) Fix fqdn_rand_string_spec.rb test Since Puppet `7.23.0` `fqdn_rand` uses the modern structured `networking` fact instead of the legacy `fqdn` fact. In this commit we mock the new fact if using `7.23.0` or later. This is a rebase of https://github.com/puppetlabs/puppetlabs-stdlib/pull/1294 and incorporates Aria Li's original change and a variation on Josh Cooper's suggestion for keeping compatibility with Puppet < `7.23.0` --- spec/functions/fqdn_rand_string_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/functions/fqdn_rand_string_spec.rb b/spec/functions/fqdn_rand_string_spec.rb index 1102b87f8..9eed4ad04 100644 --- a/spec/functions/fqdn_rand_string_spec.rb +++ b/spec/functions/fqdn_rand_string_spec.rb @@ -57,7 +57,11 @@ def fqdn_rand_string(max, args = {}) # workaround not being able to use let(:facts) because some tests need # multiple different hostnames in one context - allow(scope).to receive(:lookupvar).with('::fqdn', {}).and_return(host) + if Gem::Version.new(Puppet::PUPPETVERSION) < Gem::Version.new('7.23.0') + allow(scope).to receive(:lookupvar).with('::fqdn', {}).and_return(host) + else + allow(scope).to receive(:lookupvar).with('facts', {}).and_return({ 'networking' => { 'fqdn' => host } }) + end function_args = [max] if args.key?(:charset) || !extra.empty?