mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
fix some mocking behavior
This commit is contained in:
parent
fba07bb064
commit
824c271ae4
3 changed files with 15 additions and 7 deletions
|
@ -29,6 +29,8 @@ module Fog
|
||||||
request :modify_mount_target_security_groups
|
request :modify_mount_target_security_groups
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
||||||
|
|
||||||
def self.data
|
def self.data
|
||||||
@data ||= Hash.new do |hash, region|
|
@data ||= Hash.new do |hash, region|
|
||||||
hash[region] = Hash.new do |region_hash, key|
|
hash[region] = Hash.new do |region_hash, key|
|
||||||
|
@ -56,7 +58,13 @@ module Fog
|
||||||
attr_accessor :region
|
attr_accessor :region
|
||||||
|
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
@region = options[:region] || "us-east-1"
|
@region = options[:region] || "us-east-1"
|
||||||
|
@aws_access_key_id = options[:aws_access_key_id]
|
||||||
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
||||||
|
end
|
||||||
|
|
||||||
|
def mock_compute
|
||||||
|
@mock_compute ||= Fog::Compute::AWS.new(:aws_access_key_id => @aws_access_key_id, :aws_secret_access_key => @aws_secret_access_key, :region => @region)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def create_mount_target(file_system_id, subnet_id, options={})
|
def create_mount_target(file_system_id, subnet_id, options={})
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
default_security_group = Fog::Compute[:aws].security_groups.detect { |sg| sg.description == "default group" }
|
default_security_group = mock_compute.security_groups.detect { |sg| sg.description == 'default group' }
|
||||||
security_groups = options["SecurityGroups"] || [default_security_group.group_id]
|
security_groups = options["SecurityGroups"] || [default_security_group.group_id]
|
||||||
|
|
||||||
unless file_system = self.data[:file_systems][file_system_id]
|
unless file_system = self.data[:file_systems][file_system_id]
|
||||||
raise Fog::AWS::EFS::NotFound.new("invalid file system ID: #{file_system_id}")
|
raise Fog::AWS::EFS::NotFound.new("invalid file system ID: #{file_system_id}")
|
||||||
|
@ -37,12 +37,12 @@ module Fog
|
||||||
raise Fog::AWS::EFS::IncorrectFileSystemLifeCycleState.new("")
|
raise Fog::AWS::EFS::IncorrectFileSystemLifeCycleState.new("")
|
||||||
end
|
end
|
||||||
|
|
||||||
unless subnet = Fog::Compute[:aws].subnets.get(subnet_id)
|
unless subnet = mock_compute.subnets.get(subnet_id)
|
||||||
raise Fog::AWS::EFS::InvalidSubnet.new("invalid subnet ID: #{subnet_id}")
|
raise Fog::AWS::EFS::InvalidSubnet.new("invalid subnet ID: #{subnet_id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
security_groups.each do |sg|
|
security_groups.each do |sg|
|
||||||
raise Fog::AWS::EFS::NotFound.new("invalid security group ID: #{sg}") unless Fog::Compute[:aws].data[:security_groups].values.detect { |sgd| sgd["groupId"] == sg }
|
raise Fog::AWS::EFS::NotFound.new("invalid security group ID: #{sg}") unless mock_compute.data[:security_groups].values.detect { |sgd| sgd["groupId"] == sg }
|
||||||
end
|
end
|
||||||
|
|
||||||
id = "fsmt-#{Fog::Mock.random_letters(8)}"
|
id = "fsmt-#{Fog::Mock.random_letters(8)}"
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
security_groups.each do |sg|
|
security_groups.each do |sg|
|
||||||
raise Fog::AWS::EFS::NotFound.new("invalid security group ID: #{sg}") unless Fog::Compute[:aws].data[:security_groups].values.detect { |sgd| sgd["groupId"] == sg }
|
raise Fog::AWS::EFS::NotFound.new("invalid security group ID: #{sg}") unless mock_compute.data[:security_groups].values.detect { |sgd| sgd["groupId"] == sg }
|
||||||
end
|
end
|
||||||
|
|
||||||
self.data[:security_groups][id] = security_groups
|
self.data[:security_groups][id] = security_groups
|
||||||
|
|
Loading…
Add table
Reference in a new issue