From 077ddc41edc216cf4527af84c72699fcb5c5004f Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Wed, 30 Nov 2011 17:19:05 +0100 Subject: [PATCH] mocking delete_db_instance --- .../aws/requests/rds/delete_db_instance.rb | 22 ++++++++++++++++--- .../aws/requests/rds/describe_db_instances.rb | 12 ++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/fog/aws/requests/rds/delete_db_instance.rb b/lib/fog/aws/requests/rds/delete_db_instance.rb index 0c5979b21..170181f72 100644 --- a/lib/fog/aws/requests/rds/delete_db_instance.rb +++ b/lib/fog/aws/requests/rds/delete_db_instance.rb @@ -15,7 +15,7 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: - def delete_db_instance(identifier, snapshot_identifier, skip_snapshot = false) + def delete_db_instance(identifier, snapshot_identifier, skip_snapshot = false) params = {} params['FinalDBSnapshotIdentifier'] = snapshot_identifier if snapshot_identifier request({ @@ -30,8 +30,24 @@ module Fog class Mock - def delete_db_snapshot(identifier, snapshot_identifier, skip_snapshot = false) - Fog::Mock.not_implemented + def delete_db_instance(identifier, snapshot_identifier, skip_snapshot = false) + response = Excon::Response.new + + unless skip_snapshot + # I don't know how to mock snapshot_identifier + Fog::Logger.warning("snapshot_identifier is not mocked [light_black](#{caller.first})[/]") + end + + if server_set = self.data[:servers].delete(identifier) + response.status = 200 + response.body = { + "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, + "DeleteDBInstanceResult" => { "DBInstance" => server_set } + } + response + else + raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found") + end end end diff --git a/lib/fog/aws/requests/rds/describe_db_instances.rb b/lib/fog/aws/requests/rds/describe_db_instances.rb index 49e7cbd93..a84c54535 100644 --- a/lib/fog/aws/requests/rds/describe_db_instances.rb +++ b/lib/fog/aws/requests/rds/describe_db_instances.rb @@ -35,21 +35,13 @@ module Fog def describe_db_instances(identifier=nil, opts={}) response = Excon::Response.new if identifier - if self.data[:servers].has_key?(identifier) - servers_set = self.data[:servers][identifier] + if server_set = self.data[:servers][identifier] response.status = 200 response.body = { "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, - "DescribeDBInstancesResult" => { "DBInstances" => [servers_set] } + "DescribeDBInstancesResult" => { "DBInstances" => [server_set] } } - - else - response.status = 404 - response.body = { - "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, - "DescribeDBInstancesResult" => { "DBInstances" => 'DBInstanceNotFound' } - } raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found") end