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

166 lines
5 KiB
Ruby
Raw Normal View History

Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
tests('success') do
pending if Fog.mocking?
tests('load_balancers') do
tests('getting a missing elb') do
returns(nil) { AWS[:elb].load_balancers.get('no-such-elb') }
end
end
elb = nil
elb_id = 'fog-test'
tests('create') do
elb = AWS[:elb].load_balancers.create(:id => elb_id)
tests("dns names is set").returns(true) { elb.dns_name.is_a?(String) }
tests("created_at is set").returns(true) { (Time.now-10..Time.now).include? elb.created_at }
end
tests('all') do
elb_ids = AWS[:elb].load_balancers.all.map{|e| e.id}
tests("contains elb").returns(true) { elb_ids.include? elb_id }
end
tests('get') do
elb2 = AWS[:elb].load_balancers.get(elb_id)
tests('ids match').returns(elb_id) { elb2.id }
end
tests('createing a duplicate elb') do
raises(Fog::AWS::ELB::IdentifierTaken) do
AWS[:elb].load_balancers.create(:id => elb_id, :availability_zones => ['us-east-1d'])
end
end
tests('registering an invalid instance') do
raises(Fog::AWS::ELB::InvalidInstance) { elb.register_instances('i-00000000') }
end
tests('deregistering an invalid instance') do
raises(Fog::AWS::ELB::InvalidInstance) { elb.deregister_instances('i-00000000') }
end
server = AWS[:compute].servers.create
tests('register instance') do
begin
elb.register_instances(server.id)
rescue Fog::AWS::ELB::InvalidInstance
# It may take a moment for a newly created instances to be visible to ELB requests
raise if @retried_registered_instance
@retried_registered_instance = true
sleep 1
retry
end
returns([server.id]) { elb.instances }
end
tests('instance_health') do
returns('OutOfService') do
elb.instance_health.detect{|hash| hash['InstanceId'] == server.id}['State']
end
returns([server.id]) { elb.instances_out_of_service }
end
tests('deregister instance') do
elb.deregister_instances(server.id)
returns([]) { elb.instances }
end
server.destroy
tests('disable_availability_zones') do
elb.disable_availability_zones(%w{us-east-1c us-east-1d})
returns(%w{us-east-1a us-east-1b}) { elb.availability_zones.sort }
end
tests('enable_availability_zones') do
elb.enable_availability_zones(%w{us-east-1c us-east-1d})
returns(%w{us-east-1a us-east-1b us-east-1c us-east-1d}) { elb.availability_zones.sort }
end
tests('default health check') do
default_health_check = {
"HealthyThreshold"=>10,
"Timeout"=>5,
"UnhealthyThreshold"=>2,
"Interval"=>30,
"Target"=>"TCP:80"
}
returns(default_health_check) { elb.health_check }
end
tests('configure_health_check') do
new_health_check = {
"HealthyThreshold"=>5,
"Timeout"=>10,
"UnhealthyThreshold"=>3,
"Interval"=>15,
"Target"=>"HTTP:80/index.html"
}
elb.configure_health_check(new_health_check)
returns(new_health_check) { elb.health_check }
end
tests('listeners') do
default_listener_description = [{"Listener"=>{"InstancePort"=>80, "Protocol"=>"HTTP", "LoadBalancerPort"=>80}, "PolicyNames"=>[]}]
returns(default_listener_description) { elb.listener_descriptions }
tests('create') do
new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP'}
elb.create_listener(new_listener)
returns(true) { elb.listener_descriptions.include?({'Listener' => new_listener, 'PolicyNames' => []}) }
end
tests('destroy') do
elb.destroy_listener(443)
returns(default_listener_description) { elb.listener_descriptions }
end
end
tests('policies') do
app_policy = 'my-app-policy'
default_policies = {"LBCookieStickinessPolicies"=>[], "AppCookieStickinessPolicies"=>[]}
returns(default_policies) { elb.policies }
tests('create app policy') do
elb.create_app_policy(app_policy, 'my-app-cookie')
returns([{'PolicyName' => app_policy, 'CookieName' => 'my-app-cookie'}]) do
elb.policies['AppCookieStickinessPolicies']
end
end
tests('destroy app policy') do
elb.destroy_policy(app_policy)
returns(default_policies) { elb.policies }
end
lb_policy = 'my-lb-policy'
tests('create lb policy') do
elb.create_lb_policy(lb_policy, 600)
returns([{'PolicyName' => lb_policy, 'CookieExpirationPeriod' => 600}]) do
elb.policies['LBCookieStickinessPolicies']
end
end
tests('setting a listener policy') do
elb.set_listener_policy(80, lb_policy)
returns([lb_policy]) { elb.listener_descriptions.first['PolicyNames'] }
end
tests('unsetting a listener policy') do
elb.unset_listener_policy(80)
returns([]) { elb.listener_descriptions.first['PolicyNames'] }
end
end
tests('destroy') do
elb.destroy
end
end
end