From 3a1287def03f393b6b5fadf1a39bf58fdd37f740 Mon Sep 17 00:00:00 2001 From: Dylan Egan Date: Thu, 7 Jul 2011 13:45:39 -0700 Subject: [PATCH] delete_load_balancer_listeners and delete_load_balancer (with two more tests). --- .../aws/requests/elb/delete_load_balancer.rb | 18 ++++++++++++++++++ .../elb/delete_load_balancer_listeners.rb | 19 +++++++++++++++++++ tests/aws/requests/elb/load_balancer_tests.rb | 13 +++++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/fog/aws/requests/elb/delete_load_balancer.rb b/lib/fog/aws/requests/elb/delete_load_balancer.rb index 62771ccee..802127e90 100644 --- a/lib/fog/aws/requests/elb/delete_load_balancer.rb +++ b/lib/fog/aws/requests/elb/delete_load_balancer.rb @@ -28,6 +28,24 @@ module Fog end end + + class Mock + def delete_load_balancer(lb_name) + response = Excon::Response.new + response.status = 200 + + self.data[:load_balancers].delete(lb_name) + + response.body = { + 'ResponseMetadata' => { + 'RequestId' => Fog::AWS::Mock.request_id + }, + 'DeleteLoadBalancerResult' => nil + } + + response + end + end end end end diff --git a/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb b/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb index ce3fe3cdc..e11bc3a0f 100644 --- a/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb +++ b/lib/fog/aws/requests/elb/delete_load_balancer_listeners.rb @@ -26,6 +26,25 @@ module Fog end end + + class Mock + def delete_load_balancer_listeners(lb_name, load_balancer_ports) + raise Fog::AWS::ELB::NotFound unless load_balancer = self.data[:load_balancers][lb_name] + + response = Excon::Response.new + response.status = 200 + + load_balancer['ListenerDescriptions'].delete_if { |listener| load_balancer_ports.include? listener['Listener']['LoadBalancerPort'] } + + response.body = { + 'ResponseMetadata' => { + 'RequestId' => Fog::AWS::Mock.request_id + } + } + + response + end + end end end end diff --git a/tests/aws/requests/elb/load_balancer_tests.rb b/tests/aws/requests/elb/load_balancer_tests.rb index 97f118c19..1b8ec2f29 100644 --- a/tests/aws/requests/elb/load_balancer_tests.rb +++ b/tests/aws/requests/elb/load_balancer_tests.rb @@ -62,14 +62,11 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, policies).body end - pending if Fog.mocking? - tests("#set_load_balancer_policies_of_listener removes policy").formats(AWS::ELB::Formats::BASIC) do port = 80 - body = AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, []).body + 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 @@ -78,5 +75,13 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do tests("#delete_load_balancer").formats(AWS::ELB::Formats::DELETE_LOAD_BALANCER) do AWS[:elb].delete_load_balancer(@load_balancer_id).body end + + tests("#delete_load_balancer when non existant").formats(AWS::ELB::Formats::DELETE_LOAD_BALANCER) do + AWS[:elb].delete_load_balancer('non-existant').body + end + + tests("#delete_load_balancer when already deleted").formats(AWS::ELB::Formats::DELETE_LOAD_BALANCER) do + AWS[:elb].delete_load_balancer(@load_balancer_id).body + end end end