3 describe 'fqdn_rotate' do
4 it { is_expected.not_to eq(nil) }
5 it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
6 it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) }
7 it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) }
8 it { is_expected.to run.with_params('').and_return('') }
9 it { is_expected.to run.with_params('a').and_return('a') }
10 it { is_expected.to run.with_params('ã').and_return('ã') }
12 it { is_expected.to run.with_params([]).and_return([]) }
13 it { is_expected.to run.with_params(['a']).and_return(['a']) }
15 it "should rotate a string and the result should be the same size" do
16 expect(fqdn_rotate("asdf").size).to eq(4)
19 it "should rotate a string to give the same results for one host" do
20 val1 = fqdn_rotate("abcdefg", :host => 'one')
21 val2 = fqdn_rotate("abcdefg", :host => 'one')
22 expect(val1).to eq(val2)
25 it "allows extra arguments to control the random rotation on a single host" do
26 val1 = fqdn_rotate("abcdefg", :extra_identifier => [1, "different", "host"])
27 val2 = fqdn_rotate("abcdefg", :extra_identifier => [2, "different", "host"])
28 expect(val1).not_to eq(val2)
31 it "considers the same host and same extra arguments to have the same random rotation" do
32 val1 = fqdn_rotate("abcdefg", :extra_identifier => [1, "same", "host"])
33 val2 = fqdn_rotate("abcdefg", :extra_identifier => [1, "same", "host"])
34 expect(val1).to eq(val2)
37 it "should rotate a string to give different values on different hosts" do
38 val1 = fqdn_rotate("abcdefg", :host => 'one')
39 val2 = fqdn_rotate("abcdefg", :host => 'two')
40 expect(val1).not_to eq(val2)
43 it "should accept objects which extend String" do
44 result = fqdn_rotate(AlsoString.new('asdf'))
45 expect(result).to eq('dfas')
48 it "should use the Puppet::Util.deterministic_rand function" do
49 if Puppet::Util.respond_to?(:deterministic_rand)
50 Puppet::Util.expects(:deterministic_rand).with(44489829212339698569024999901561968770,4)
53 skip 'Puppet::Util#deterministic_rand not available'
57 it "should not leave the global seed in a deterministic state" do
62 expect(rand1).not_to eql(rand2)
65 def fqdn_rotate(value, args = {})
66 host = args[:host] || '127.0.0.1'
67 extra = args[:extra_identifier] || []
69 # workaround not being able to use let(:facts) because some tests need
70 # multiple different hostnames in one context
71 scope.stubs(:lookupvar).with("::fqdn").returns(host)
73 function_args = [value] + extra
74 scope.function_fqdn_rotate(function_args)