2011-08-04 17:21:22 -04:00
|
|
|
Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace']) do
|
2011-07-07 18:17:31 -04:00
|
|
|
|
2011-08-16 12:56:44 -04:00
|
|
|
pending if Fog.mocking?
|
|
|
|
|
2011-07-28 14:37:21 -04:00
|
|
|
given_a_load_balancer_service do
|
|
|
|
tests('success') do
|
|
|
|
|
|
|
|
@lb_id = nil
|
|
|
|
@lb_name = 'fog' + Time.now.to_i.to_s
|
|
|
|
|
2011-11-24 12:32:53 -05:00
|
|
|
tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...)").formats(LOAD_BALANCER_FORMAT) do
|
2012-05-15 17:38:45 -04:00
|
|
|
data = @service.create_load_balancer(@lb_name, 'HTTP', 80, [{ :type => 'PUBLIC'}], [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}]).body
|
2011-07-28 14:37:21 -04:00
|
|
|
@lb_id = data['loadBalancer']['id']
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2012-03-31 16:07:27 -04:00
|
|
|
tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...with algorithm)").formats(LOAD_BALANCER_FORMAT) do
|
|
|
|
data = @service.create_load_balancer(@lb_name, 'HTTP', 80, [{ :type => 'PUBLIC'}],
|
2012-05-15 17:38:45 -04:00
|
|
|
[{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}],
|
2012-03-31 16:07:27 -04:00
|
|
|
{ :algorithm => 'LEAST_CONNECTIONS' }).body
|
|
|
|
@lb_id = data['loadBalancer']['id']
|
|
|
|
returns('LEAST_CONNECTIONS') { data['loadBalancer']['algorithm'] }
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2011-08-16 22:22:24 -04:00
|
|
|
tests("#update_load_balancer(#{@lb_id}) while immutable").raises(Fog::Rackspace::LoadBalancers::ServiceError) do
|
2011-07-28 14:37:21 -04:00
|
|
|
@service.update_load_balancer(@lb_id, { :port => 80 }).body
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#get_load_balancer(#{@lb_id})").formats(LOAD_BALANCER_FORMAT) do
|
|
|
|
@service.get_load_balancer(@lb_id).body
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#list_load_balancers()").formats(LOAD_BALANCERS_FORMAT) do
|
|
|
|
@service.list_load_balancers.body
|
|
|
|
end
|
|
|
|
|
|
|
|
until @service.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
|
|
|
|
sleep 10
|
|
|
|
end
|
|
|
|
|
2012-05-15 17:38:45 -04:00
|
|
|
tests("#list_load_balancers({:node_address => '1.1.1.1'})").formats(LOAD_BALANCERS_FORMAT) do
|
|
|
|
@service.list_load_balancers({:node_address => '1.1.1.1'}).body
|
2011-12-16 13:07:43 -05:00
|
|
|
end
|
2011-07-28 14:37:21 -04:00
|
|
|
|
2011-08-17 15:44:17 -04:00
|
|
|
tests("#update_load_balancer(#{@lb_id}, { :port => 80 })").succeeds do
|
2011-07-28 14:37:21 -04:00
|
|
|
@service.update_load_balancer(@lb_id, { :port => 80 }).body
|
|
|
|
end
|
|
|
|
|
|
|
|
until @service.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
|
|
|
|
sleep 10
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("#delete_load_balancer(#{@ld_id})").succeeds do
|
|
|
|
@service.delete_load_balancer(@lb_id).body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('failure') do
|
2011-08-16 22:22:24 -04:00
|
|
|
tests('#create_load_balancer(invalid name)').raises(Fog::Rackspace::LoadBalancers::BadRequest) do
|
2012-05-15 17:38:45 -04:00
|
|
|
@service.create_load_balancer('', 'HTTP', 80, [{ :type => 'PUBLIC'}], [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}])
|
2011-07-28 14:37:21 -04:00
|
|
|
end
|
|
|
|
|
2011-08-16 22:22:24 -04:00
|
|
|
tests('#get_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::NotFound) do
|
2011-07-28 14:37:21 -04:00
|
|
|
@service.get_load_balancer(0)
|
|
|
|
end
|
2011-09-26 17:56:32 -04:00
|
|
|
tests('#delete_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::BadRequest) do
|
2011-07-28 14:37:21 -04:00
|
|
|
@service.delete_load_balancer(0)
|
|
|
|
end
|
2011-08-16 22:22:24 -04:00
|
|
|
tests('#update_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::NotFound) do
|
2011-07-28 14:37:21 -04:00
|
|
|
@service.update_load_balancer(0, { :name => 'newname' })
|
|
|
|
end
|
2011-07-09 17:46:15 -04:00
|
|
|
end
|
2011-07-07 18:17:31 -04:00
|
|
|
end
|
|
|
|
end
|