From 13b61992f61792f02b218deb1804867c5b25554e Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Mon, 5 Mar 2012 22:31:18 +0100 Subject: [PATCH] Support for rds parameter groups mocking --- lib/fog/aws/rds.rb | 13 ++++++++++-- .../requests/rds/create_db_parameter_group.rb | 20 ++++++++++++++++++- .../requests/rds/delete_db_parameter_group.rb | 12 ++++++++++- .../rds/describe_db_parameter_groups.rb | 20 ++++++++++++++++++- .../requests/rds/describe_db_parameters.rb | 1 - .../aws/requests/rds/parameter_group_tests.rb | 8 +------- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 29024c0e8..59206b556 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -66,8 +66,17 @@ module Fog region_hash[key] = { :servers => {}, :security_groups => {}, - :snapshots => {} - } + :snapshots => {}, + :parameter_groups => {"default.mysql5.1" => { "DBParameterGroupFamily"=>"mysql5.1", + "Description"=>"Default parameter group for mysql5.1", + "DBParameterGroupName"=>"default.mysql5.1" + }, + "default.mysql5.5" => {"DBParameterGroupFamily"=>"mysql5.5", + "Description"=>"Default parameter group for mysql5.5", + "DBParameterGroupName"=>"default.mysql5.5" + } + } + } end end end diff --git a/lib/fog/aws/requests/rds/create_db_parameter_group.rb b/lib/fog/aws/requests/rds/create_db_parameter_group.rb index 9fdcf680f..a11a34955 100644 --- a/lib/fog/aws/requests/rds/create_db_parameter_group.rb +++ b/lib/fog/aws/requests/rds/create_db_parameter_group.rb @@ -32,7 +32,25 @@ module Fog class Mock def create_db_parameter_group(group_name, group_family, description) - Fog::Mock.not_implemented + response = Excon::Response.new + if self.data[:parameter_groups] and self.data[:parameter_groups][group_name] + raise Fog::AWS::RDS::IdentifierTaken.new("Parameter group #{group_name} already exists") + end + + data = { + 'DBParameterGroupName' => group_name, + 'DBParameterGroupFamily' => group_family.downcase, + 'Description' => description + } + self.data[:parameter_groups][group_name] = data + + response.body = { + "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, + "CreateDBParameterGroupResult"=> {"DBParameterGroup"=> data} + } + response.status = 200 + response + end end diff --git a/lib/fog/aws/requests/rds/delete_db_parameter_group.rb b/lib/fog/aws/requests/rds/delete_db_parameter_group.rb index d7f294b3e..02a3b88ca 100644 --- a/lib/fog/aws/requests/rds/delete_db_parameter_group.rb +++ b/lib/fog/aws/requests/rds/delete_db_parameter_group.rb @@ -27,7 +27,17 @@ module Fog class Mock def delete_db_parameter_group(group_name) - Fog::Mock.not_implemented + response = Excon::Response.new + + if self.data[:parameter_groups].delete(group_name) + response.status = 200 + response.body = { + "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, + } + response + else + raise Fog::AWS::RDS::NotFound.new("DBParameterGroup not found: #{group_name}") + end end end diff --git a/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb b/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb index 26244a255..d9a033663 100644 --- a/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb +++ b/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb @@ -36,7 +36,25 @@ module Fog class Mock def describe_db_parameter_groups(name=nil, opts={}) - Fog::Mock.not_implemented + response = Excon::Response.new + parameter_set = [] + if name + if server = self.data[:parameter_groups][name] + parameter_set << server + else + raise Fog::AWS::RDS::NotFound.new("DBInstance #{name} not found") + end + else + parameter_set = self.data[:parameter_groups].values + end + + + response.status = 200 + response.body = { + "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id }, + "DescribeDBParameterGroupsResult" => { "DBParameterGroups" => parameter_set } + } + response end end diff --git a/lib/fog/aws/requests/rds/describe_db_parameters.rb b/lib/fog/aws/requests/rds/describe_db_parameters.rb index d76036b01..8a93a5d6d 100644 --- a/lib/fog/aws/requests/rds/describe_db_parameters.rb +++ b/lib/fog/aws/requests/rds/describe_db_parameters.rb @@ -39,7 +39,6 @@ module Fog def describe_db_parameters(name, opts={}) Fog::Mock.not_implemented end - end end end diff --git a/tests/aws/requests/rds/parameter_group_tests.rb b/tests/aws/requests/rds/parameter_group_tests.rb index 9654a3803..0db18030b 100644 --- a/tests/aws/requests/rds/parameter_group_tests.rb +++ b/tests/aws/requests/rds/parameter_group_tests.rb @@ -1,9 +1,7 @@ Shindo.tests('AWS::RDS | parameter group requests', ['aws', 'rds']) do tests('success') do - pending if Fog.mocking? tests("#create_db_parameter_groups").formats(AWS::RDS::Formats::CREATE_DB_PARAMETER_GROUP) do - pending if Fog.mocking? body = Fog::AWS[:rds].create_db_parameter_group('fog-group', 'MySQL5.1', 'Some description').body returns( 'mysql5.1') { body['CreateDBParameterGroupResult']['DBParameterGroup']['DBParameterGroupFamily']} @@ -16,16 +14,14 @@ Shindo.tests('AWS::RDS | parameter group requests', ['aws', 'rds']) do Fog::AWS[:rds].create_db_parameter_group('other-fog-group', 'MySQL5.1', 'Some description') tests("#describe_db_parameter_groups").formats(AWS::RDS::Formats::DESCRIBE_DB_PARAMETER_GROUP) do - pending if Fog.mocking? body = Fog::AWS[:rds].describe_db_parameter_groups().body - returns(3) {body['DescribeDBParameterGroupsResult']['DBParameterGroups'].length} + returns(4) {body['DescribeDBParameterGroupsResult']['DBParameterGroups'].length} body end tests("#describe_db_parameter_groups('fog-group)").formats(AWS::RDS::Formats::DESCRIBE_DB_PARAMETER_GROUP) do - pending if Fog.mocking? body = Fog::AWS[:rds].describe_db_parameter_groups('fog-group').body @@ -40,7 +36,6 @@ Shindo.tests('AWS::RDS | parameter group requests', ['aws', 'rds']) do end tests("delete_db_parameter_group").formats(AWS::RDS::Formats::BASIC) do - pending if Fog.mocking? body = Fog::AWS[:rds].delete_db_parameter_group('fog-group').body raises(Fog::AWS::RDS::NotFound) {Fog::AWS[:rds].describe_db_parameter_groups('fog-group')} @@ -52,7 +47,6 @@ Shindo.tests('AWS::RDS | parameter group requests', ['aws', 'rds']) do end tests("failures") do - pending if Fog.mocking? raises(Fog::AWS::RDS::NotFound) {Fog::AWS[:rds].describe_db_parameter_groups('doesntexist')} raises(Fog::AWS::RDS::NotFound) {Fog::AWS[:rds].delete_db_parameter_group('doesntexist')}