From 824c271ae4bb28cb9a26d9b6fa910cd01838b3a9 Mon Sep 17 00:00:00 2001 From: Eugene Howe Date: Mon, 10 Oct 2016 08:46:46 -0400 Subject: [PATCH] fix some mocking behavior --- lib/fog/aws/efs.rb | 10 +++++++++- lib/fog/aws/requests/efs/create_mount_target.rb | 10 +++++----- .../efs/modify_mount_target_security_groups.rb | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/fog/aws/efs.rb b/lib/fog/aws/efs.rb index 711c29038..9832da0bc 100644 --- a/lib/fog/aws/efs.rb +++ b/lib/fog/aws/efs.rb @@ -29,6 +29,8 @@ module Fog request :modify_mount_target_security_groups class Mock + include Fog::AWS::CredentialFetcher::ConnectionMethods + def self.data @data ||= Hash.new do |hash, region| hash[region] = Hash.new do |region_hash, key| @@ -56,7 +58,13 @@ module Fog attr_accessor :region 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 diff --git a/lib/fog/aws/requests/efs/create_mount_target.rb b/lib/fog/aws/requests/efs/create_mount_target.rb index d1e8bc6a7..e3f96c60c 100644 --- a/lib/fog/aws/requests/efs/create_mount_target.rb +++ b/lib/fog/aws/requests/efs/create_mount_target.rb @@ -24,9 +24,9 @@ module Fog class Mock def create_mount_target(file_system_id, subnet_id, options={}) - response = Excon::Response.new - default_security_group = Fog::Compute[:aws].security_groups.detect { |sg| sg.description == "default group" } - security_groups = options["SecurityGroups"] || [default_security_group.group_id] + response = Excon::Response.new + default_security_group = mock_compute.security_groups.detect { |sg| sg.description == 'default group' } + security_groups = options["SecurityGroups"] || [default_security_group.group_id] unless file_system = self.data[:file_systems][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("") 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}") end 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 id = "fsmt-#{Fog::Mock.random_letters(8)}" diff --git a/lib/fog/aws/requests/efs/modify_mount_target_security_groups.rb b/lib/fog/aws/requests/efs/modify_mount_target_security_groups.rb index 0767ee41a..deef0bfd5 100644 --- a/lib/fog/aws/requests/efs/modify_mount_target_security_groups.rb +++ b/lib/fog/aws/requests/efs/modify_mount_target_security_groups.rb @@ -25,7 +25,7 @@ module Fog end 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 self.data[:security_groups][id] = security_groups