diff options
Diffstat (limited to 'spec/unit/search')
-rw-r--r-- | spec/unit/search/query_spec.rb | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index f85b1760d4..c390f658bc 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -20,7 +20,7 @@ require 'spec_helper' require 'chef/search/query' describe Chef::Search::Query do - let(:rest) { double("Chef::REST") } + let(:rest) { double("Chef::ServerAPI") } let(:query) { Chef::Search::Query.new } shared_context "filtered search" do @@ -76,8 +76,8 @@ describe Chef::Search::Query do end before(:each) do - allow(Chef::REST).to receive(:new).and_return(rest) - allow(rest).to receive(:get_rest).and_return(response) + allow(Chef::ServerAPI).to receive(:new).and_return(rest) + allow(rest).to receive(:get).and_return(response) end describe "search" do @@ -91,6 +91,7 @@ describe Chef::Search::Query do { "name" => "my-name-is-node", "chef_environment" => "elysium", "platform" => "rhel", + "run_list" => [], "automatic" => { "languages" => { "ruby" => { @@ -104,6 +105,7 @@ describe Chef::Search::Query do { "name" => "my-name-is-jonas", "chef_environment" => "hades", "platform" => "rhel", + "run_list" => [], "automatic" => { "languages" => { "ruby" => { @@ -117,6 +119,7 @@ describe Chef::Search::Query do { "name" => "my-name-is-flipper", "chef_environment" => "elysium", "platform" => "rhel", + "run_list" => [], "automatic" => { "languages" => { "ruby" => { @@ -130,6 +133,7 @@ describe Chef::Search::Query do { "name" => "my-name-is-butters", "chef_environment" => "moon", "platform" => "rhel", + "run_list" => [], "automatic" => { "languages" => { "ruby" => { @@ -173,27 +177,27 @@ describe Chef::Search::Query do end it "queries for every object of a type by default" do - expect(rest).to receive(:get_rest).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response) + expect(rest).to receive(:get).with("search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response) query.search(:node) end it "allows a custom query" do - expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response) + expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0").and_return(response) query.search(:node, "platform:rhel") end it "lets you set a sort order" do - expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=id%20desc&start=0").and_return(response) + expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=id%20desc&start=0").and_return(response) query.search(:node, "platform:rhel", sort: "id desc") end it "lets you set a starting object" do - expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=2").and_return(response) + expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=2").and_return(response) query.search(:node, "platform:rhel", start: 2) end it "lets you set how many rows to return" do - expect(rest).to receive(:get_rest).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=40").and_return(response) + expect(rest).to receive(:get).with("search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=40").and_return(response) query.search(:node, "platform:rhel", rows: 40) end @@ -211,27 +215,27 @@ describe Chef::Search::Query do it "calls a block for each object in the response" do @call_me = double("blocky") - response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) } + response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) } query.search(:node) { |r| @call_me.do(r) } end it "pages through the responses" do @call_me = double("blocky") - response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) } + response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) } query.search(:node, "*:*", sort: nil, start: 0, rows: 4) { |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) + expect(rest).to receive(:get).with(query_string).and_return(big_response) + expect(rest).to receive(:get).with(query_string_continue).and_return(big_response_end) query.search(:node, "platform:rhel") do |r| nil end end it "paginates correctly in the face of filtered nodes" do - expect(rest).to receive(:get_rest).with(query_string_with_rows).and_return(big_response_empty) - expect(rest).to receive(:get_rest).with(query_string_continue_with_rows).and_return(big_response_end) + expect(rest).to receive(:get).with(query_string_with_rows).and_return(big_response_empty) + expect(rest).to receive(:get).with(query_string_continue_with_rows).and_return(big_response_end) query.search(:node, "platform:rhel", rows: 4) do |r| nil end @@ -242,7 +246,7 @@ describe Chef::Search::Query do let(:filter_key) { :filter_result } before(:each) do - expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response) + expect(rest).to receive(:post).with(query_string, args[filter_key]).and_return(response) end it "returns start" do @@ -276,7 +280,7 @@ describe Chef::Search::Query do end it "returns an array of filtered hashes" do - expect(rest).to receive(:post_rest).with(query_string, args[filter_key]).and_return(response) + expect(rest).to receive(:post).with(query_string, args[filter_key]).and_return(response) results = query.partial_search(:node, "platform:rhel", args) expect(results[0]).to match_array(response_rows) end |