summaryrefslogtreecommitdiff
path: root/spec/functions/fqdn_rotate_spec.rb
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2015-01-27 15:14:18 -0500
committerMicah Anderson <micah@riseup.net>2015-01-27 15:14:18 -0500
commit71123634744b9fe2ec7d6a3e38e9789fd84801e3 (patch)
tree1794e812d83facd93b3007c42632c63ddf1eb2fc /spec/functions/fqdn_rotate_spec.rb
parent71cb0f4c2c3bf95f62c9f189f5cef155b09a9682 (diff)
parent5863ab3901368310186790980aea2b0bf7cecb06 (diff)
Merge branch 'master' into leap
Diffstat (limited to 'spec/functions/fqdn_rotate_spec.rb')
-rwxr-xr-xspec/functions/fqdn_rotate_spec.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb
new file mode 100755
index 0000000..40057d4
--- /dev/null
+++ b/spec/functions/fqdn_rotate_spec.rb
@@ -0,0 +1,43 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the fqdn_rotate function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("fqdn_rotate")).to eq("function_fqdn_rotate")
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ expect { scope.function_fqdn_rotate([]) }.to( raise_error(Puppet::ParseError))
+ end
+
+ it "should rotate a string and the result should be the same size" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ result = scope.function_fqdn_rotate(["asdf"])
+ expect(result.size).to(eq(4))
+ end
+
+ it "should rotate a string to give the same results for one host" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
+ expect(scope.function_fqdn_rotate(["abcdefg"])).to eql(scope.function_fqdn_rotate(["abcdefg"]))
+ end
+
+ it "should rotate a string to give different values on different hosts" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
+ val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
+ expect(val1).not_to eql(val2)
+ end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ value = AlsoString.new("asdf")
+ result = scope.function_fqdn_rotate([value])
+ result.size.should(eq(4))
+ end
+end