diff options
author | Marc Fournier <marc.fournier@camptocamp.com> | 2012-01-04 10:40:13 +0100 |
---|---|---|
committer | Marc Fournier <marc.fournier@camptocamp.com> | 2012-01-04 10:40:13 +0100 |
commit | 09a26a5df6489e068f288c4de84ae9e0d2ca5082 (patch) | |
tree | 2c896f5543155304ac9dee9540775a981ed69268 /spec/unit/puppet/parser/functions/couchdblookup_spec.rb | |
parent | d132bb2ffbb6f6d5a148db1aa0ad2f3645a3971c (diff) |
couchdblookup: added tests.
Diffstat (limited to 'spec/unit/puppet/parser/functions/couchdblookup_spec.rb')
-rwxr-xr-x | spec/unit/puppet/parser/functions/couchdblookup_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/unit/puppet/parser/functions/couchdblookup_spec.rb b/spec/unit/puppet/parser/functions/couchdblookup_spec.rb new file mode 100755 index 0000000..4e9ab76 --- /dev/null +++ b/spec/unit/puppet/parser/functions/couchdblookup_spec.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env rspec + +require 'puppet' + +describe "the couchdblookup function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + @datapath = File.dirname(__FILE__) + '/../../../data/' + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + Puppet::Parser::Functions.function("couchdblookup").should == "function_couchdblookup" + end + + it "should raise a ParseError unless there is exactly 2 arguments" do + lambda { @scope.function_couchdblookup([]) }.should raise_error(Puppet::ParseError) + lambda { @scope.function_couchdblookup([1]) }.should raise_error(Puppet::ParseError) + lambda { @scope.function_couchdblookup([1,2,3]) }.should raise_error(Puppet::ParseError) + end + + it "should return the value of a key from a single couchdb document" do + sample_json = File.open(@datapath + 'one-document.txt') + OpenURI.stub!(:open_uri).and_return(sample_json) + + result = @scope.function_couchdblookup(["http://fake/uri", "wiki"]) + result.should eq(true) + end + + it "should raise a ParseError if a key can't be found in a couchdb document" do + sample_json = File.open(@datapath + 'one-document.txt') + OpenURI.stub!(:open_uri).and_return(sample_json) + + result = lambda { @scope.function_couchdblookup(["http://fake/uri", "fake-key"]) } + result.should raise_error(Puppet::ParseError) + end + + it "should return an array from the values of a couchdb view" do + sample_json = File.open(@datapath + 'map.txt') + OpenURI.stub!(:open_uri).and_return(sample_json) + + result = @scope.function_couchdblookup(["http://fake/uri", "value"]) + result.should eq(["foo", "bar"]) + end + + it "should raise a ParseError if a key can't be found in the rows of a couchdb view" do + sample_json = File.open(@datapath + 'map.txt') + OpenURI.stub!(:open_uri).and_return(sample_json) + + result = lambda { @scope.function_couchdblookup(["http://fake/uri", "fake-key"]) } + result.should raise_error(Puppet::ParseError) + end + +end |