1 #! /usr/bin/env ruby -S rspec
4 describe "the fqdn_rotate function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("fqdn_rotate")).to eq("function_fqdn_rotate")
11 it "should raise a ParseError if there is less than 1 arguments" do
12 expect { scope.function_fqdn_rotate([]) }.to( raise_error(Puppet::ParseError))
15 it "should rotate a string and the result should be the same size" do
16 scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
17 result = scope.function_fqdn_rotate(["asdf"])
18 expect(result.size).to(eq(4))
21 it "should rotate a string to give the same results for one host" do
22 scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
23 expect(scope.function_fqdn_rotate(["abcdefg"])).to eql(scope.function_fqdn_rotate(["abcdefg"]))
26 it "should rotate a string to give different values on different hosts" do
27 scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
28 val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
29 scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
30 val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
31 expect(val1).not_to eql(val2)
34 it "should accept objects which extend String" do
35 class AlsoString < String
38 scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
39 value = AlsoString.new("asdf")
40 result = scope.function_fqdn_rotate([value])
41 result.size.should(eq(4))
44 it "should use the Puppet::Util.deterministic_rand function if available" do
45 scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
46 if Puppet::Util.respond_to?(:deterministic_rand)
47 Puppet::Util.expects(:deterministic_rand).with(113646079810780526294648115052177588845,4)
49 scope.function_fqdn_rotate(["asdf"])
52 it "should not leave the global seed in a deterministic state" do
53 scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
54 scope.function_fqdn_rotate(["asdf"])
56 scope.function_fqdn_rotate(["asdf"])
58 expect(rand1).not_to eql(rand2)