Skip to content

Commit 1e9d82e

Browse files
committed
fqdn_rotate: Add tests for custom seeds
1 parent d7c8460 commit 1e9d82e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

spec/functions/fqdn_rotate_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
expect(val1).to eq(val2)
2222
end
2323

24+
it "allows extra arguments to control the random rotation on a single host" do
25+
val1 = fqdn_rotate("abcdefg", :extra_identifier => [1, "different", "host"])
26+
val2 = fqdn_rotate("abcdefg", :extra_identifier => [2, "different", "host"])
27+
expect(val1).not_to eq(val2)
28+
end
29+
30+
it "considers the same host and same extra arguments to have the same random rotation" do
31+
val1 = fqdn_rotate("abcdefg", :extra_identifier => [1, "same", "host"])
32+
val2 = fqdn_rotate("abcdefg", :extra_identifier => [1, "same", "host"])
33+
expect(val1).not_to eq(val2)
34+
end
35+
2436
it "should rotate a string to give different values on different hosts" do
2537
val1 = fqdn_rotate("abcdefg", :host => 'one')
2638
val2 = fqdn_rotate("abcdefg", :host => 'two')
@@ -51,11 +63,13 @@
5163

5264
def fqdn_rotate(value, args = {})
5365
host = args[:host] || '127.0.0.1'
66+
extra = args[:extra_identifier] || []
5467

5568
# workaround not being able to use let(:facts) because some tests need
5669
# multiple different hostnames in one context
5770
scope.stubs(:lookupvar).with("::fqdn").returns(host)
5871

59-
scope.function_fqdn_rotate([value])
72+
function_args = [value] + extra
73+
scope.function_fqdn_rotate(function_args)
6074
end
6175
end

0 commit comments

Comments
 (0)