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

More fixes to AWS::Elasticache mocking

* Implemented recommendations from @jbence review
 * Enabled tests which revealed a bug in create_cache_security_group response
This commit is contained in:
Brian Nelson 2013-09-08 18:31:33 -07:00
parent d463d313d5
commit 8948156ee0
4 changed files with 34 additions and 30 deletions

View file

@ -25,7 +25,7 @@ module Fog
class Mock
def create_cache_security_group(name, description = name)
response = Excon::Response.new
if self.data[:security_groups][name]
raise Fog::AWS::Elasticache::IdentifierTaken.new("CacheClusterAlreadyExists => The security group '#{name}' already exists")
end
@ -37,11 +37,15 @@ module Fog
'OwnerId' => '0123456789'
}
self.data[:security_groups][name] = data
response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
'CreateCacheSecurityGroupResult' => { 'DBSecurityGroup' => data }
}
response
Excon::Response.new(
{
:body => {
'ResponseMetadata'=>{ 'RequestId'=> Fog::AWS::Mock.request_id },
'CacheSecurityGroup' => data
}
}
)
end
end

View file

@ -23,14 +23,13 @@ module Fog
class Mock
def delete_cache_security_group(name)
response = Excon::Response.new
if self.data[:security_groups].delete(name)
response.status = 200
response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
}
response
Excon::Response.new(
{
:status => 200,
:body => { 'ResponseMetadata'=>{ 'RequestId'=> Fog::AWS::Mock.request_id } }
}
)
else
raise Fog::AWS::RDS::NotFound.new("DBSecurityGroupNotFound => #{name} not found")
end

View file

@ -25,22 +25,18 @@ module Fog
end
class Mock
def describe_cache_security_groups(name, opts={})
response = Excon::Response.new
sec_group_set = []
def describe_cache_security_groups(name = nil, opts={})
sec_group = self.data[:security_groups][name]
if sec_group
sec_group_set << sec_group
if name
sec_group_set = [self.data[:security_groups][name]].compact
raise Fog::AWS::Elasticache::NotFound.new("Security Group #{name} not found") if sec_group_set.empty?
else
raise Fog::AWS::Elasticache::NotFound.new("Security Group #{name} not found")
sec_group_set = self.data[:security_groups].values
end
# TODO: refactor to not delete items that we're iterating over. Causes
# model tests to fail (currently pending)
sec_group_set.each do |sec_group|
# TODO: refactor to not delete items that we're iterating over. Causes
# model tests to fail (currently pending)
sec_group["EC2SecurityGroups"].each do |ec2_secg|
@ -55,12 +51,16 @@ module Fog
end
end
response.status = 200
response.body = {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
"CacheSecurityGroups" => sec_group_set
}
response
Excon::Response.new(
{
:status => 200,
:body => {
"ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
"CacheSecurityGroups" => sec_group_set
}
}
)
end
end
end

View file

@ -1,10 +1,9 @@
Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache']) do
tests('success') do
pending if Fog.mocking?
name = 'fog-test'
description = 'Fog Test Group'
description = 'Fog Test Security Group'
tests(
'#create_cache_security_group'
@ -74,6 +73,8 @@ Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache'
tests(
'#revoke_cache_security_group_ingress'
).formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
pending if Fog.mocking?
body = AWS[:elasticache].revoke_cache_security_group_ingress(
name, ec2_group.name, ec2_group.owner_id
).body