summaryrefslogtreecommitdiff
path: root/spec/functions
diff options
context:
space:
mode:
authorEli Young <elyscape@gmail.com>2015-01-28 15:28:54 -0800
committerEli Young <elyscape@gmail.com>2015-02-12 14:04:47 -0800
commit84f866ffafbb27a6aa6a1eea92c393a63829e242 (patch)
tree7e0792a13888ccd15bee9d2da13bebfd79071dd3 /spec/functions
parentafc83ea564520378ac507251ddfea46f8d571829 (diff)
(MODULES-1738) Don't modify global seed in fqdn_rotate()
As per puppetlabs/puppet@292233c, this leaves the global seed in a deterministic state, which is bad. Puppet::Util.deterministic_rand() exists to avoid running into this issue, but is only present starting in Puppet 3.2.0.
Diffstat (limited to 'spec/functions')
-rwxr-xr-xspec/functions/fqdn_rotate_spec.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb
index 40057d4..673a8a3 100755
--- a/spec/functions/fqdn_rotate_spec.rb
+++ b/spec/functions/fqdn_rotate_spec.rb
@@ -40,4 +40,21 @@ describe "the fqdn_rotate function" do
result = scope.function_fqdn_rotate([value])
result.size.should(eq(4))
end
+
+ it "should use the Puppet::Util.deterministic_rand function if available" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ if Puppet::Util.respond_to?(:deterministic_rand)
+ Puppet::Util.expects(:deterministic_rand).with(113646079810780526294648115052177588845,4)
+ end
+ scope.function_fqdn_rotate(["asdf"])
+ end
+
+ it "should not leave the global seed in a deterministic state" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
+ scope.function_fqdn_rotate(["asdf"])
+ rand1 = rand()
+ scope.function_fqdn_rotate(["asdf"])
+ rand2 = rand()
+ expect(rand1).not_to eql(rand2)
+ end
end