mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
finishing up address mocks
This commit is contained in:
parent
7dffa3db46
commit
7d70746c23
4 changed files with 62 additions and 27 deletions
|
@ -175,7 +175,7 @@ module Fog
|
|||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
|
||||
if Fog.mocking?
|
||||
@data = { :addresses => [] }
|
||||
@data = { 'addressesSet' => [] }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,9 +31,10 @@ else
|
|||
response = Fog::Response.new
|
||||
response.status = 200
|
||||
data ={
|
||||
'instanceId' => '',
|
||||
'publicIp' => Fog::AWS::Mock.ip_address
|
||||
}
|
||||
@data[:addresses] << data
|
||||
@data['addressesSet'] << data
|
||||
response.body = {
|
||||
'publicIp' => data['publicIp'],
|
||||
'requestId' => Fog::AWS::Mock.request_id
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
@ -24,3 +26,35 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def describe_addresses(public_ip = [])
|
||||
public_ip = [*public_ip]
|
||||
response = Fog::Response.new
|
||||
if public_ip != []
|
||||
addresses_set = @data['addressesSet'].select {|address| public_ip.include?(address['publicIp'])}
|
||||
else
|
||||
addresses_set = @data['addressesSet']
|
||||
end
|
||||
if public_ip.length == 0 || public_ip.length == addresses_set.length
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'addressesSet' => addresses_set
|
||||
}
|
||||
else
|
||||
response.status = 400
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -30,9 +30,9 @@ else
|
|||
|
||||
def release_address(public_ip)
|
||||
response = Fog::Response.new
|
||||
initial_addresses_count = @data[:addresses].length
|
||||
@data[:addresses].delete_if {|address| address['publicIp'] == public_ip}
|
||||
if initial_addresses_count > @data[:addresses].length
|
||||
initial_addresses_count = @data['addressesSet'].length
|
||||
@data['addressesSet'].delete_if {|address| address['publicIp'] == public_ip}
|
||||
if initial_addresses_count > @data['addressesSet'].length
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
|
|
Loading…
Reference in a new issue