summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-09-15 13:18:22 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-09-16 07:14:52 +1000
commitcb90528c041b63c1c483ac8650d1d9c67a12d791 (patch)
tree3e0ce533fa20da9a1847ddc7ac08036caa2364c8 /spec
parentb1554a1a38aa7a4da6c9927e26c9411af4ce1dff (diff)
downloadpuppet-cb90528c041b63c1c483ac8650d1d9c67a12d791.tar.gz
puppet-cb90528c041b63c1c483ac8650d1d9c67a12d791.tar.xz
puppet-cb90528c041b63c1c483ac8650d1d9c67a12d791.zip
Merged fix for #2601
This patch rolls up the changeses discussed on the list & the ticket The fqdn_rand now takes any number of additional arguments of any type that has a string representation (typically integers or strings) and concatenats them on to the salt. The tests have been adjusted to reflect this. Signed-off-by: Markus Roberts <Markus@reality.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/parser/functions/fqdn_rand.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/fqdn_rand.rb b/spec/unit/parser/functions/fqdn_rand.rb
new file mode 100644
index 000000000..cde899eef
--- /dev/null
+++ b/spec/unit/parser/functions/fqdn_rand.rb
@@ -0,0 +1,62 @@
+#! /usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the fqdn_rand function" do
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("fqdn_rand").should == "function_fqdn_rand"
+ end
+
+ it "should handle 0 arguments" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([]) }.should_not raise_error(Puppet::ParseError)
+ end
+
+ it "should handle 1 argument'}" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([3]) }.should_not raise_error(Puppet::ParseError)
+ end
+
+
+ (1..10).each { |n|
+ it "should handle #{n} additional arguments" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) }.should_not raise_error(Puppet::ParseError)
+ end
+ it "should handle #{n} additional string arguments" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError)
+ end
+ }
+
+ it "should return a value less than max" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 }
+ end
+
+ it "should return the same values on subsequent invocations for the same host" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1").twice
+ @scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 4]))
+ end
+
+ it "should return different sequences of value for different hosts" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ val1 = @scope.function_fqdn_rand([10000000,4])
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.2")
+ val2 = @scope.function_fqdn_rand([10000000,4])
+ val1.should_not eql(val2)
+ end
+
+ it "should return different values for the same hosts with different seeds" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ val1 = @scope.function_fqdn_rand([10000000,4])
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ val2 = @scope.function_fqdn_rand([10000000,42])
+ val1.should_not eql(val2)
+ end
+end