diff options
author | Thom May <thom@clearairturbulence.org> | 2015-04-16 13:53:07 +0100 |
---|---|---|
committer | Thom May <thom@clearairturbulence.org> | 2015-04-16 13:53:07 +0100 |
commit | 3508db14540c5c9262974081aff4d22e02df810d (patch) | |
tree | 4572df34ec6fb8d58d58551709ec0a01a008dd37 | |
parent | e358c40aee1c7d9a4ea9d03bfeee6d35280df8df (diff) | |
parent | 02498e3a3233bd47062b24c0ba4526df761e1251 (diff) | |
download | chef-3508db14540c5c9262974081aff4d22e02df810d.tar.gz |
Merge pull request #3135 from tomhughes/search
Ensure that a search query makes progress
-rw-r--r-- | lib/chef/search/query.rb | 2 | ||||
-rw-r--r-- | spec/unit/search/query_spec.rb | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/chef/search/query.rb b/lib/chef/search/query.rb index 8656e810db..6469a18c49 100644 --- a/lib/chef/search/query.rb +++ b/lib/chef/search/query.rb @@ -89,7 +89,7 @@ WARNDEP if block response["rows"].each { |row| block.call(row) if row } unless (response["start"] + response["rows"].length) >= response["total"] - args_h[:start] = response["start"] + (args_h[:rows] || 0) + args_h[:start] = response["start"] + response["rows"].length search(type, query, args_h, &block) end true diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 2fb197b183..59ac80f228 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -81,6 +81,9 @@ describe Chef::Search::Query do end describe "search" do + let(:query_string) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0" } + let(:query_string_continue) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=4" } + let(:response) { { "rows" => [ { "name" => "my-name-is-node", @@ -140,6 +143,19 @@ describe Chef::Search::Query do "total" => 4 } } + let(:big_response) { + r = response.dup + r["total"] = 8 + r + } + + let(:big_response_end) { + r = response.dup + r["start"] = 4 + r["total"] = 8 + r + } + it "accepts a type as the first argument" do expect { query.search("node") }.not_to raise_error expect { query.search(:node) }.not_to raise_error @@ -195,6 +211,14 @@ describe Chef::Search::Query do query.search(:node, "*:*", sort: nil, start: 0, rows: 1) { |r| @call_me.do(r) } end + it "sends multiple API requests when the server indicates there is more data" do + expect(rest).to receive(:get_rest).with(query_string).and_return(big_response) + expect(rest).to receive(:get_rest).with(query_string_continue).and_return(big_response_end) + query.search(:node, "platform:rhel") do |r| + nil + end + end + context "when :filter_result is provided as a result" do include_context "filtered search" do let(:filter_key) { :filter_result } |