mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
dxsdk-335 add tests and a post_container request
This commit is contained in:
parent
fdbf6f5994
commit
f3eeaedf2a
5 changed files with 66 additions and 9 deletions
38
lib/fog/hp/requests/storage/post_container.rb
Normal file
38
lib/fog/hp/requests/storage/post_container.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class HP
|
||||
class Real
|
||||
|
||||
# Update or create a container
|
||||
#
|
||||
# ==== Parameters
|
||||
# * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
|
||||
#
|
||||
def post_container(container, headers = {})
|
||||
response = request(
|
||||
:expects => 204,
|
||||
:headers => headers,
|
||||
:method => 'POST',
|
||||
:path => "#{Fog::HP.escape(container)}"
|
||||
)
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
|
||||
def post_container(container_name, object_name, headers = {})
|
||||
if self.data[:containers][container_name].nil?
|
||||
raise Fog::Storage::HP::NotFound
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,16 +24,11 @@ module Fog
|
|||
|
||||
def post_object(container_name, object_name, headers = {})
|
||||
response = Excon::Response.new
|
||||
### Take care of case of copy operation
|
||||
source = headers['X-Copy-From']
|
||||
# split source container and object
|
||||
_, source_container_name, source_object_name = source.split('/')
|
||||
# dup object into target object
|
||||
source_container = self.data[:containers][source_container_name]
|
||||
source_container = self.data[:containers][container_name]
|
||||
container = self.data[:containers][container_name]
|
||||
if (source_container && container)
|
||||
response.status = 202
|
||||
source_object = source_container[:objects][source_object_name]
|
||||
source_object = source_container[:objects][object_name]
|
||||
target_object = source_object.dup
|
||||
target_object.merge!({
|
||||
'Key' => object_name,
|
||||
|
|
|
@ -41,6 +41,8 @@ module Fog
|
|||
request :head_object
|
||||
request :head_shared_container
|
||||
request :head_shared_object
|
||||
request :post_container
|
||||
request :post_object
|
||||
request :put_container
|
||||
request :put_object
|
||||
request :put_shared_object
|
||||
|
|
|
@ -14,6 +14,10 @@ Shindo.tests("Fog::Storage[:hp] | container requests", ['hp']) do
|
|||
Fog::Storage[:hp].put_container('fogcontainertests')
|
||||
end
|
||||
|
||||
tests("#post_container('fogcontainertests', {'X-Container-Sync-Key' => 'keyd'})").succeeds do
|
||||
Fog::Storage[:hp].post_container('fogcontainertests', {'X-Container-Meta-Foo' => 'd'})
|
||||
end
|
||||
|
||||
tests("#get_container('fogcontainertests')").formats(@container_format) do
|
||||
Fog::Storage[:hp].get_container('fogcontainertests').body
|
||||
end
|
||||
|
@ -57,6 +61,10 @@ Shindo.tests("Fog::Storage[:hp] | container requests", ['hp']) do
|
|||
Fog::Storage[:hp].get_container('fognoncontainer')
|
||||
end
|
||||
|
||||
tests("#post_container('fognoncontainer', {})").raises(Fog::Storage::HP::NotFound) do
|
||||
Fog::Storage[:hp].post_container('fognoncontainer', {})
|
||||
end
|
||||
|
||||
tests("#head_container('fognoncontainer')").raises(Fog::Storage::HP::NotFound) do
|
||||
Fog::Storage[:hp].head_container('fognoncontainer')
|
||||
end
|
||||
|
@ -75,4 +83,4 @@ Shindo.tests("Fog::Storage[:hp] | container requests", ['hp']) do
|
|||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,10 @@ Shindo.tests("Fog::Storage[:hp] | object requests", ['hp', 'storage']) do
|
|||
Fog::Storage[:hp].put_object(@dir_name, 'fog_object', lorem_file)
|
||||
end
|
||||
|
||||
tests("#post_object('#{@dir_name}', 'fog_object', {})").succeeds do
|
||||
Fog::Storage[:hp].post_object(@dir_name, 'fog_object', {})
|
||||
end
|
||||
|
||||
tests("#get_object('#{@dir_name}', 'fog_object')").succeeds do
|
||||
Fog::Storage[:hp].get_object(@dir_name, 'fog_object')
|
||||
end
|
||||
|
@ -43,8 +47,14 @@ Shindo.tests("Fog::Storage[:hp] | object requests", ['hp', 'storage']) do
|
|||
@another_dir.files.get('fog_another_object').destroy
|
||||
@another_dir.destroy
|
||||
|
||||
tests("#post_object('#{@dir_name}', 'fog_delete_object', {'X-Delete-After' => 40})" ).succeeds do
|
||||
Fog::Storage[:hp].put_object(@dir_name, 'fog_delete_object', lorem_file)
|
||||
Fog::Storage[:hp].post_object(@dir_name, 'fog_delete_object', {'X-Delete-After' => 40})
|
||||
end
|
||||
|
||||
tests("#delete_object('#{@dir_name}', 'fog_object')").succeeds do
|
||||
Fog::Storage[:hp].delete_object(@dir_name, 'fog_object')
|
||||
Fog::Storage[:hp].delete_object(@dir_name, 'fog_delete_object')
|
||||
end
|
||||
|
||||
tests("#get_object_http_url('#{@directory.identity}', 'fog_object', expiration timestamp)").returns(true) do
|
||||
|
@ -72,6 +82,10 @@ Shindo.tests("Fog::Storage[:hp] | object requests", ['hp', 'storage']) do
|
|||
Fog::Storage[:hp].put_object('fognoncontainer', 'fog_object', lorem_file)
|
||||
end
|
||||
|
||||
tests("#post_object('fognoncontainer', 'fog_object')").raises(Fog::Storage::HP::NotFound) do
|
||||
Fog::Storage[:hp].post_object('fognoncontainer', 'fog_object')
|
||||
end
|
||||
|
||||
tests("#get_object('#{@dir_name}', 'fog_non_object')").raises(Fog::Storage::HP::NotFound) do
|
||||
Fog::Storage[:hp].get_object(@dir_name, 'fog_non_object')
|
||||
end
|
||||
|
@ -104,4 +118,4 @@ Shindo.tests("Fog::Storage[:hp] | object requests", ['hp', 'storage']) do
|
|||
|
||||
@directory.destroy
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue