1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/rackspace/requests/compute_v2/metadata_tests.rb

105 lines
4.6 KiB
Ruby
Raw Normal View History

Shindo.tests('Fog::Compute::RackspaceV2 | metadata_tests', ['rackspace']) do
@service = Fog::Compute.new(:provider => 'Rackspace', :version => 'V2')
tests('success') do
begin
2013-01-03 15:51:36 -05:00
metadata = {"tag" => "database"}
unless Fog.mocking?
2013-01-03 15:51:36 -05:00
name = "fog-server-metadata-#{Time.now.to_i}"
@server = @service.servers.create(:name => name,
:flavor_id => 2,
:image_id => '3afe97b2-26dc-49c5-a2cc-a2fc8d80c001',
2013-01-03 15:51:36 -05:00
:metadata => metadata)
@server.wait_for { ready? }
2013-01-03 15:51:36 -05:00
@server_id = @server.id
@image = @server.create_image(name, :metadata => metadata)
@image_id = @image.id
2013-01-03 15:51:36 -05:00
else
@image_id = 1
@server_id = 1
end
2013-01-03 15:51:36 -05:00
tests("servers") do
tests('list_metadata').returns("metadata" => metadata) do
2013-01-03 15:51:36 -05:00
@service.list_metadata("servers", @server_id).body
end
tests('set_metadata').returns("metadata" => {"environment" => "dev"}) do
2013-01-03 15:51:36 -05:00
@service.set_metadata("servers", @server_id, {"environment" => "dev"}).body
end
2013-01-03 15:51:36 -05:00
tests('update_metadata').returns("metadata" => {"environment" => "dev", "tag" => "database"}) do
@service.update_metadata("servers", @server_id, {"environment" => "dev", "tag" => "database"}).body
end
tests('get_metadata_item').returns("meta" => {"environment" => "dev"}) do
2013-01-03 15:51:36 -05:00
@service.get_metadata_item("servers", @server_id, "environment").body
end
2013-01-08 11:32:24 -05:00
tests('set_metadata_item').returns("meta" => {"environment" => "test"}) do
2013-01-03 15:51:36 -05:00
@service.set_metadata_item("servers", @server_id, "environment", "test").body
end
tests('delete_metadata_item').succeeds do
@service.delete_metadata_item("servers", @server_id, "environment")
2013-01-03 15:51:36 -05:00
end
end
tests("images") do
@image.wait_for { ready? } unless Fog.mocking?
2013-01-07 12:42:37 -05:00
2013-01-03 15:51:36 -05:00
tests('list_metadata').returns(metadata) do
h = @service.list_metadata("images", @image_id).body
h["metadata"].reject {|k,v| k.downcase != "tag"} #only look at the metadata we created
end
tests('set_metadata').returns({"environment" => "dev"}) do
h = @service.set_metadata("images", @image_id, {"environment" => "dev"}).body
h["metadata"].reject {|k,v| k.downcase != "environment"} #only look at the metadata we created
end
2013-01-07 12:42:37 -05:00
tests('update_metadata').returns({"environment" => "dev", "tag" => "database"}) do
h = @service.update_metadata("images", @image_id, {"environment" => "dev", "tag" => "database"}).body
2013-01-03 15:51:36 -05:00
h["metadata"].reject {|k,v| !['environment', 'tag'].include?(k.downcase)} #only look at the metadata we created
end
tests('get_metadata_item').returns("meta" => {"environment" => "dev"}) do
@service.get_metadata_item("images", @image_id, "environment").body
end
2013-01-08 11:32:24 -05:00
tests('set_metadata_item').returns("meta" => {"environment" => "test"}) do
2013-01-03 15:51:36 -05:00
@service.set_metadata_item("images", @image_id, "environment", "test").body
end
tests('delete_metadata_item').succeeds do
@service.delete_metadata_item("images", @image_id, "environment")
end
end
ensure
2013-01-03 15:51:36 -05:00
@image.destroy if @image
@server.destroy if @server
end
end
tests('failure') do
2013-01-03 15:51:36 -05:00
['server', 'image'].each do |collection|
tests(collection) do
tests('list_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do
@service.list_metadata(collection, 0)
end
tests('set_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do
@service.set_metadata(collection, 0, {"environment" => "dev"})
end
tests('update_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do
2013-01-03 15:51:36 -05:00
@service.update_metadata(collection, 0, {"environment" => "dev", "tag" => "database"})
end
tests('get_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do
@service.get_metadata_item(collection, 0, "environment")
end
tests('set_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do
@service.set_metadata_item(collection, 0, "environment", "test")
end
tests('delete_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do
@service.delete_metadata_item(collection, 0, "environment")
end
end
end
end
end