summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-10-08 17:44:23 -0700
committerdanielsdeleo <dan@opscode.com>2013-10-08 17:44:23 -0700
commita44352871130b3adea32c93bdaca696b518a335a (patch)
treeaa160fadd1d7c6eb4daea570b79c7a9df8d7a6c1
parent61dd5990429afa67800607533b9c306d5633e5b8 (diff)
downloadchef-a44352871130b3adea32c93bdaca696b518a335a.tar.gz
Convert http_request provider to HTTP::Simple
-rw-r--r--lib/chef/provider/http_request.rb16
-rw-r--r--spec/unit/provider/http_request_spec.rb30
2 files changed, 23 insertions, 23 deletions
diff --git a/lib/chef/provider/http_request.rb b/lib/chef/provider/http_request.rb
index a5bc3b5e04..1e0aa8b4a0 100644
--- a/lib/chef/provider/http_request.rb
+++ b/lib/chef/provider/http_request.rb
@@ -17,26 +17,27 @@
#
require 'tempfile'
+require 'chef/http/simple'
class Chef
class Provider
class HttpRequest < Chef::Provider
- attr_accessor :rest
+ attr_accessor :http
def whyrun_supported?
true
end
def load_current_resource
- @rest = Chef::REST.new(@new_resource.url, nil, nil)
+ @http = Chef::HTTP::Simple.new(@new_resource.url)
end
# Send a HEAD request to @new_resource.url, with ?message=@new_resource.message
def action_head
message = check_message(@new_resource.message)
# returns true from Chef::REST if returns 2XX (Net::HTTPSuccess)
- modified = @rest.head(
+ modified = @http.head(
"#{@new_resource.url}?message=#{message}",
@new_resource.headers
)
@@ -53,9 +54,8 @@ class Chef
converge_by("#{@new_resource} GET to #{@new_resource.url}") do
message = check_message(@new_resource.message)
- body = @rest.get(
+ body = @http.get(
"#{@new_resource.url}?message=#{message}",
- false,
@new_resource.headers
)
Chef::Log.info("#{@new_resource} GET to #{@new_resource.url} successful")
@@ -67,7 +67,7 @@ class Chef
def action_put
converge_by("#{@new_resource} PUT to #{@new_resource.url}") do
message = check_message(@new_resource.message)
- body = @rest.put(
+ body = @http.put(
"#{@new_resource.url}",
message,
@new_resource.headers
@@ -81,7 +81,7 @@ class Chef
def action_post
converge_by("#{@new_resource} POST to #{@new_resource.url}") do
message = check_message(@new_resource.message)
- body = @rest.post(
+ body = @http.post(
"#{@new_resource.url}",
message,
@new_resource.headers
@@ -94,7 +94,7 @@ class Chef
# Send a DELETE request to @new_resource.url
def action_delete
converge_by("#{@new_resource} DELETE to #{@new_resource.url}") do
- body = @rest.delete(
+ body = @http.delete(
"#{@new_resource.url}",
@new_resource.headers
)
diff --git a/spec/unit/provider/http_request_spec.rb b/spec/unit/provider/http_request_spec.rb
index 436eaec558..e8ce5f9ae3 100644
--- a/spec/unit/provider/http_request_spec.rb
+++ b/spec/unit/provider/http_request_spec.rb
@@ -35,7 +35,7 @@ describe Chef::Provider::HttpRequest do
describe "load_current_resource" do
it "should set up a Chef::REST client, with no authentication" do
- Chef::REST.should_receive(:new).with(@new_resource.url, nil, nil)
+ Chef::HTTP::Simple.should_receive(:new).with(@new_resource.url)
@provider.load_current_resource
end
end
@@ -45,21 +45,21 @@ describe Chef::Provider::HttpRequest do
# run_action(x) forces load_current_resource to run;
# that would overwrite our supplied mock Chef::Rest # object
@provider.stub!(:load_current_resource).and_return(true)
- @rest = mock("Chef::REST")
- @provider.rest = @rest
+ @http = mock("Chef::REST")
+ @provider.http = @http
end
describe "action_get" do
it "should inflate a message block at runtime" do
@new_resource.message { "return" }
- @rest.should_receive(:get).with("http://www.opscode.com/?message=return", false, {})
+ @http.should_receive(:get).with("http://www.opscode.com/?message=return", {})
@provider.run_action(:get)
@new_resource.should be_updated
end
it "should run a GET request" do
- @rest.should_receive(:get).with("http://www.opscode.com/?message=is cool", false, {})
+ @http.should_receive(:get).with("http://www.opscode.com/?message=is cool", {})
@provider.run_action(:get)
@new_resource.should be_updated
end
@@ -67,14 +67,14 @@ describe Chef::Provider::HttpRequest do
describe "action_put" do
it "should run a PUT request with the message as the payload" do
- @rest.should_receive(:put).with("http://www.opscode.com/", @new_resource.message, {})
+ @http.should_receive(:put).with("http://www.opscode.com/", @new_resource.message, {})
@provider.run_action(:put)
@new_resource.should be_updated
end
it "should inflate a message block at runtime" do
@new_resource.stub!(:message).and_return(lambda { "return" })
- @rest.should_receive(:put).with("http://www.opscode.com/", "return", {})
+ @http.should_receive(:put).with("http://www.opscode.com/", "return", {})
@provider.run_action(:put)
@new_resource.should be_updated
end
@@ -82,14 +82,14 @@ describe Chef::Provider::HttpRequest do
describe "action_post" do
it "should run a PUT request with the message as the payload" do
- @rest.should_receive(:post).with("http://www.opscode.com/", @new_resource.message, {})
+ @http.should_receive(:post).with("http://www.opscode.com/", @new_resource.message, {})
@provider.run_action(:post)
@new_resource.should be_updated
end
it "should inflate a message block at runtime" do
@new_resource.message { "return" }
- @rest.should_receive(:post).with("http://www.opscode.com/", "return", {})
+ @http.should_receive(:post).with("http://www.opscode.com/", "return", {})
@provider.run_action(:post)
@new_resource.should be_updated
end
@@ -97,7 +97,7 @@ describe Chef::Provider::HttpRequest do
describe "action_delete" do
it "should run a DELETE request" do
- @rest.should_receive(:delete).with("http://www.opscode.com/", {})
+ @http.should_receive(:delete).with("http://www.opscode.com/", {})
@provider.run_action(:delete)
@new_resource.should be_updated
end
@@ -105,30 +105,30 @@ describe Chef::Provider::HttpRequest do
describe "action_head" do
before do
- @provider.rest = @rest
+ @provider.http = @http
end
it "should inflate a message block at runtime" do
@new_resource.message { "return" }
- @rest.should_receive(:head).with("http://www.opscode.com/?message=return", {}).and_return("")
+ @http.should_receive(:head).with("http://www.opscode.com/?message=return", {}).and_return("")
@provider.run_action(:head)
@new_resource.should be_updated
end
it "should run a HEAD request" do
- @rest.should_receive(:head).with("http://www.opscode.com/?message=is cool", {}).and_return("")
+ @http.should_receive(:head).with("http://www.opscode.com/?message=is cool", {}).and_return("")
@provider.run_action(:head)
@new_resource.should be_updated
end
it "should run a HEAD request with If-Modified-Since header" do
@new_resource.headers "If-Modified-Since" => File.mtime(__FILE__).httpdate
- @rest.should_receive(:head).with("http://www.opscode.com/?message=is cool", @new_resource.headers)
+ @http.should_receive(:head).with("http://www.opscode.com/?message=is cool", @new_resource.headers)
@provider.run_action(:head)
end
it "doesn't call converge_by if HEAD does not return modified" do
- @rest.should_receive(:head).and_return(false)
+ @http.should_receive(:head).and_return(false)
@provider.should_not_receive(:converge_by)
@provider.run_action(:head)
end