Skip to content
Closed
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
2 changes: 1 addition & 1 deletion spec/functions/fqdn_rand_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ 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)
allow(scope).to receive(:lookupvar).with('facts', {}).and_return({ 'networking' => { 'fqdn' => host } })
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah the expectation needs to be different based on the version of puppet (before and after this change puppetlabs/puppet@c0d2560). So something like

if Puppet::PUPPETVERSION.to_f < 7.23
  allow(scope).to receive(:lookupvar).with('::fqdn', {}).and_return(host)
else
  allow(scope).to receive(:lookupvar).with('facts', {}).and_return({ 'networking' => { 'fqdn' => host } })
end

Or there may be a better way to stub out the facts using RspecPuppetFacts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps this function should just mock fqdn_rand? It really is fqdn_rand which gets the fact, so we don't care about the internal implementation:

rand_string += charset[function_fqdn_rand([charset.size, (args + [current.to_s]).join(':')]).to_i]


function_args = [max]
if args.key?(:charset) || !extra.empty?
Expand Down