1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[rackspace|blockstorage] Add volume tests.

This commit is contained in:
Brad Gignac 2012-09-04 20:18:49 -04:00
parent a1513800cb
commit c149d80988
4 changed files with 103 additions and 0 deletions

View file

@ -23,6 +23,10 @@ module Fog
attribute :volume_type
attribute :availability_zone
def ready?
state == AVAILABLE
end
def save
requires :size
data = connection.create_volume(size, {

View file

@ -0,0 +1,27 @@
Shindo.tests('Fog::Rackspace::BlockStorage | volume', ['rackspace']) do
pending if Fog.mocking?
service = Fog::Rackspace::BlockStorage.new
options = { :display_name => "fog_#{Time.now.to_i.to_s}", :size => 100 }
model_tests(service.volumes, options, false) do
@instance.wait_for { ready? }
tests('#attached?').succeeds do
@instance.state = 'in-use'
returns(true) { @instance.attached? }
end
tests('#snapshots').succeeds do
snapshot = service.snapshots.create({ :volume_id => @instance.id })
snapshot.wait_for { ready? }
returns(true) { @instance.snapshots.first.id == snapshot.id }
snapshot.destroy
end
@instance.wait_for { snapshots.empty? }
end
end

View file

@ -0,0 +1,11 @@
Shindo.tests('Fog::Rackspace::BlockStorage | volumes', ['rackspace']) do
pending if Fog.mocking?
service = Fog::Rackspace::BlockStorage.new
options = { :display_name => "fog_#{Time.now.to_i.to_s}", :size => 100 }
collection_tests(service.volumes, options, false) do
@instance.wait_for { ready? }
end
end

View file

@ -0,0 +1,61 @@
Shindo.tests('Fog::Rackspace::BlockStorage | volume_tests', ['rackspace']) do
pending if Fog.mocking?
VOLUME_FORMAT = {
'id' => String,
'status' => String,
'display_name' => Fog::Nullable::String,
'display_description' => Fog::Nullable::String,
'size' => Integer,
'created_at' => String,
'volume_type' => String,
'availability_zone' => String,
'snapshot_id' => Fog::Nullable::String,
'attachments' => Array,
'metadata' => Hash
}
GET_VOLUME_FORMAT = {
'volume' => VOLUME_FORMAT
}
LIST_VOLUME_FORMAT = {
'volumes' => [VOLUME_FORMAT]
}
service = Fog::Rackspace::BlockStorage.new
tests('success') do
id = nil
size = 10
tests("#create_volume(#{size})").formats(GET_VOLUME_FORMAT) do
data = service.create_volume(size).body
id = data['volume']['id']
data
end
tests("#list_volumes").formats(LIST_VOLUME_FORMAT) do
service.list_volumes.body
end
tests("#get_volume(#{id})").formats(GET_VOLUME_FORMAT) do
service.get_volume(id).body
end
tests("#delete_volume(#{id})").succeeds do
service.delete_volume(id)
end
end
tests('failure') do
tests("#create_volume(-1)").raises(Fog::Rackspace::BlockStorage::BadRequest) do
service.create_volume(-1)
end
tests("#get_volume(-1)").raises(Fog::Rackspace::BlockStorage::NotFound) do
service.get_volume(-1)
end
end
end