mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
refactored Fog::Compute::RackspaceV2 metadata to take collection as a parameter rather than using it as part of the method name.
This commit is contained in:
parent
68254a3f1d
commit
fc1c77ca7e
8 changed files with 68 additions and 58 deletions
|
@ -53,12 +53,12 @@ module Fog
|
|||
request :list_attachments
|
||||
request :delete_attachment
|
||||
|
||||
request :list_server_metadata
|
||||
request :set_server_metadata
|
||||
request :update_server_metadata
|
||||
request :get_server_metadata_item
|
||||
request :set_server_metadata_item
|
||||
request :delete_server_metadata_item
|
||||
request :list_metadata
|
||||
request :set_metadata
|
||||
request :update_metadata
|
||||
request :get_metadata_item
|
||||
request :set_metadata_item
|
||||
request :delete_metadata_item
|
||||
|
||||
class Mock
|
||||
|
||||
|
|
|
@ -2,17 +2,17 @@ module Fog
|
|||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def delete_server_metadata_item(server_id, key)
|
||||
def delete_metadata_item(collection, server_id, key)
|
||||
request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "/servers/#{server_id}/metadata/#{key}"
|
||||
:path => "/#{collection}/#{server_id}/metadata/#{key}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_server_metadata_item(server_id, key)
|
||||
def delete_metadata_item(collection, server_id, key)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
|
@ -2,17 +2,17 @@ module Fog
|
|||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def get_server_metadata_item(server_id, key)
|
||||
def get_metadata_item(collection, server_id, key)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/servers/#{server_id}/metadata/#{key}"
|
||||
:path => "/#{collection}/#{server_id}/metadata/#{key}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_server_metadata_item(server_id, key)
|
||||
def get_metadata_item(collection, server_id, key)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
|
@ -2,17 +2,17 @@ module Fog
|
|||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def list_server_metadata(server_id)
|
||||
def list_metadata(collection, server_id)
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => "/servers/#{server_id}/metadata"
|
||||
:path => "/#{collection}/#{server_id}/metadata"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_server_metadata(server_id)
|
||||
def list_metadata(collection, server_id)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
|
@ -2,11 +2,11 @@ module Fog
|
|||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def set_server_metadata(server_id, metadata = {})
|
||||
def set_metadata(collection, server_id, metadata = {})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'PUT',
|
||||
:path => "/servers/#{server_id}/metadata",
|
||||
:path => "/#{collection}/#{server_id}/metadata",
|
||||
:body => Fog::JSON.encode('metadata' => metadata)
|
||||
)
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ module Fog
|
|||
|
||||
|
||||
class Mock
|
||||
def set_server_metadata(server_id, metadata = {})
|
||||
def set_metadata(collection, server_id, metadata = {})
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
|
@ -2,18 +2,18 @@ module Fog
|
|||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def set_server_metadata_item(server_id, key, value)
|
||||
def set_metadata_item(collection, server_id, key, value)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "/servers/#{server_id}/metadata/#{key}",
|
||||
:path => "/#{collection}/#{server_id}/metadata/#{key}",
|
||||
:body => Fog::JSON.encode('meta' => { key => value })
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def set_server_metadata_item(server_id, key, value)
|
||||
def set_metadata_item(collection, server_id, key, value)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
|
@ -2,18 +2,18 @@ module Fog
|
|||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def update_server_metadata(server_id, metadata = {})
|
||||
def update_metadata(collection, server_id, metadata = {})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'POST',
|
||||
:path => "/servers/#{server_id}/metadata",
|
||||
:path => "/#{collection}/#{server_id}/metadata",
|
||||
:body => Fog::JSON.encode('metadata' => metadata)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_server_metadata(server_id, metadata = {})
|
||||
def update_metadata(collection, server_id, metadata = {})
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
|
@ -13,23 +13,29 @@ Shindo.tests('Fog::Compute::RackspaceV2 | metadata_tests', ['rackspace']) do
|
|||
:metadata => {"Tag" => "Database"})
|
||||
@server.wait_for(timeout = 1200) { ready? }
|
||||
end
|
||||
tests('list_server_metadata').returns("metadata" => metadata) do
|
||||
@service.list_server_metadata(@server.id).body
|
||||
end
|
||||
tests('set_server_metadata').returns("metadata" => {"environment" => "dev"}) do
|
||||
@service.set_server_metadata(@server.id, {"environment" => "dev"}).body
|
||||
end
|
||||
tests('update_server_metadata').returns("metadata" => {"environment" => "dev", "Tag" => "Database"}) do
|
||||
@service.update_server_metadata(@server.id, {"environment" => "dev", "Tag" => "Database"}).body
|
||||
end
|
||||
tests('get_server_metadata_item').returns("meta" => {"environment" => "dev"}) do
|
||||
@service.get_server_metadata_item(@server.id, "environment").body
|
||||
end
|
||||
tests('set_server_metadata_item').returns("meta" => {"environment", "test"}) do
|
||||
@service.set_server_metadata_item(@server.id, "environment", "test").body
|
||||
end
|
||||
tests('delete_server_metadata_item').succeeds do
|
||||
@service.delete_server_metadata_item(@server.id, "environment").body
|
||||
[['server', @server.id]].each do |params|
|
||||
collection = params[0]
|
||||
id = params[1]
|
||||
tests(collection) do
|
||||
tests('list_metadata').returns("metadata" => metadata) do
|
||||
@service.list_metadata(collection, id).body
|
||||
end
|
||||
tests('set_metadata').returns("metadata" => {"environment" => "dev"}) do
|
||||
@service.set_metadata(collection, id, {"environment" => "dev"}).body
|
||||
end
|
||||
tests('update_metadata').returns("metadata" => {"environment" => "dev", "Tag" => "Database"}) do
|
||||
@service.update_metadata(collection, id, {"environment" => "dev", "Tag" => "Database"}).body
|
||||
end
|
||||
tests('get_metadata_item').returns("meta" => {"environment" => "dev"}) do
|
||||
@service.get_metadata_item(collection, id, "environment").body
|
||||
end
|
||||
tests('set_metadata_item').returns("meta" => {"environment", "test"}) do
|
||||
@service.set_metadata_item(collection, id, "environment", "test").body
|
||||
end
|
||||
tests('delete_metadata_item').succeeds do
|
||||
@service.delete_metadata_item(collection, id, "environment").body
|
||||
end
|
||||
end
|
||||
end
|
||||
ensure
|
||||
@server.destroy if @server
|
||||
|
@ -37,23 +43,27 @@ Shindo.tests('Fog::Compute::RackspaceV2 | metadata_tests', ['rackspace']) do
|
|||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('list_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
@service.list_server_metadata(0)
|
||||
end
|
||||
tests('set_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
@service.set_server_metadata(0, {"environment" => "dev"})
|
||||
end
|
||||
tests('update_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
@service.update_server_metadata(0, {"environment" => "dev", "Tag" => "Database"})
|
||||
end
|
||||
tests('get_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
@service.get_server_metadata_item(0, "environment")
|
||||
end
|
||||
tests('set_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
@service.set_server_metadata_item(0, "environment", "test")
|
||||
end
|
||||
tests('delete_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
@service.delete_server_metadata_item(0, "environment")
|
||||
['server'].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
|
||||
@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
|
||||
|
|
Loading…
Reference in a new issue