From cb96d902a91325998765d9c981eab7ea0da098da Mon Sep 17 00:00:00 2001 From: Marc Fournier Date: Wed, 4 Jan 2012 13:17:38 +0100 Subject: couchdblookup: 2 more tests --- spec/unit/data/missing.txt | 1 + spec/unit/data/proxy-failure.txt | 1 + spec/unit/puppet/parser/functions/couchdblookup_spec.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 spec/unit/data/missing.txt create mode 100644 spec/unit/data/proxy-failure.txt (limited to 'spec') diff --git a/spec/unit/data/missing.txt b/spec/unit/data/missing.txt new file mode 100644 index 0000000..4e6d97e --- /dev/null +++ b/spec/unit/data/missing.txt @@ -0,0 +1 @@ +{"error":"not_found","reason":"missing"} diff --git a/spec/unit/data/proxy-failure.txt b/spec/unit/data/proxy-failure.txt new file mode 100644 index 0000000..f5f1c37 --- /dev/null +++ b/spec/unit/data/proxy-failure.txt @@ -0,0 +1 @@ +

It works!

diff --git a/spec/unit/puppet/parser/functions/couchdblookup_spec.rb b/spec/unit/puppet/parser/functions/couchdblookup_spec.rb index 2af51a9..8777d71 100755 --- a/spec/unit/puppet/parser/functions/couchdblookup_spec.rb +++ b/spec/unit/puppet/parser/functions/couchdblookup_spec.rb @@ -70,4 +70,20 @@ describe "the couchdblookup function" do result.should raise_error(Puppet::ParseError) end + it "should raise a ParseError if couchdb can't find the requested document" do + sample_json = File.open(@datapath + 'missing.txt') + OpenURI.stub!(:open_uri).and_return(sample_json) + + result = lambda { @scope.function_couchdblookup(["http://fake/uri", "a-key"]) } + result.should raise_error(Puppet::ParseError) + end + + it "should raise a ParseError if input in not valid JSON" do + sample_json = File.open(@datapath + 'proxy-failure.txt') + OpenURI.stub!(:open_uri).and_return(sample_json) + + result = lambda { @scope.function_couchdblookup(["http://fake/uri", "a-key"]) } + result.should raise_error(Puppet::ParseError) + end + end -- cgit v1.2.3