diff options
Diffstat (limited to 'spec/unit/provider/remote_file/http_spec.rb')
-rw-r--r-- | spec/unit/provider/remote_file/http_spec.rb | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb index 89f2964076..12c75d4144 100644 --- a/spec/unit/provider/remote_file/http_spec.rb +++ b/spec/unit/provider/remote_file/http_spec.rb @@ -19,7 +19,6 @@ require "spec_helper" describe Chef::Provider::RemoteFile::HTTP do - let(:uri) { URI.parse("http://opscode.com/seattle.txt") } let(:existing_file_source) { nil } @@ -44,9 +43,7 @@ describe Chef::Provider::RemoteFile::HTTP do let(:cache_control_data) { Chef::Provider::RemoteFile::CacheControlData.new(uri) } describe "generating cache control headers" do - context "and there is no valid cache control data for this URI on disk" do - before do expect(Chef::Provider::RemoteFile::CacheControlData).to receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) end @@ -61,14 +58,12 @@ describe Chef::Provider::RemoteFile::HTTP do end it "has the user-specified custom headers" do - expect(fetcher.headers).to eq({"x-myapp-header" => "custom-header-value"}) + expect(fetcher.headers).to eq({ "x-myapp-header" => "custom-header-value" }) end end - end context "and the cache control data matches the existing file" do - # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26 let(:etag) { "\"a-strong-unique-identifier\"" } @@ -120,7 +115,6 @@ describe Chef::Provider::RemoteFile::HTTP do expect(headers["if-modified-since"]).to eq("custom-last-modified") end end - end context "and etag support is enabled" do @@ -149,11 +143,9 @@ describe Chef::Provider::RemoteFile::HTTP do end end end - end describe "when fetching the uri" do - let(:expected_http_opts) { {} } let(:expected_http_args) { [uri, expected_http_opts] } @@ -178,19 +170,15 @@ describe Chef::Provider::RemoteFile::HTTP do expect(Chef::HTTP::Simple).to receive(:new).with(*expected_http_args).and_return(rest) end - describe "and the request does not return new content" do - it "should return a nil tempfile for a 304 HTTPNotModifed" do # Streaming request returns nil for 304 errors allow(rest).to receive(:streaming_request).and_return(nil) expect(fetcher.fetch).to be_nil end - end describe "and the request returns new content" do - let(:fetched_content_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" } before do @@ -207,7 +195,7 @@ describe Chef::Provider::RemoteFile::HTTP do end context "and the response does not contain an etag" do - let(:last_response) { {"etag" => nil} } + let(:last_response) { { "etag" => nil } } it "does not include an etag in the result" do fetcher.fetch expect(cache_control_data.etag).to be_nil @@ -217,7 +205,7 @@ describe Chef::Provider::RemoteFile::HTTP do end context "and the response has an etag header" do - let(:last_response) { {"etag" => "abc123"} } + let(:last_response) { { "etag" => "abc123" } } it "includes the etag value in the response" do fetcher.fetch @@ -225,11 +213,10 @@ describe Chef::Provider::RemoteFile::HTTP do expect(cache_control_data.mtime).to be_nil expect(cache_control_data.checksum).to eq(fetched_content_checksum) end - end context "and the response has no Date or Last-Modified header" do - let(:last_response) { {"date" => nil, "last_modified" => nil} } + let(:last_response) { { "date" => nil, "last_modified" => nil } } it "does not set an mtime in the result" do # RFC 2616 suggests that servers that do not set a Date header do not # have a reliable clock, so no use in making them deal with dates. @@ -243,7 +230,7 @@ describe Chef::Provider::RemoteFile::HTTP do context "and the response has a Last-Modified header" do let(:last_response) do # Last-Modified should be preferred to Date if both are set - {"date" => "Fri, 17 May 2013 23:23:23 GMT", "last_modified" => "Fri, 17 May 2013 11:11:11 GMT"} + { "date" => "Fri, 17 May 2013 23:23:23 GMT", "last_modified" => "Fri, 17 May 2013 11:11:11 GMT" } end it "sets the mtime to the Last-Modified time in the response" do @@ -255,7 +242,7 @@ describe Chef::Provider::RemoteFile::HTTP do context "and the response has a Date header but no Last-Modified header" do let(:last_response) do - {"date" => "Fri, 17 May 2013 23:23:23 GMT", "last_modified" => nil} + { "date" => "Fri, 17 May 2013 23:23:23 GMT", "last_modified" => nil } end it "sets the mtime to the Date in the response" do @@ -264,13 +251,11 @@ describe Chef::Provider::RemoteFile::HTTP do expect(cache_control_data.mtime).to eq(last_response["date"]) expect(cache_control_data.checksum).to eq(fetched_content_checksum) end - end context "and the target file is a tarball [CHEF-3140]" do - let(:uri) { URI.parse("http://opscode.com/tarball.tgz") } - let(:expected_http_opts) { {:disable_gzip => true} } + let(:expected_http_opts) { { :disable_gzip => true } } # CHEF-3140 # Some servers return tarballs as content type tar and encoding gzip, which @@ -296,8 +281,5 @@ describe Chef::Provider::RemoteFile::HTTP do end end end - end - end - |