summaryrefslogtreecommitdiff
path: root/spec/unit/provider/remote_file/http_spec.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@opscode.com>2013-04-15 14:02:33 -0700
committerLamont Granquist <lamont@opscode.com>2013-04-15 14:02:33 -0700
commitb1e692497baf11a97a2a2e3012b2fbe6b996aafa (patch)
tree48d53415474ae64dc9ce65a34cfd05aafa4a3316 /spec/unit/provider/remote_file/http_spec.rb
parent51bb051018a8236df20e69d344d85e4f80d3c1f3 (diff)
downloadchef-b1e692497baf11a97a2a2e3012b2fbe6b996aafa.tar.gz
add http specs
Diffstat (limited to 'spec/unit/provider/remote_file/http_spec.rb')
-rw-r--r--spec/unit/provider/remote_file/http_spec.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb
index 3ecbf38754..360a781cb1 100644
--- a/spec/unit/provider/remote_file/http_spec.rb
+++ b/spec/unit/provider/remote_file/http_spec.rb
@@ -28,6 +28,7 @@ describe Chef::Provider::RemoteFile::HTTP do
before do
@new_resource = mock('Chef::Resource::RemoteFile (new_resource)')
@current_resource = mock('Chef::Resource::RemoteFile (current_resource)')
+ @new_resource.stub!(:headers).and_return({})
end
describe "when the current resource has no source" do
@@ -40,10 +41,56 @@ describe Chef::Provider::RemoteFile::HTTP do
fetcher.uri.should == @uri
end
+ it "stores any headers it is passed" do
+ headers = { "foo" => "foo", "bar" => "bar", "baz" => "baz" }
+ @new_resource.stub!(:headers).and_return(headers)
+ fetcher = Chef::Provider::RemoteFile::HTTP.new(@uri, @new_resource, @current_resource)
+ fetcher.headers.should == headers
+ end
+
end
describe "when the current resource has a source" do
+
+ it "stores the last_modified string in the headers when we are using last_modified headers and the uri matches the cache" do
+ @current_resource.stub!(:source).and_return(["http://opscode.com/seattle.txt"])
+ @new_resource.should_receive(:use_last_modified).and_return(true)
+ @current_resource.stub!(:last_modified).and_return(Time.new)
+ @current_resource.stub!(:etag).and_return(nil)
+ Chef::Provider::RemoteFile::Util.should_receive(:uri_matches_string?).with(@uri, @current_resource.source[0]).and_return(true)
+ fetcher = Chef::Provider::RemoteFile::HTTP.new(@uri, @new_resource, @current_resource)
+ fetcher.headers['if-modified-since'].should == @current_resource.last_modified.strftime("%a, %d %b %Y %H:%M:%S %Z")
+ fetcher.headers.should_not have_key('if-none-match')
+ end
+
+ it "stores the etag string in the headers when we are using etag headers and the uri matches the cache" do
+ @current_resource.stub!(:source).and_return(["http://opscode.com/seattle.txt"])
+ @new_resource.should_receive(:use_etag).and_return(true)
+ @new_resource.should_receive(:use_last_modified).and_return(false)
+ @current_resource.stub!(:last_modified).and_return(Time.new)
+ @current_resource.stub!(:etag).and_return("a_unique_identifier")
+ Chef::Provider::RemoteFile::Util.should_receive(:uri_matches_string?).with(@uri, @current_resource.source[0]).and_return(true)
+ fetcher = Chef::Provider::RemoteFile::HTTP.new(@uri, @new_resource, @current_resource)
+ fetcher.headers['if-none-match'].should == "\"#{@current_resource.etag}\""
+ fetcher.headers.should_not have_key('if-modified-since')
+ end
+
+ end
+
+ describe "when use_last_modified is disabled in the new_resource" do
+
+ it "stores nil for the last_modified date" do
+ @current_resource.stub!(:source).and_return(["http://opscode.com/seattle.txt"])
+ @new_resource.should_receive(:use_last_modified).and_return(false)
+ @current_resource.stub!(:last_modified).and_return(Time.new)
+ @current_resource.stub!(:etag).and_return(nil)
+ Chef::Provider::RemoteFile::Util.should_receive(:uri_matches_string?).with(@uri, @current_resource.source[0]).and_return(true)
+ fetcher = Chef::Provider::RemoteFile::HTTP.new(@uri, @new_resource, @current_resource)
+ fetcher.headers.should_not have_key('if-modified-since')
+ fetcher.headers.should_not have_key('if-none-match')
+ end
end
+
end
describe "when fetching the uri" do