summaryrefslogtreecommitdiff
path: root/spec/functions/dig44_spec.rb
diff options
context:
space:
mode:
authorNate Potter <ntpttr@gmail.com>2016-07-07 21:10:22 -0700
committerNate Potter <ntpttr@gmail.com>2016-07-08 08:53:24 -0700
commita2f980d44d6703561769c5e0ef25a7f531417643 (patch)
treefd5118256340a58ed674911cf741169264af0589 /spec/functions/dig44_spec.rb
parent098e82e694704222200d42f2dd4b50ca6d9999fa (diff)
(MODULES-3568) Move dig to dig44 and deprecate dig
A new version of dig was introduced in Puppet 4.5.0 that isn't compatible with the stdlib version of dig. To maintain backwards compatibility and ensure that tests for stdlib aren't broken, this patch renames dig to dig44 and adds a deprecation warning to the stdlib dig function.
Diffstat (limited to 'spec/functions/dig44_spec.rb')
-rw-r--r--spec/functions/dig44_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/functions/dig44_spec.rb b/spec/functions/dig44_spec.rb
new file mode 100644
index 0000000..fd451ff
--- /dev/null
+++ b/spec/functions/dig44_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe 'dig44' do
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("dig44")).to eq("function_dig44")
+ end
+
+ it "should raise a ParseError if there are less than 2 arguments" do
+ expect { scope.function_dig44([]) }.to raise_error(Puppet::ParseError)
+ end
+
+ it "should raise a ParseError if the first argument isn't a hash or array" do
+ expect { scope.function_dig44(['bad', []]) }.to raise_error(Puppet::ParseError)
+ end
+
+ it "should raise a ParseError if the second argument isn't an array" do
+ expect { scope.function_dig44([{}, 'bad']) }.to raise_error(Puppet::ParseError)
+ end
+
+ it "should return an empty hash when given empty parameters" do
+ result = scope.function_dig44([{}, []])
+ expect(result).to(eq({}))
+ end
+
+ it "should return value when given simple hash" do
+ result = scope.function_dig44([{"a" => "b"}, ["a"]])
+ expect(result).to(eq("b"))
+ end
+
+ it "should find hash values two levels deep" do
+ result = scope.function_dig44([{"a" => {"b" => "c"}}, ["a", "b"]])
+ expect(result).to(eq("c"))
+ end
+
+ it "should return default value if nothing was found" do
+ result = scope.function_dig44([{}, ["a", "b"], "d"])
+ expect(result).to(eq("d"))
+ end
+
+ it "should work on booleans as well as strings" do
+ result = scope.function_dig44([{"a" => false}, ["a"]])
+ expect(result).to(eq(false))
+ end
+end