Skip to content

(PUP-11752) fqdn_rand_string_spec.rb relies on legacy fqdn fact #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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