summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@chef.io>2015-11-04 16:37:41 -0800
committerChris Doherty <cdoherty@chef.io>2015-11-10 14:50:22 -0800
commit8297ed53a6c00421eddba8fa976a9ec3ceb916f3 (patch)
treea9e363472f2cafde672bb5c2fc68e310b9e9248c
parent3627567298769fcc3e6d9904c0f52a810e5a26b4 (diff)
downloadchef-zero-8297ed53a6c00421eddba8fa976a9ec3ceb916f3.tar.gz
Add a dummy GET that returns meaningful values, due to pedant making Solr-related calls.
-rw-r--r--lib/chef_zero/endpoints/dummy_endpoint.rb31
-rw-r--r--lib/chef_zero/server.rb2
-rw-r--r--spec/run_oc_pedant.rb7
3 files changed, 39 insertions, 1 deletions
diff --git a/lib/chef_zero/endpoints/dummy_endpoint.rb b/lib/chef_zero/endpoints/dummy_endpoint.rb
new file mode 100644
index 0000000..fe16a7e
--- /dev/null
+++ b/lib/chef_zero/endpoints/dummy_endpoint.rb
@@ -0,0 +1,31 @@
+
+# pedant makes a couple of Solr-related calls from its search_utils.rb file that we can't work around (e.g.
+# with monkeypatching). the necessary Pedant::Config values are set in run_oc_pedant.rb. --cdoherty
+module ChefZero
+ module Endpoints
+ class DummyEndpoint < RestBase
+ # called by #direct_solr_query, once each for roles, nodes, and data bag items. each RSpec example makes
+ # 3 calls, with the expected sequence of return values [0, 1, 0].
+ def get(request)
+
+ # this could be made less brittle, but if things change to have more than 3 cycles, we should really
+ # be notified by a spec failure.
+ @mock_values ||= ([0, 1, 0] * 3).map { |val| make_response(val) }
+
+ retval = @mock_values.shift
+ json_response(200, retval)
+ end
+
+ # called by #force_solr_commit in pedant's , which doesn't check the return value.
+ def post(request)
+ # sure thing!
+ json_response(200, { message: "This dummy POST endpoint didn't do anything." })
+ end
+
+ def make_response(value)
+ { "response" => { "numFound" => value } }
+ end
+ end
+ end
+end
+
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 5723ae4..d9e3931 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -47,6 +47,7 @@ require 'chef_zero/endpoints/cookbook_endpoint'
require 'chef_zero/endpoints/cookbook_version_endpoint'
require 'chef_zero/endpoints/containers_endpoint'
require 'chef_zero/endpoints/container_endpoint'
+require 'chef_zero/endpoints/dummy_endpoint'
require 'chef_zero/endpoints/data_bags_endpoint'
require 'chef_zero/endpoints/data_bag_endpoint'
require 'chef_zero/endpoints/data_bag_item_endpoint'
@@ -528,6 +529,7 @@ module ChefZero
end
result + [
# Both
+ [ "/dummy", DummyEndpoint.new(self) ],
[ "/organizations/*/clients", ActorsEndpoint.new(self) ],
[ "/organizations/*/clients/*", ActorEndpoint.new(self) ],
[ "/organizations/*/cookbooks", CookbooksEndpoint.new(self) ],
diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb
index a11448c..df1eba1 100644
--- a/spec/run_oc_pedant.rb
+++ b/spec/run_oc_pedant.rb
@@ -29,7 +29,12 @@ begin
# Pedant::Config.rerun = true
Pedant.config.suite = 'api'
- Pedant.config.internal_server = 'http://localhost:8889'
+ Pedant.config.internal_server = Pedant::Config.search_server = 'http://localhost:8889'
+
+ # see dummy_endpoint.rb.
+ Pedant.config.search_commit_url = "/dummy"
+ Pedant::Config.search_url_fmt = "/dummy?fq=+X_CHEF_type_CHEF_X:%{type}&q=%{query}&wt=json"
+
Pedant.config[:config_file] = 'spec/support/oc_pedant.rb'
Pedant.config[:server_api_version] = 0