diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2010-10-28 14:49:37 -0700 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2010-10-28 15:09:15 -0700 |
| commit | 45a9a97285d99db524d5330c236352b29e5884ed (patch) | |
| tree | 65d227ec46a7259a2a06221889cb48d1698dff3a /spec/unit/network/http | |
| parent | e559b48d51c53c4a345353de1e196634c7430195 (diff) | |
| download | puppet-45a9a97285d99db524d5330c236352b29e5884ed.tar.gz puppet-45a9a97285d99db524d5330c236352b29e5884ed.tar.xz puppet-45a9a97285d99db524d5330c236352b29e5884ed.zip | |
(#5132) Provide a query REST interface for inventory
This REST interface returns a list of nodes that match a fact query.
Fact queries can use (in)equality testing as a string comparison, and >,
<, >=, <= numerical comparisons. Multiple tests can be done as AND
comparisons, not OR.
The fact queries need to be prefixed by facts, and the comparisons other
than equality are specified with a .comparison_type after the fact name.
This will be better explained in the REST documentation on the website.
Searches that don't match anything now return empty array instead of a
404 error.
Diffstat (limited to 'spec/unit/network/http')
| -rw-r--r-- | spec/unit/network/http/api/v1_spec.rb | 12 | ||||
| -rwxr-xr-x | spec/unit/network/http/handler_spec.rb | 11 |
2 files changed, 19 insertions, 4 deletions
diff --git a/spec/unit/network/http/api/v1_spec.rb b/spec/unit/network/http/api/v1_spec.rb index c593242c0..8d507046f 100644 --- a/spec/unit/network/http/api/v1_spec.rb +++ b/spec/unit/network/http/api/v1_spec.rb @@ -72,6 +72,18 @@ describe Puppet::Network::HTTP::API::V1 do @tester.uri2indirection("GET", "/env/foos/bar", {}).method.should == :search end + it "should choose 'find' as the indirection method if the http method is a GET and the indirection name is facts" do + @tester.uri2indirection("GET", "/env/facts/bar", {}).method.should == :find + end + + it "should choose 'save' as the indirection method if the http method is a PUT and the indirection name is facts" do + @tester.uri2indirection("PUT", "/env/facts/bar", {}).method.should == :save + end + + it "should choose 'search' as the indirection method if the http method is a GET and the indirection name is inventory" do + @tester.uri2indirection("GET", "/env/inventory/search", {}).method.should == :search + end + it "should choose 'delete' as the indirection method if the http method is a DELETE and the indirection name is singular" do @tester.uri2indirection("DELETE", "/env/foo/bar", {}).method.should == :destroy end diff --git a/spec/unit/network/http/handler_spec.rb b/spec/unit/network/http/handler_spec.rb index 76a9c5530..355f500e6 100755 --- a/spec/unit/network/http/handler_spec.rb +++ b/spec/unit/network/http/handler_spec.rb @@ -305,17 +305,20 @@ describe Puppet::Network::HTTP::Handler do @handler.do_search(@irequest, @request, @response) end - it "should return a 404 when searching returns an empty array" do - @model_class.stubs(:name).returns "my name" - @handler.expects(:set_response).with { |response, body, status| status == 404 } + it "should return [] when searching returns an empty array" do + @handler.expects(:accept_header).with(@request).returns "one,two" @model_class.stubs(:search).returns([]) + @model_class.expects(:render_multiple).with(@oneformat, []).returns "[]" + + + @handler.expects(:set_response).with { |response, data| data == "[]" } @handler.do_search(@irequest, @request, @response) end it "should return a 404 when searching returns nil" do @model_class.stubs(:name).returns "my name" @handler.expects(:set_response).with { |response, body, status| status == 404 } - @model_class.stubs(:search).returns([]) + @model_class.stubs(:search).returns(nil) @handler.do_search(@irequest, @request, @response) end end |
