summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Campbell <hikeit@gmail.com>2013-02-18 11:58:57 -0500
committerJesse Campbell <hikeit@gmail.com>2013-02-18 11:58:57 -0500
commitf372f8ca80444a038b7dfaf1a1f035de7e1a90ca (patch)
tree0e16521cb2d0e2e231cc9f04cce655d3603a628f
parentf54a08a4111482afe78a3c3b521978c882c96652 (diff)
downloadchef-f372f8ca80444a038b7dfaf1a1f035de7e1a90ca.tar.gz
functional test for CHEF-3140
-rw-r--r--spec/data/remote_file/nyan_cat.png.gzbin0 -> 14944 bytes
-rw-r--r--spec/functional/resource/remote_file_spec.rb43
-rw-r--r--spec/tiny_server.rb21
-rw-r--r--spec/unit/resource/remote_file_spec.rb2
4 files changed, 45 insertions, 21 deletions
diff --git a/spec/data/remote_file/nyan_cat.png.gz b/spec/data/remote_file/nyan_cat.png.gz
new file mode 100644
index 0000000000..efa9d4427a
--- /dev/null
+++ b/spec/data/remote_file/nyan_cat.png.gz
Binary files differ
diff --git a/spec/functional/resource/remote_file_spec.rb b/spec/functional/resource/remote_file_spec.rb
index 57a5321ea2..fbb921d48c 100644
--- a/spec/functional/resource/remote_file_spec.rb
+++ b/spec/functional/resource/remote_file_spec.rb
@@ -23,14 +23,6 @@ describe Chef::Resource::RemoteFile do
include_context Chef::Resource::File
let(:file_base) { "remote_file_spec" }
- let(:source) { 'http://localhost:9000/nyan_cat.png' }
- let(:expected_content) do
- content = File.open(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png'), "rb") do |f|
- f.read
- end
- content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
- content
- end
def create_resource
node = Chef::Node.new
@@ -71,13 +63,44 @@ describe Chef::Resource::RemoteFile do
f.read
end
}
+ @api.get("/nyan_cat.png.gz", 200, nil, { 'Content-Type' => 'application/gzip', 'Content-Encoding' => 'gzip' } ) {
+ File.open(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png.gz'), "rb") do |f|
+ f.read
+ end
+ }
end
after(:all) do
@server.stop
end
- it_behaves_like "a file resource"
+ context "when using normal encoding" do
+ let(:source) { 'http://localhost:9000/nyan_cat.png' }
+ let(:expected_content) do
+ content = File.open(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png'), "rb") do |f|
+ f.read
+ end
+ content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
+ content
+ end
+
+ it_behaves_like "a file resource"
- it_behaves_like "a securable resource with reporting"
+ it_behaves_like "a securable resource with reporting"
+ end
+
+ context "when using gzip encoding" do
+ let(:source) { 'http://localhost:9000/nyan_cat.png.gz' }
+ let(:expected_content) do
+ content = File.open(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png.gz'), "rb") do |f|
+ f.read
+ end
+ content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
+ content
+ end
+
+ it_behaves_like "a file resource"
+
+ it_behaves_like "a securable resource with reporting"
+ end
end
diff --git a/spec/tiny_server.rb b/spec/tiny_server.rb
index 9eecf13cec..eb5f5c0fc0 100644
--- a/spec/tiny_server.rb
+++ b/spec/tiny_server.rb
@@ -127,20 +127,20 @@ module TinyServer
@routes = {GET => [], PUT => [], POST => [], DELETE => []}
end
- def get(path, response_code, data=nil, &block)
- @routes[GET] << Route.new(path, Response.new(response_code,data, &block))
+ def get(path, response_code, data=nil, headers=nil, &block)
+ @routes[GET] << Route.new(path, Response.new(response_code, data, headers, &block))
end
- def put(path, response_code, data=nil, &block)
- @routes[PUT] << Route.new(path, Response.new(response_code,data, &block))
+ def put(path, response_code, data=nil, headers=nil, &block)
+ @routes[PUT] << Route.new(path, Response.new(response_code, data, headers, &block))
end
- def post(path, response_code, data=nil, &block)
- @routes[POST] << Route.new(path, Response.new(response_code,data, &block))
+ def post(path, response_code, data=nil, headers=nil, &block)
+ @routes[POST] << Route.new(path, Response.new(response_code, data, headers, &block))
end
- def delete(path, response_code, data=nil, &block)
- @routes[DELETE] << Route.new(path, Response.new(response_code,data, &block))
+ def delete(path, response_code, data=nil, headers=nil, &block)
+ @routes[DELETE] << Route.new(path, Response.new(response_code, data, headers, &block))
end
def call(env)
@@ -183,14 +183,15 @@ module TinyServer
class Response
HEADERS = {'Content-Type' => 'application/json'}
- def initialize(response_code=200,data=nil, &block)
+ def initialize(response_code=200, data=nil, headers=nil, &block)
@response_code, @data = response_code, data
+ @response_headers = headers ? HEADERS.merge(headers) : HEADERS
@block = block_given? ? block : nil
end
def call
data = @data || @block.call
- [@response_code, HEADERS, Array(data)]
+ [@response_code, @response_headers, Array(data)]
end
def to_s
diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb
index b626a73882..064c97fc27 100644
--- a/spec/unit/resource/remote_file_spec.rb
+++ b/spec/unit/resource/remote_file_spec.rb
@@ -42,7 +42,7 @@ describe Chef::Resource::RemoteFile do
describe "source" do
it "does not have a default value for 'source'" do
- @resource.source.should be_nil
+ @resource.source.should eql([])
end
it "should accept a URI for the remote file source" do