Skip to content

Commit

Permalink
add CHEF::Rest#get func tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lamont-granquist committed Apr 22, 2014
1 parent 23c5d8d commit 662507a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions spec/functional/http/simple_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
end
end

# see CHEF-5100
shared_examples_for "a 403 after a successful request when reusing the request object" do
it "fails with a Net::HTTPServerException for a streaming request" do
tempfile = http_client.streaming_request(source)
Expand Down
26 changes: 24 additions & 2 deletions spec/functional/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,49 @@
tempfile.close
expect(Digest::MD5.hexdigest(binread(tempfile.path))).to eq(Digest::MD5.hexdigest(expected_content))
end

it "successfully downloads a GET request" do
tempfile = http_client.get(source, {})
tempfile.close
expect(Digest::MD5.hexdigest(binread(tempfile.path))).to eq(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

it "fails validation on a GET request" do
expect { http_client.get(source, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
end
end

shared_examples_for "an endpoint that 403s" do
it "fails with a Net::HTTPServerException" do
it "fails with a Net::HTTPServerException on a streaming download" do
expect { http_client.streaming_request(source, {}) }.to raise_error(Net::HTTPServerException)
end

it "fails with a Net::HTTPServerException on a GET request" do
expect { http_client.get(source, {}) }.to raise_error(Net::HTTPServerException)
end
end

# see CHEF-5100
shared_examples_for "a 403 after a successful request when reusing the request object" do
it "fails with a Net::HTTPServerException" do
it "fails with a Net::HTTPServerException on a streaming download" do
tempfile = http_client.streaming_request(source, {})
tempfile.close
expect(Digest::MD5.hexdigest(binread(tempfile.path))).to eq(Digest::MD5.hexdigest(expected_content))
expect { http_client.streaming_request(source2, {}) }.to raise_error(Net::HTTPServerException)
end

it "fails with a Net::HTTPServerException on a GET request" do
tempfile = http_client.get(source, {})
tempfile.close
expect(Digest::MD5.hexdigest(binread(tempfile.path))).to eq(Digest::MD5.hexdigest(expected_content))
expect { http_client.get(source2, {}) }.to raise_error(Net::HTTPServerException)
end
end

before do
Expand Down

0 comments on commit 662507a

Please sign in to comment.