mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|storage] Added OpenStack Storage service tests
Mostly copy&paste from the Rackspace Storage service
This commit is contained in:
parent
e82ad3c07d
commit
74ce4467eb
4 changed files with 373 additions and 0 deletions
178
tests/openstack/models/storage/file_tests.rb
Normal file
178
tests/openstack/models/storage/file_tests.rb
Normal file
|
@ -0,0 +1,178 @@
|
|||
Shindo.tests('Fog::OpenStack::Storage | file', ['openstack']) do
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
def object_meta_attributes
|
||||
@instance.service.head_object(@directory.key, @instance.key).headers.reject {|k, v| !(k =~ /X-Object-Meta-/)}
|
||||
end
|
||||
|
||||
def clear_metadata
|
||||
@instance.metadata.tap do |metadata|
|
||||
metadata.each_pair {|k, v| metadata[k] = nil }
|
||||
end
|
||||
end
|
||||
|
||||
file_attributes = {
|
||||
:key => 'fog_file_tests',
|
||||
:body => lorem_file
|
||||
}
|
||||
|
||||
directory_attributes = {
|
||||
# Add a random suffix to prevent collision
|
||||
:key => "fogfilestests-#{rand(65536)}"
|
||||
}
|
||||
|
||||
@directory = Fog::Storage[:openstack].
|
||||
directories.
|
||||
create(directory_attributes)
|
||||
|
||||
model_tests(@directory.files, file_attributes.merge(:etag => 'foo'), Fog.mocking?) do
|
||||
tests('#save should not blow up with etag') do
|
||||
@instance.save
|
||||
end
|
||||
end
|
||||
|
||||
model_tests(@directory.files, file_attributes, Fog.mocking?) do
|
||||
|
||||
tests("#metadata should load empty metadata").returns({}) do
|
||||
@instance.metadata
|
||||
end
|
||||
|
||||
tests('#save') do
|
||||
|
||||
tests('#metadata') do
|
||||
|
||||
before do
|
||||
@instance.metadata[:foo] = 'bar'
|
||||
@instance.save
|
||||
end
|
||||
|
||||
after do
|
||||
clear_metadata
|
||||
@instance.save
|
||||
end
|
||||
|
||||
tests("should update metadata").returns('bar') do
|
||||
object_meta_attributes['X-Object-Meta-Foo']
|
||||
end
|
||||
|
||||
tests('should cache metadata').returns('bar') do
|
||||
@instance.metadata[:foo]
|
||||
end
|
||||
|
||||
tests('should remove empty metadata').returns({}) do
|
||||
@instance.metadata[:foo] = nil
|
||||
@instance.save
|
||||
object_meta_attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('#metadata keys') do
|
||||
|
||||
after do
|
||||
clear_metadata
|
||||
@instance.save
|
||||
end
|
||||
|
||||
@instance.metadata[:foo_bar] = 'baz'
|
||||
tests("should support compound key names").returns('baz') do
|
||||
@instance.save
|
||||
object_meta_attributes['X-Object-Meta-Foo-Bar']
|
||||
end
|
||||
|
||||
@instance.metadata['foo'] = 'bar'
|
||||
tests("should support string keys").returns('bar') do
|
||||
@instance.save
|
||||
object_meta_attributes['X-Object-Meta-Foo']
|
||||
end
|
||||
|
||||
@instance.metadata['foo_bar'] = 'baz'
|
||||
tests("should support compound string key names").returns('baz') do
|
||||
@instance.save
|
||||
object_meta_attributes['X-Object-Meta-Foo-Bar']
|
||||
end
|
||||
|
||||
@instance.metadata['foo-bar'] = 'baz'
|
||||
tests("should support hyphenated keys").returns('baz') do
|
||||
@instance.save
|
||||
object_meta_attributes['X-Object-Meta-Foo-Bar']
|
||||
end
|
||||
|
||||
@instance.metadata['foo-bar'] = 'baz'
|
||||
@instance.metadata[:'foo_bar'] = 'bref'
|
||||
tests("should only support one value per metadata key").returns('bref') do
|
||||
@instance.save
|
||||
object_meta_attributes['X-Object-Meta-Foo-Bar']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests("#access_control_allow_origin") do
|
||||
|
||||
tests("#access_control_allow_origin should default to nil").returns(nil) do
|
||||
@instance.access_control_allow_origin
|
||||
end
|
||||
|
||||
@instance.access_control_allow_origin = 'http://example.com'
|
||||
@instance.save
|
||||
tests("#access_control_allow_origin should return access control attribute").returns('http://example.com') do
|
||||
@instance.access_control_allow_origin
|
||||
end
|
||||
|
||||
@instance.access_control_allow_origin = 'foo'
|
||||
@instance.save
|
||||
tests("#access_control_allow_origin= should update access_control_allow_origin").returns('bar') do
|
||||
@instance.access_control_allow_origin = 'bar'
|
||||
@instance.save
|
||||
@instance.access_control_allow_origin
|
||||
end
|
||||
|
||||
tests("#access_control_allow_origin= should not blow up on nil") do
|
||||
@instance.access_control_allow_origin = nil
|
||||
@instance.save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
model_tests(@directory.files, file_attributes, Fog.mocking?) do
|
||||
|
||||
tests("#origin") do
|
||||
|
||||
tests("#origin should default to nil").returns(nil) do
|
||||
@instance.save
|
||||
@instance.origin
|
||||
end
|
||||
|
||||
@instance.origin = 'http://example.com'
|
||||
@instance.save
|
||||
tests("#origin should return access control attributes").returns('http://example.com') do
|
||||
@instance.origin
|
||||
end
|
||||
@instance.attributes.delete('Origin')
|
||||
|
||||
@instance.origin = 'foo'
|
||||
@instance.save
|
||||
tests("#origin= should update origin").returns('bar') do
|
||||
@instance.origin = 'bar'
|
||||
@instance.save
|
||||
@instance.origin
|
||||
end
|
||||
|
||||
tests("#origin= should not blow up on nil") do
|
||||
@instance.origin = nil
|
||||
@instance.save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@directory.destroy
|
||||
|
||||
end
|
64
tests/openstack/requests/storage/container_tests.rb
Normal file
64
tests/openstack/requests/storage/container_tests.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
Shindo.tests('Fog::Storage[:openstack] | container requests', ["openstack"]) do
|
||||
|
||||
@container_format = [String]
|
||||
|
||||
@containers_format = [{
|
||||
'bytes' => Integer,
|
||||
'count' => Integer,
|
||||
'name' => String
|
||||
}]
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#put_container('fogcontainertests')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].put_container('fogcontainertests')
|
||||
end
|
||||
|
||||
tests("#get_container('fogcontainertests')").formats(@container_format) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].get_container('fogcontainertests').body
|
||||
end
|
||||
|
||||
tests("#get_containers").formats(@containers_format) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].get_containers.body
|
||||
end
|
||||
|
||||
tests("#head_container('fogcontainertests')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].head_container('fogcontainertests')
|
||||
end
|
||||
|
||||
tests("#head_containers").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].head_containers
|
||||
end
|
||||
|
||||
tests("#delete_container('fogcontainertests')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].delete_container('fogcontainertests')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get_container('fognoncontainer')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].get_container('fognoncontainer')
|
||||
end
|
||||
|
||||
tests("#head_container('fognoncontainer')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].head_container('fognoncontainer')
|
||||
end
|
||||
|
||||
tests("#delete_container('fognoncontainer')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].delete_container('fognoncontainer')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
47
tests/openstack/requests/storage/large_object_tests.rb
Normal file
47
tests/openstack/requests/storage/large_object_tests.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
Shindo.tests('Fog::Storage[:openstack] | large object requests', ["openstack"]) do
|
||||
|
||||
unless Fog.mocking?
|
||||
@directory = Fog::Storage[:openstack].directories.create(:key => 'foglargeobjecttests')
|
||||
end
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#put_object('foglargeobjecttests', 'fog_large_object/1', ('x' * 6 * 1024 * 1024))").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].put_object(@directory.identity, 'fog_large_object/1', ('x' * 6 * 1024 * 1024))
|
||||
end
|
||||
|
||||
tests("#put_object('foglargeobjecttests', 'fog_large_object/2', ('x' * 4 * 1024 * 1024))").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].put_object(@directory.identity, 'fog_large_object/2', ('x' * 4 * 1024 * 1024))
|
||||
end
|
||||
|
||||
tests("#put_object_manifest('foglargeobjecttests', 'fog_large_object')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].put_object_manifest(@directory.identity, 'fog_large_object')
|
||||
end
|
||||
|
||||
tests("#get_object('foglargeobjecttests', 'fog_large_object').body").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].get_object(@directory.identity, 'fog_large_object').body == ('x' * 10 * 1024 * 1024)
|
||||
end
|
||||
|
||||
unless Fog.mocking?
|
||||
['fog_large_object', 'fog_large_object/1', 'fog_large_object/2'].each do |key|
|
||||
@directory.files.new(:key => key).destroy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("put_object_manifest")
|
||||
|
||||
end
|
||||
|
||||
unless Fog.mocking?
|
||||
@directory.destroy
|
||||
end
|
||||
|
||||
end
|
84
tests/openstack/requests/storage/object_tests.rb
Normal file
84
tests/openstack/requests/storage/object_tests.rb
Normal file
|
@ -0,0 +1,84 @@
|
|||
Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
|
||||
|
||||
unless Fog.mocking?
|
||||
@directory = Fog::Storage[:openstack].directories.create(:key => 'fogobjecttests')
|
||||
end
|
||||
|
||||
module OpenStackStorageHelpers
|
||||
def override_path(path)
|
||||
@path = path
|
||||
end
|
||||
end
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#put_object('fogobjecttests', 'fog_object')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', lorem_file)
|
||||
end
|
||||
|
||||
tests("#get_object('fogobjectests', 'fog_object')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object')
|
||||
end
|
||||
|
||||
tests("#get_object('fogobjecttests', 'fog_object', &block)").returns(lorem_file.read) do
|
||||
pending if Fog.mocking?
|
||||
data = ''
|
||||
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object') do |chunk, remaining_bytes, total_bytes|
|
||||
data << chunk
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
tests("#head_object('fogobjectests', 'fog_object')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].head_object('fogobjecttests', 'fog_object')
|
||||
end
|
||||
|
||||
tests("#delete_object('fogobjecttests', 'fog_object')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_object')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get_object('fogobjecttests', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_non_object')
|
||||
end
|
||||
|
||||
tests("#get_object('fognoncontainer', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].get_object('fognoncontainer', 'fog_non_object')
|
||||
end
|
||||
|
||||
tests("#head_object('fogobjecttests', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].head_object('fogobjecttests', 'fog_non_object')
|
||||
end
|
||||
|
||||
tests("#head_object('fognoncontainer', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].head_object('fognoncontainer', 'fog_non_object')
|
||||
end
|
||||
|
||||
tests("#delete_object('fogobjecttests', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_non_object')
|
||||
end
|
||||
|
||||
tests("#delete_object('fognoncontainer', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:openstack].delete_object('fognoncontainer', 'fog_non_object')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
unless Fog.mocking?
|
||||
@directory.destroy
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue