Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

configure_health_check should be more forgiving of the params passed.

  • Loading branch information...
commit 2fe18e0ef3f295d860818ff33db9fd88af52bc1b 1 parent b0b14ec
@grempe authored
Showing with 46 additions and 14 deletions.
  1. +8 −13 lib/AWS/ELB/load_balancers.rb
  2. +38 −1 test/test_ELB_load_balancers.rb
View
21 lib/AWS/ELB/load_balancers.rb
@@ -125,26 +125,21 @@ def deregister_instances_from_load_balancer( options = {} )
#
# Note: Completion of this API does not guarantee that operation has completed. Rather, it means that the request has been registered and the changes will happen shortly.
#
- # @option options [Hash] :health_check A Hash with the keys (:timeout, :interval, :unhealthy_threshold, :healthy_threshold)
# @option options [String] :load_balancer_name The name of the load balancer.
+ # @option options [Hash] :health_check A Hash with the key values provided as String or FixNum values (:timeout, :interval, :unhealthy_threshold, :healthy_threshold)
#
def configure_health_check( options = {} )
- raise ArgumentError, "No :health_check provided" if options[:health_check].nil? || options[:health_check].empty?
- raise ArgumentError, "No :health_check => :target provided" if options[:health_check][:target].nil? || options[:health_check][:target].empty?
- raise ArgumentError, "No :health_check => :timeout provided" if options[:health_check][:timeout].nil? || options[:health_check][:timeout].empty?
- raise ArgumentError, "No :health_check => :interval provided" if options[:health_check][:interval].nil? || options[:health_check][:interval].empty?
- raise ArgumentError, "No :health_check => :unhealthy_threshold provided" if options[:health_check][:unhealthy_threshold].nil? || options[:health_check][:unhealthy_threshold].empty?
- raise ArgumentError, "No :health_check => :healthy_threshold provided" if options[:health_check][:healthy_threshold].nil? || options[:health_check][:healthy_threshold].empty?
raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
+ raise ArgumentError, "No :health_check Hash provided" if options[:health_check].nil? || options[:health_check].empty?
params = {}
- params['LoadBalancerName'] = options[:load_balancer_name]
- params['HealthCheck.Target'] = options[:health_check][:target]
- params['HealthCheck.Timeout'] = options[:health_check][:timeout]
- params['HealthCheck.Interval'] = options[:health_check][:interval]
- params['HealthCheck.UnhealthyThreshold'] = options[:health_check][:unhealthy_threshold]
- params['HealthCheck.HealthyThreshold'] = options[:health_check][:healthy_threshold]
+ params['LoadBalancerName'] = options[:load_balancer_name]
+ params['HealthCheck.Target'] = options[:health_check][:target] unless options[:health_check][:target].nil?
+ params['HealthCheck.Timeout'] = options[:health_check][:timeout].to_s unless options[:health_check][:timeout].nil?
+ params['HealthCheck.Interval'] = options[:health_check][:interval].to_s unless options[:health_check][:interval].nil?
+ params['HealthCheck.UnhealthyThreshold'] = options[:health_check][:unhealthy_threshold].to_s unless options[:health_check][:unhealthy_threshold].nil?
+ params['HealthCheck.HealthyThreshold'] = options[:health_check][:healthy_threshold].to_s unless options[:health_check][:healthy_threshold].nil?
return response_generator(:action => "ConfigureHealthCheck", :params => params)
end
View
39 test/test_ELB_load_balancers.rb
@@ -206,7 +206,7 @@
lambda { @elb.deregister_instances_from_load_balancer(@valid_deregister_instances_from_load_balancer_params.merge(:instances=>[])) }.should.raise(AWS::ArgumentError)
end
- specify "should be able to degresiter instances from load balancers with degregister_instances_from_load_balancer" do
+ specify "should be able to configure_health_check for instances from load balancers" do
@elb.stubs(:make_request).with('ConfigureHealthCheck', {
'LoadBalancerName' => 'Test Name',
'HealthCheck.Interval' => '5',
@@ -218,8 +218,45 @@
response = @elb.configure_health_check(@valid_configure_health_check_params)
response.should.be.an.instance_of Hash
+
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params) }.should.not.raise(AWS::ArgumentError)
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params.merge(:load_balancer_name => nil)) }.should.raise(AWS::ArgumentError)
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params.merge(:load_balancer_name => "")) }.should.raise(AWS::ArgumentError)
+
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params.merge(:health_check => nil)) }.should.raise(AWS::ArgumentError)
+ lambda { @elb.configure_health_check(@valid_configure_health_check_params.merge(:health_check => "")) }.should.raise(AWS::ArgumentError)
+
end
+ specify "should be able to configure_health_check for instances from load balancers with string health check args" do
+ @elb.stubs(:make_request).with('ConfigureHealthCheck', {
+ 'LoadBalancerName' => 'Test Name',
+ 'HealthCheck.Interval' => '5',
+ 'HealthCheck.Target' => 'HTTP:80/servlets-examples/servlet/',
+ 'HealthCheck.HealthyThreshold' => '2',
+ 'HealthCheck.Timeout' => '2',
+ 'HealthCheck.UnhealthyThreshold' => '2'
+ }).returns stub(:body => @configure_health_check_response_body, :is_a? => true)
+
+ response = @elb.configure_health_check(@valid_configure_health_check_params.merge(:health_check => {:target => 'HTTP:80/servlets-examples/servlet/', :timeout => '2', :interval => '5', :unhealthy_threshold => '2', :healthy_threshold => '2' }))
+ response.should.be.an.instance_of Hash
+ end
+
+ specify "should be able to configure_health_check for instances from load balancers with FixNum health check args" do
+ @elb.stubs(:make_request).with('ConfigureHealthCheck', {
+ 'LoadBalancerName' => 'Test Name',
+ 'HealthCheck.Interval' => '5',
+ 'HealthCheck.Target' => 'HTTP:80/servlets-examples/servlet/',
+ 'HealthCheck.HealthyThreshold' => '2',
+ 'HealthCheck.Timeout' => '2',
+ 'HealthCheck.UnhealthyThreshold' => '2'
+ }).returns stub(:body => @configure_health_check_response_body, :is_a? => true)
+
+ response = @elb.configure_health_check(@valid_configure_health_check_params.merge(:health_check => {:target => 'HTTP:80/servlets-examples/servlet/', :timeout => 2, :interval => 5, :unhealthy_threshold => 2, :healthy_threshold => 2 }))
+ response.should.be.an.instance_of Hash
+ end
+
+
specify "method degregister_instances_from_load_balancer should reject bad arguments" do
@elb.stubs(:make_request).with('ConfigureHealthCheck', {
'LoadBalancerName' => 'Test Name',

0 comments on commit 2fe18e0

Please sign in to comment.
Something went wrong with that request. Please try again.