diff options
author | Marc Fournier <marc.fournier@camptocamp.com> | 2012-01-04 12:21:05 +0100 |
---|---|---|
committer | Marc Fournier <marc.fournier@camptocamp.com> | 2012-01-04 12:21:05 +0100 |
commit | 9418066cc806ca172c1214fb112c09ac23e41acb (patch) | |
tree | 0ab94727e5ed390c9386e55076022d16a6e87526 /spec | |
parent | 09a26a5df6489e068f288c4de84ae9e0d2ca5082 (diff) |
couchdblookup: added case for map+reduce view.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/data/map+reduce.txt | 3 | ||||
-rwxr-xr-x | spec/unit/puppet/parser/functions/couchdblookup_spec.rb | 16 |
2 files changed, 19 insertions, 0 deletions
diff --git a/spec/unit/data/map+reduce.txt b/spec/unit/data/map+reduce.txt new file mode 100644 index 0000000..71e1836 --- /dev/null +++ b/spec/unit/data/map+reduce.txt @@ -0,0 +1,3 @@ +{"rows":[ +{"key":1,"value":["foo","bar","baz"]} +]} diff --git a/spec/unit/puppet/parser/functions/couchdblookup_spec.rb b/spec/unit/puppet/parser/functions/couchdblookup_spec.rb index 4e9ab76..2af51a9 100755 --- a/spec/unit/puppet/parser/functions/couchdblookup_spec.rb +++ b/spec/unit/puppet/parser/functions/couchdblookup_spec.rb @@ -54,4 +54,20 @@ describe "the couchdblookup function" do result.should raise_error(Puppet::ParseError) end + it "should return an array the values from a couchdb reduced view" do + sample_json = File.open(@datapath + 'map+reduce.txt') + OpenURI.stub!(:open_uri).and_return(sample_json) + + result = @scope.function_couchdblookup(["http://fake/uri", "value"]) + result.should eq(["foo", "bar", "baz"]) + end + + it "should raise a ParseError if a key can't be found in the rows of a couchdb reduced view" do + sample_json = File.open(@datapath + 'map+reduce.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 |