Skip to content

Commit e1e0306

Browse files
author
Timur Alperovich
committed
Enable put_object tests with mocks.
Now that put_object mock is implemented, we can enable some of the tests that rely on it.
1 parent b0f30a9 commit e1e0306

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lib/fog/storage/openstack/requests/put_object.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,25 @@ def put_object(container, object, data, options = {}, &block)
3838
end
3939

4040
class Mock
41-
def put_object(container, object, data, options = {}, &block)
41+
require 'digest'
42+
43+
def put_object(_container, _object, data, _options = {}, &block)
44+
dgst = Digest::MD5.new
45+
if block_given?
46+
Kernel.loop do
47+
chunk = yield
48+
break if chunk.empty?
49+
dgst.update chunk
50+
end
51+
elsif data.kind_of?(String)
52+
dgst.update data
53+
else
54+
dgst.file data
55+
end
4256
response = Excon::Response.new
4357
response.status = 201
44-
response.body = ""
58+
response.body = ''
59+
response.headers = {'ETag' => dgst.hexdigest}
4560
response
4661
end
4762
end

test/requests/storage/object_tests.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ def override_path(path)
3131

3232
describe "success" do
3333
it "#put_object('fogobjecttests', 'fog_object')" do
34-
skip if Fog.mocking?
3534
resp = Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', lorem_file)
3635
resp.headers['ETag'].must_equal '80d7930fe13ff4e45156b6581656a247'
3736
end
3837

3938
describe "with_object" do
4039
before do
41-
skip if Fog.mocking?
4240
file = lorem_file
4341
resp = Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', file)
4442
file.close
@@ -118,7 +116,6 @@ def override_path(path)
118116

119117
describe "put_object with block" do
120118
it "#put_object('fogobjecttests', 'fog_object', &block)" do
121-
skip if Fog.mocking?
122119
begin
123120
file = lorem_file
124121
buffer_size = file.stat.size / 2 # chop it up into two buffers
@@ -133,13 +130,11 @@ def override_path(path)
133130

134131
describe "with_object" do
135132
before do
136-
unless Fog.mocking?
137-
file = lorem_file
138-
Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_block_object', nil) do
139-
file.read(file.stat.size).to_s
140-
end
141-
file.close
133+
file = lorem_file
134+
Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_block_object', nil) do
135+
file.read(file.stat.size).to_s
142136
end
137+
file.close
143138
end
144139

145140
it "#get_object" do

0 commit comments

Comments
 (0)