]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/fqdn_rotate_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / fqdn_rotate_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the fqdn_rotate function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("fqdn_rotate")).to eq("function_fqdn_rotate")
9   end
10
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))
13   end
14
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))
19   end
20
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"]))
24   end
25
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)
32   end
33
34   it "should accept objects which extend String" do
35     class AlsoString < String
36     end
37
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))
42   end
43
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)
48     end
49     scope.function_fqdn_rotate(["asdf"])
50   end
51
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"])
55     rand1 = rand()
56     scope.function_fqdn_rotate(["asdf"])
57     rand2 = rand()
58     expect(rand1).not_to eql(rand2)
59   end
60 end