diff --git a/lib/fog/aws/models/elb/load_balancer.rb b/lib/fog/aws/models/elb/load_balancer.rb index 3041c0517..c492c1235 100644 --- a/lib/fog/aws/models/elb/load_balancer.rb +++ b/lib/fog/aws/models/elb/load_balancer.rb @@ -16,7 +16,7 @@ module Fog def initialize(attributes={}) attributes[:availability_zones] ||= %w(us-east-1a us-east-1b us-east-1c us-east-1d) attributes['ListenerDescriptions'] ||= [{ - 'Listener' => {'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'http'}, + 'Listener' => {'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'HTTP'}, 'PolicyNames' => [] }] attributes['Policies'] ||= {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => []} diff --git a/lib/fog/aws/requests/elb/create_load_balancer.rb b/lib/fog/aws/requests/elb/create_load_balancer.rb index 978ddb738..8ead17a1f 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer.rb @@ -51,7 +51,7 @@ module Fog end class Mock - def create_load_balancer(availability_zones, lb_name, listeners) + def create_load_balancer(availability_zones, lb_name, listeners = []) response = Excon::Response.new response.status = 200 @@ -72,16 +72,7 @@ module Fog 'Target' => 'TCP:80' }, 'Instances' => [], - 'ListenerDescriptions' => [ - { - 'Listener' => { - 'InstancePort' => 80, - 'Protocol' => 'HTTP', - 'LoadBalancerPort' => 80 - }, - 'PolicyNames' => [] - } - ], + 'ListenerDescriptions' => [*listeners].map { |listener| {'Listener' => listener, 'PolicyNames' => []}}, 'LoadBalancerName' => lb_name, 'Policies' => { 'LBCookieStickinessPolicies' => [], diff --git a/tests/aws/requests/elb/model_tests.rb b/tests/aws/models/elb/model_tests.rb similarity index 97% rename from tests/aws/requests/elb/model_tests.rb rename to tests/aws/models/elb/model_tests.rb index 2b56c6029..58c181273 100644 --- a/tests/aws/requests/elb/model_tests.rb +++ b/tests/aws/models/elb/model_tests.rb @@ -105,13 +105,11 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do end tests('listeners') do - default_listener_description = [{"Listener"=>{"InstancePort"=>80, "Protocol"=>"HTTP", "LoadBalancerPort"=>80}, "PolicyNames"=>[]}] tests('default') do returns(1) { elb.listeners.size } listener = elb.listeners.first returns([80,80,'HTTP', []]) { [listener.instance_port, listener.lb_port, listener.protocol, listener.policy_names] } - end tests('#get') do diff --git a/tests/aws/requests/elb/listener_tests.rb b/tests/aws/requests/elb/listener_tests.rb new file mode 100644 index 000000000..09bbbf845 --- /dev/null +++ b/tests/aws/requests/elb/listener_tests.rb @@ -0,0 +1,22 @@ +Shindo.tests('AWS::ELB | listener_tests', ['aws', 'elb']) do + @load_balancer_id = 'fog-test-listener' + + tests('success') do + AWS[:elb].create_load_balancer(['us-east-1a'], @load_balancer_id, [{'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'HTTP'}]) + + tests("#create_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do + listeners = [ + {'Protocol' => 'TCP', 'LoadBalancerPort' => 443, 'InstancePort' => 443}, + {'Protocol' => 'HTTP', 'LoadBalancerPort' => 80, 'InstancePort' => 80} + ] + AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body + end + + tests("#delete_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do + ports = [80, 443] + AWS[:elb].delete_load_balancer_listeners(@load_balancer_id, ports).body + end + + AWS[:elb].delete_load_balancer(@load_balancer_id) + end +end diff --git a/tests/aws/requests/elb/load_balancer_tests.rb b/tests/aws/requests/elb/load_balancer_tests.rb index 1b8ec2f29..443ea2fb8 100644 --- a/tests/aws/requests/elb/load_balancer_tests.rb +++ b/tests/aws/requests/elb/load_balancer_tests.rb @@ -4,7 +4,7 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do tests('success') do tests("#create_load_balancer").formats(AWS::ELB::Formats::CREATE_LOAD_BALANCER) do zones = ['us-east-1a'] - listeners = [{'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'http'}] + listeners = [{'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'HTTP'}] AWS[:elb].create_load_balancer(zones, @load_balancer_id, listeners).body end @@ -28,50 +28,6 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do AWS[:elb].configure_health_check(@load_balancer_id, health_check).body end - tests("#create_app_cookie_stickiness_policy").formats(AWS::ELB::Formats::BASIC) do - cookie, policy = 'fog-app-cookie', 'fog-app-policy' - AWS[:elb].create_app_cookie_stickiness_policy(@load_balancer_id, policy, cookie).body - end - - tests("#create_lb_cookie_stickiness_policy with expiry").formats(AWS::ELB::Formats::BASIC) do - policy = 'fog-lb-expiry' - expiry = 300 - AWS[:elb].create_lb_cookie_stickiness_policy(@load_balancer_id, policy, expiry).body - end - - tests("#create_lb_cookie_stickiness_policy without expiry").formats(AWS::ELB::Formats::BASIC) do - policy = 'fog-lb-no-expiry' - AWS[:elb].create_lb_cookie_stickiness_policy(@load_balancer_id, policy).body - end - - tests("#delete_load_balancer_policy").formats(AWS::ELB::Formats::BASIC) do - policy = 'fog-lb-no-expiry' - AWS[:elb].delete_load_balancer_policy(@load_balancer_id, policy).body - end - - tests("#create_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do - listeners = [ - {'Protocol' => 'tcp', 'LoadBalancerPort' => 443, 'InstancePort' => 443}, - {'Protocol' => 'HTTP', 'LoadBalancerPort' => 80, 'InstancePort' => 80} - ] - AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body - end - - tests("#set_load_balancer_policies_of_listener adds policy").formats(AWS::ELB::Formats::BASIC) do - port, policies = 80, ['fog-lb-expiry'] - AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, policies).body - end - - tests("#set_load_balancer_policies_of_listener removes policy").formats(AWS::ELB::Formats::BASIC) do - port = 80 - AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, []).body - end - - tests("#delete_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do - ports = [80, 443] - AWS[:elb].delete_load_balancer_listeners(@load_balancer_id, ports).body - end - tests("#delete_load_balancer").formats(AWS::ELB::Formats::DELETE_LOAD_BALANCER) do AWS[:elb].delete_load_balancer(@load_balancer_id).body end diff --git a/tests/aws/requests/elb/policy_tests.rb b/tests/aws/requests/elb/policy_tests.rb new file mode 100644 index 000000000..285a044fb --- /dev/null +++ b/tests/aws/requests/elb/policy_tests.rb @@ -0,0 +1,41 @@ +Shindo.tests('AWS::ELB | policy_tests', ['aws', 'elb']) do + @load_balancer_id = 'fog-test-policies' + + tests('success') do + listeners = [{'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'HTTP'}] + AWS[:elb].create_load_balancer(['us-east-1a'], @load_balancer_id, listeners) + + tests("#create_app_cookie_stickiness_policy").formats(AWS::ELB::Formats::BASIC) do + cookie, policy = 'fog-app-cookie', 'fog-app-policy' + AWS[:elb].create_app_cookie_stickiness_policy(@load_balancer_id, policy, cookie).body + end + + tests("#create_lb_cookie_stickiness_policy with expiry").formats(AWS::ELB::Formats::BASIC) do + policy = 'fog-lb-expiry' + expiry = 300 + AWS[:elb].create_lb_cookie_stickiness_policy(@load_balancer_id, policy, expiry).body + end + + tests("#create_lb_cookie_stickiness_policy without expiry").formats(AWS::ELB::Formats::BASIC) do + policy = 'fog-lb-no-expiry' + AWS[:elb].create_lb_cookie_stickiness_policy(@load_balancer_id, policy).body + end + + tests("#delete_load_balancer_policy").formats(AWS::ELB::Formats::BASIC) do + policy = 'fog-lb-no-expiry' + AWS[:elb].delete_load_balancer_policy(@load_balancer_id, policy).body + end + + tests("#set_load_balancer_policies_of_listener adds policy").formats(AWS::ELB::Formats::BASIC) do + port, policies = 80, ['fog-lb-expiry'] + AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, policies).body + end + + tests("#set_load_balancer_policies_of_listener removes policy").formats(AWS::ELB::Formats::BASIC) do + port = 80 + AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, []).body + end + + AWS[:elb].delete_load_balancer(@load_balancer_id) + end +end