From 1d68d201ac65004c90dea55de882239026b9067e Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 22 Apr 2014 17:47:45 -0700 Subject: adding more func specs --- spec/functional/rest_spec.rb | 29 +++++++++++++++++++++++++++++ spec/support/shared/functional/http.rb | 16 ++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/spec/functional/rest_spec.rb b/spec/functional/rest_spec.rb index 7c6b1872ef..29427dd5f4 100644 --- a/spec/functional/rest_spec.rb +++ b/spec/functional/rest_spec.rb @@ -91,4 +91,33 @@ describe Chef::REST do end it_behaves_like "downloading all the things" + + context "rest endpoints" do + it "gets json inflated nodes via get_rest" do + nodes = Chef::REST.new("http://localhost:9000").get_rest("nodes") + expect(nodes).to be_a(Hash) + expect(nodes['foo']).to eql("https://api.opscode.com/organizations/scriptkiddie/nodes/foo") + end + + it "gets json inflated nodes via get" do + nodes = Chef::REST.new("http://localhost:9000").get("nodes") + expect(nodes).to be_a(Hash) + expect(nodes['foo']).to eql("https://api.opscode.com/organizations/scriptkiddie/nodes/foo") + end + + it "gets raw JSON to a tempfile via get_rest" do + tempfile = Chef::REST.new("http://localhost:9000").get_rest("nodes", true) + tempfile.close + nodes = JSON.parse(IO.read(tempfile.path)) + expect(nodes['foo']).to eql("https://api.opscode.com/organizations/scriptkiddie/nodes/foo") + end + + it "gets raw JSON to a tempfile via get" do + tempfile = Chef::REST.new("http://localhost:9000").get("nodes", true) + tempfile.close + nodes = JSON.parse(IO.read(tempfile.path)) + expect(nodes['foo']).to eql("https://api.opscode.com/organizations/scriptkiddie/nodes/foo") + end + end + end diff --git a/spec/support/shared/functional/http.rb b/spec/support/shared/functional/http.rb index c362ecaa18..d3214b77f1 100644 --- a/spec/support/shared/functional/http.rb +++ b/spec/support/shared/functional/http.rb @@ -155,6 +155,22 @@ module ChefHTTPShared } ) + # + # RESTful endpoints + # + json_response = <<-EOF +{ + "foo": "https://api.opscode.com/organizations/scriptkiddie/nodes/foo", + "bar": "https://api.opscode.com/organizations/scriptkiddie/nodes/bar" +} + EOF + @api.get('/nodes', 200, json_response, + { + 'Content-Type' => 'application/json', + 'Content-Length' => json_response.bytesize.to_s, + } + ) + end def stop_tiny_server -- cgit v1.2.1