mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Start ELB mocks. Support create_load_balancer and describe_load_balancers.
This commit is contained in:
parent
47e0b65c2a
commit
46c2ef983a
4 changed files with 111 additions and 4 deletions
|
@ -36,10 +36,43 @@ module Fog
|
|||
|
||||
class Mock
|
||||
|
||||
def initialize(options={})
|
||||
Fog::Mock.not_implemented
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, region|
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
hash[region] = Hash.new do |region_hash, key|
|
||||
region_hash[key] = {
|
||||
:owner_id => owner_id,
|
||||
:load_balancers => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.dns_name(name, region)
|
||||
"#{name}-#{Fog::Mock.random_hex(8)}.#{region}.elb.amazonaws.com"
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@aws_access_key_id = options[:aws_access_key_id]
|
||||
|
||||
@region = options[:region] || 'us-east-1'
|
||||
|
||||
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1'].include?(@region)
|
||||
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@region][@aws_access_key_id]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data[@region].delete(@aws_access_key_id)
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
|
|
|
@ -49,6 +49,51 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_load_balancer(availability_zones, lb_name, listeners)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
dns_name = Fog::AWS::ELB::Mock.dns_name(lb_name, @region)
|
||||
self.data[:load_balancers][lb_name] = {
|
||||
'AvailabilityZones' => availability_zones,
|
||||
'CanonicalHostedZoneName' => '',
|
||||
'CanonicalHostedZoneNameID' => '',
|
||||
'CreatedTime' => Time.now,
|
||||
'DNSName' => dns_name,
|
||||
'HealthCheck' => {
|
||||
'HealthyThreshold' => 3,
|
||||
'Interval' => 60,
|
||||
'Target' => 'TCP:5000',
|
||||
'Timeout' => 60,
|
||||
'UnhealthyThreshold' => 2
|
||||
},
|
||||
'Instances' => [],
|
||||
'ListenerDescriptions' => [],
|
||||
'LoadBalancerName' => lb_name,
|
||||
'Policies' => {
|
||||
'LBCookieStickinessPolicies' => [],
|
||||
'AppCookieStickinessPolicies' => []
|
||||
},
|
||||
'SourceSecurityGroup' => {
|
||||
'GroupName' => '',
|
||||
'OwnerAlias' => ''
|
||||
}
|
||||
}
|
||||
|
||||
response.body = {
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
},
|
||||
'CreateLoadBalancerResult' => {
|
||||
'DNSName' => dns_name
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,6 +51,35 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_load_balancers(lb_names = [])
|
||||
lb_names = [*lb_names]
|
||||
load_balancers = if lb_names.any?
|
||||
lb_names.map do |lb_name|
|
||||
lb = self.data[:load_balancers].find { |name, data| data if name == lb_name }
|
||||
raise Fog::AWS::ELB::NotFound unless lb
|
||||
lb
|
||||
end.compact
|
||||
else
|
||||
self.data[:load_balancers].values
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
response.body = {
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
},
|
||||
'DescribeLoadBalancersResult' => {
|
||||
'LoadBalancerDescriptions' => load_balancers
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,6 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do
|
|||
@load_balancer_id = 'fog-test-elb'
|
||||
|
||||
tests('success') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests("#create_load_balancer").formats(AWS::ELB::Formats::CREATE_LOAD_BALANCER) do
|
||||
zones = ['us-east-1a']
|
||||
listeners = [{'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'http'}]
|
||||
|
@ -18,6 +16,8 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do
|
|||
raises(Fog::AWS::ELB::NotFound) { AWS[:elb].describe_load_balancers('none-such-lb') }
|
||||
end
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
tests("#configure_health_check").formats(AWS::ELB::Formats::CONFIGURE_HEALTH_CHECK) do
|
||||
health_check = {
|
||||
'Target' => 'HTTP:80/index.html',
|
||||
|
|
Loading…
Add table
Reference in a new issue