1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/rackspace/requests/load_balancers/load_balancer_tests.rb

76 lines
3 KiB
Ruby
Raw Normal View History

Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace']) do
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
tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...)").formats(LOAD_BALANCER_FORMAT) do
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
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'}],
[{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}],
{ :algorithm => 'LEAST_CONNECTIONS' }).body
@lb_id = data['loadBalancer']['id']
returns('LEAST_CONNECTIONS') { data['loadBalancer']['algorithm'] }
data
end
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
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
end
2011-07-28 14:37:21 -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
tests('#create_load_balancer(invalid name)').raises(Fog::Rackspace::LoadBalancers::BadRequest) do
@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
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
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
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
end
end