diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-04-11 15:36:42 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-04-11 15:38:57 -0700 |
commit | c96317f806cccc1db975eac2e94842cd1cba2ca2 (patch) | |
tree | 410d768293f207f2925ab6720dae72dce7696c12 /spec/functional/rest_spec.rb | |
parent | dad83ca8eca2c8679ac381a0bbf2a08d5ebe2fbf (diff) | |
download | chef-c96317f806cccc1db975eac2e94842cd1cba2ca2.tar.gz |
CHEF-5198: adding func tests for Chef::HTTP clients
Start of func tests for Chef::REST and Chef::HTTP::Simple
- Chef::REST is missing func tests against JSON endpoints using simple
GET requests
- HEAD and POST requests are also still missing, etc.
Diffstat (limited to 'spec/functional/rest_spec.rb')
-rw-r--r-- | spec/functional/rest_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/functional/rest_spec.rb b/spec/functional/rest_spec.rb new file mode 100644 index 0000000000..0e0b3ee9f1 --- /dev/null +++ b/spec/functional/rest_spec.rb @@ -0,0 +1,55 @@ +# +# Author:: Lamont Granquist (<lamont@getchef.com>) +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' +require 'tiny_server' +require 'support/shared/functional/http' + +describe Chef::REST do + let(:http_client) { described_class.new(source) } + let(:http_client_disable_gzip) { described_class.new(source, Chef::Config[:node_name], Chef::Config[:client_key], { :disable_gzip => true } ) } + + shared_examples_for "downloads requests correctly" do + it "successfully downloads a streaming request" do + tempfile = http_client.streaming_request(source, {}) + tempfile.close + Digest::MD5.hexdigest(binread(tempfile.path)).should == Digest::MD5.hexdigest(expected_content) + end + end + + shared_examples_for "validates content length and throws an exception" do + it "fails validation on a streaming download" do + expect { http_client.streaming_request(source, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch) + end + end + + before do + Chef::Config[:node_name] = "webmonkey.example.com" + Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem" + end + + before(:all) do + start_tiny_server + end + + after(:all) do + stop_tiny_server + end + + it_behaves_like "downloading all the things" +end |