summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2015-03-25 14:02:29 +0000
committerTom Hughes <tom@compton.nu>2015-03-25 14:03:26 +0000
commit02498e3a3233bd47062b24c0ba4526df761e1251 (patch)
tree46bba3ab459ba82437f6c7207b43d35a93cea465
parentfb885002b132b46677a4c1e4b4fbedf5a19e331c (diff)
downloadchef-02498e3a3233bd47062b24c0ba4526df761e1251.tar.gz
Test that search queries make progress
-rw-r--r--spec/unit/search/query_spec.rb24
1 files changed, 24 insertions, 0 deletions
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 }