summaryrefslogtreecommitdiff
path: root/spec/unit/provider/remote_file_spec.rb
diff options
context:
space:
mode:
authorJesse Campbell <hikeit@gmail.com>2013-02-05 16:13:50 -0500
committerBryan McLellan <btm@opscode.com>2013-02-26 11:11:43 -0800
commit0a0c8c4e6134f843c16127eaa666f454ddd3e3fb (patch)
treeb783752945505e48837b3b4c2d5779347d4ba401 /spec/unit/provider/remote_file_spec.rb
parent3dff33d68b43c67dac5b6f5b4bf27309f5c0a6ff (diff)
downloadchef-0a0c8c4e6134f843c16127eaa666f454ddd3e3fb.tar.gz
Update existing tests to function with RestClient::Request
Diffstat (limited to 'spec/unit/provider/remote_file_spec.rb')
-rw-r--r--spec/unit/provider/remote_file_spec.rb36
1 files changed, 17 insertions, 19 deletions
diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb
index 78d7e77121..d7fbad52ef 100644
--- a/spec/unit/provider/remote_file_spec.rb
+++ b/spec/unit/provider/remote_file_spec.rb
@@ -46,11 +46,9 @@ describe Chef::Provider::RemoteFile, "action_create" do
describe "when fetching the file from the remote" do
before(:each) do
@tempfile = Tempfile.new("chef-rspec-remote_file_spec-line#{__LINE__}--")
+ @rawresp = RestClient::RawResponse.new(@tempfile, nil, nil)
- @rest = mock(Chef::REST, { })
- Chef::REST.stub!(:new).and_return(@rest)
- @rest.stub!(:streaming_request).and_return(@tempfile)
- @rest.stub!(:create_url) { |url| url }
+ RestClient::Request.stub!(:execute).and_return(@rawresp)
@resource.cookbook_name = "monkey"
@provider.stub!(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa")
@@ -66,7 +64,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
end
before do
- @resource.source("http://opscode.com/seattle.txt")
+ @resource.source("http://localhost:9000/seattle.txt")
end
describe "and the target location's enclosing directory does not exist" do
@@ -81,19 +79,19 @@ describe Chef::Provider::RemoteFile, "action_create" do
shared_examples_for "source specified with multiple URIs" do
it "should try to download the next URI when the first one fails" do
- @rest.should_receive(:streaming_request).with("http://foo", {}).once.and_raise(SocketError)
- @rest.should_receive(:streaming_request).with("http://bar", {}).once.and_return(@tempfile)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://foo", :raw_response => true).once.and_raise(SocketError)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://bar", :raw_response => true).once.and_return(@rawresp)
@provider.run_action(:create)
end
it "should raise an exception when all the URIs fail" do
- @rest.should_receive(:streaming_request).with("http://foo", {}).once.and_raise(SocketError)
- @rest.should_receive(:streaming_request).with("http://bar", {}).once.and_raise(SocketError)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://foo", :raw_response => true).once.and_raise(SocketError)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://bar", :raw_response => true).once.and_raise(SocketError)
lambda { @provider.run_action(:create) }.should raise_error(SocketError)
end
it "should download from only one URI when the first one works" do
- @rest.should_receive(:streaming_request).once.and_return(@tempfile)
+ RestClient::Request.should_receive(:execute).once.and_return(@rawresp)
@provider.run_action(:create)
end
@@ -123,7 +121,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
end
it "does not download the file" do
- @rest.should_not_receive(:fetch).with("http://opscode.com/seattle.txt").and_return(@tempfile)
+ RestClient::Request.should_not_receive(:execute).with("http://localhost:9000/seattle.txt").and_return(@tempfile)
@provider.run_action(:create)
end
@@ -140,7 +138,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
end
it "should not download the file if the checksum is a partial match from the beginning" do
- @rest.should_not_receive(:fetch).with("http://opscode.com/seattle.txt").and_return(@tempfile)
+ @rawresp.should_not_receive(:fetch).with("http://localhost:9000/seattle.txt").and_return(@tempfile)
@provider.run_action(:create)
end
@@ -154,7 +152,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
describe "and the existing file doesn't match the given checksum" do
it "downloads the file" do
@resource.checksum("this hash doesn't match")
- @rest.should_receive(:streaming_request).with("http://opscode.com/seattle.txt", {}).and_return(@tempfile)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://localhost:9000/seattle.txt", :raw_response => true).and_return(@rawresp)
@provider.stub!(:update_new_file_state)
@provider.run_action(:create)
end
@@ -162,7 +160,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
it "does not consider the checksum a match if the matching string is offset" do
# i.e., the existing file is "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa"
@resource.checksum("fd012fd")
- @rest.should_receive(:streaming_request).with("http://opscode.com/seattle.txt", {}).and_return(@tempfile)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://localhost:9000/seattle.txt", :raw_response => true).and_return(@rawresp)
@provider.stub!(:update_new_file_state)
@provider.run_action(:create)
end
@@ -173,7 +171,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
describe "and the resource doesn't specify a checksum" do
it "should download the file from the remote URL" do
@resource.checksum(nil)
- @rest.should_receive(:streaming_request).with("http://opscode.com/seattle.txt", {}).and_return(@tempfile)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://localhost:9000/seattle.txt", :raw_response => true).and_return(@rawresp)
@provider.run_action(:create)
end
end
@@ -190,7 +188,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
context "and the target file is a tarball" do
before do
@resource.path(File.expand_path(File.join(CHEF_SPEC_DATA, "seattle.tar.gz")))
- Chef::REST.should_receive(:new).with("http://opscode.com/seattle.txt", nil, nil, :disable_gzip => true).and_return(@rest)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://localhost:9000/seattle.txt", :raw_response => true).and_return(@rawresp)
end
it "disables gzip in the http client" do
@@ -202,7 +200,7 @@ describe Chef::Provider::RemoteFile, "action_create" do
context "and the source appears to be a tarball" do
before do
@resource.source("http://example.com/tarball.tgz")
- Chef::REST.should_receive(:new).with("http://example.com/tarball.tgz", nil, nil, :disable_gzip => true).and_return(@rest)
+ RestClient::Request.should_receive(:execute).with(:method => :get, :url => "http://example.com/tarball.tgz", :raw_response => true).and_return(@rawresp)
end
it "disables gzip in the http client" do
@@ -213,14 +211,14 @@ describe Chef::Provider::RemoteFile, "action_create" do
it "should raise an exception if it's any other kind of retriable response than 304" do
r = Net::HTTPMovedPermanently.new("one", "two", "three")
e = Net::HTTPRetriableError.new("301", r)
- @rest.stub!(:streaming_request).and_raise(e)
+ RestClient::Request.stub!(:execute).and_raise(e)
lambda { @provider.run_action(:create) }.should raise_error(Net::HTTPRetriableError)
end
it "should raise an exception if anything else happens" do
r = Net::HTTPBadRequest.new("one", "two", "three")
e = Net::HTTPServerException.new("fake exception", r)
- @rest.stub!(:streaming_request).and_raise(e)
+ RestClient::Request.stub!(:execute).and_raise(e)
lambda { @provider.run_action(:create) }.should raise_error(Net::HTTPServerException)
end