summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDavid Schmitt <david.schmitt@puppet.com>2016-07-13 09:50:30 +0100
committerGitHub <noreply@github.com>2016-07-13 09:50:30 +0100
commit9224143da2195c57ce814e837f722348c2038ecb (patch)
tree5b2aa1370903527e27428399500ec9a78b9a3e84 /spec
parente723c7c292dbc1b1792798a4c70d58937d412b13 (diff)
parenta2f980d44d6703561769c5e0ef25a7f531417643 (diff)
Merge pull request #618 from ntpttr/fix/master/modules-3568
(MODULES-3568) Move dig to dig44 and deprecate dig
Diffstat (limited to 'spec')
-rw-r--r--spec/functions/dig44_spec.rb44
-rw-r--r--spec/functions/dig_spec.rb16
2 files changed, 52 insertions, 8 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
diff --git a/spec/functions/dig_spec.rb b/spec/functions/dig_spec.rb
index 1c5d49d..ad16fdd 100644
--- a/spec/functions/dig_spec.rb
+++ b/spec/functions/dig_spec.rb
@@ -1,13 +1,13 @@
require 'spec_helper'
describe 'dig' do
- it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) }
- it { is_expected.to run.with_params('bad', []).and_raise_error(Puppet::ParseError) }
- it { is_expected.to run.with_params({}, 'bad').and_raise_error(Puppet::ParseError) }
- it { is_expected.to run.with_params({}, []).and_return({}) }
- it { is_expected.to run.with_params({"a" => "b"}, ["a"]).and_return("b") }
- it { is_expected.to run.with_params({"a" => {"b" => "c"}}, ["a", "b"]).and_return("c") }
- it { is_expected.to run.with_params({}, ["a", "b"], "d").and_return("d") }
- it { is_expected.to run.with_params({"a" => false}, ["a"]).and_return(false) }
+ it "should exist" do
+ expect(Puppet::Parser::Functions.function("dig")).to eq("function_dig")
+ end
+
+ it "should give a deprecation warning when called" do
+ scope.expects(:warning).with("dig() DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.")
+ scope.function_dig([{}, []])
+ end
end