1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|rds] Refactor RDS model & collection tests

Added tests for several models & collections.
This commit is contained in:
Aaron Suggs 2011-06-04 07:55:56 -04:00
parent 3e5d48a1c5
commit c95038bdc6
13 changed files with 86 additions and 120 deletions

View file

@ -65,8 +65,6 @@ module Fog
merge_attributes(data) merge_attributes(data)
end end
end end
end end
end end

View file

@ -0,0 +1,5 @@
def rds_default_server_params
{ :id => uniq_id, :allocated_storage => 5, :engine => 'mysql',
:master_username => 'foguser', :password => 'fogpassword',
:backup_retention_period => 0 }
end

View file

@ -3,6 +3,7 @@ Shindo.tests("AWS::RDS | parameter_group", ['aws', 'rds']) do
group_name = 'fog-test' group_name = 'fog-test'
params = {:id => group_name, :family => 'mysql5.1', :description => group_name} params = {:id => group_name, :family => 'mysql5.1', :description => group_name}
pending if Fog.mocking?
model_tests(AWS[:rds].parameter_groups, params, false) do model_tests(AWS[:rds].parameter_groups, params, false) do
tests('#parameters') do tests('#parameters') do
#search for a sample parameter #search for a sample parameter

View file

@ -3,5 +3,6 @@ Shindo.tests("AWS::RDS | parameter_groups", ['aws', 'rds']) do
group_name = 'fog-test' group_name = 'fog-test'
params = {:id => group_name, :family => 'mysql5.1', :description => group_name} params = {:id => group_name, :family => 'mysql5.1', :description => group_name}
pending if Fog.mocking?
collection_tests(AWS[:rds].parameter_groups, params, false) collection_tests(AWS[:rds].parameter_groups, params, false)
end end

View file

@ -2,11 +2,11 @@ Shindo.tests("AWS::RDS | security_group", ['aws', 'rds']) do
group_name = 'fog-test' group_name = 'fog-test'
params = {:id => group_name, :description => 'fog test'} params = {:id => group_name, :description => 'fog test'}
pending if Fog.mocking?
model_tests(AWS[:rds].security_groups, params, false) do model_tests(AWS[:rds].security_groups, params, false) do
tests("#description").returns('fog test') { @instance.description } tests("#description").returns('fog test') { @instance.description }
# TODO:
tests("#ready?")
tests("#authorize_ec2_security_group").succeeds do tests("#authorize_ec2_security_group").succeeds do
@ec2_sec_group = AWS[:compute].security_groups.create(:name => 'fog-test', :description => 'fog test') @ec2_sec_group = AWS[:compute].security_groups.create(:name => 'fog-test', :description => 'fog test')

View file

@ -1,5 +1,6 @@
Shindo.tests("AWS::RDS | security groups", ['aws', 'rds']) do Shindo.tests("AWS::RDS | security groups", ['aws', 'rds']) do
params = {:id => 'fog-test', :description => 'fog test'} params = {:id => 'fog-test', :description => 'fog test'}
pending if Fog.mocking?
collection_tests(AWS[:rds].security_groups, params, false) collection_tests(AWS[:rds].security_groups, params, false)
end end

View file

@ -1,13 +1,10 @@
Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
@params = {:id => uniq_id, :allocated_storage => 5, :engine => 'mysql', pending if Fog.mocking?
:master_username => 'foguser', :password => 'fogpassword',
:backup_retention_period => 0
}
model_tests(AWS[:rds].servers, @params, false) do model_tests(AWS[:rds].servers, rds_default_server_params, false) do
# We'll need this later; create it early to avoid waiting # We'll need this later; create it early to avoid waiting
@instance_with_final_snapshot = AWS[:rds].servers.create(@params.merge(:id => uniq_id("fog-snapshot-test"))) @instance_with_final_snapshot = AWS[:rds].servers.create(rds_default_server_params.merge(:id => uniq_id("fog-snapshot-test"), :backup_retention_period => 1))
@instance.wait_for { ready? } @instance.wait_for { ready? }
@ -32,11 +29,11 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
parameter_group = AWS[:rds].parameter_groups.create(:id => uniq_id, :family => 'mysql5.1', :description => 'fog-test') parameter_group = AWS[:rds].parameter_groups.create(:id => uniq_id, :family => 'mysql5.1', :description => 'fog-test')
orig_security_groups = @instance.db_security_groups.map{|h| h['DBSecurityGroupName']} orig_security_groups = @instance.db_security_groups.map{|h| h['DBSecurityGroupName']}
security_group = AWS[:rds].security_group.create(:id => uniq_id, :description => 'fog-test') security_group = AWS[:rds].security_groups.create(:id => uniq_id, :description => 'fog-test')
modify_options = { modify_options = {
'DBParameterGroupName' => parameter_group.id, 'DBParameterGroupName' => parameter_group.id,
'DBSecurityGroups' => orig_security_groups << security_group.id 'DBSecurityGroups' => orig_security_groups + [security_group.id]
} }
@instance.modify(true, modify_options) @instance.modify(true, modify_options)
@ -50,7 +47,9 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
@instance.db_security_groups.any?{|hash| hash['DBSecurityGroupName'] == security_group.id} @instance.db_security_groups.any?{|hash| hash['DBSecurityGroupName'] == security_group.id}
end end
@instance.wait_for { ready? } @instance.reboot
@instance.reload.wait_for { state == 'rebooting' }
@instance.reload.wait_for { ready? }
# Restore back to original state # Restore back to original state
restore_options = { restore_options = {
@ -59,6 +58,14 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
} }
@instance.modify(true, restore_options) @instance.modify(true, restore_options)
@instance.reboot
@instance.reload.wait_for { state == 'rebooting' }
@instance.reload.wait_for do
ready? &&
db_security_groups.all? {|hash| hash['Status'] == 'active'} &&
db_parameter_groups.all? {|hash| hash['ParameterApplyStatus'] == 'in-sync' }
end
parameter_group.destroy parameter_group.destroy
security_group.destroy security_group.destroy
end end
@ -66,8 +73,18 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
tests("#reboot").succeeds do tests("#reboot").succeeds do
@instance.reboot @instance.reboot
end end
@instance.wait_for {state == 'rebooting'} @instance.reload.wait_for {state == 'rebooting'}
@instance.wait_for { ready? } @instance.reload.wait_for { ready? }
tests('#create_read_replica').succeeds do
replica = @instance_with_final_snapshot.create_read_replica(uniq_id('fog-replica'))
@instance_with_final_snapshot.reload
returns([replica.id]) { @instance_with_final_snapshot.read_replica_identifiers }
returns(@instance_with_final_snapshot.id) { replica.read_replica_source }
replica.wait_for { ready? }
replica.destroy
end
test("Destroying with a final snapshot") do test("Destroying with a final snapshot") do
final_snapshot_id = 'fog-test-snapshot' final_snapshot_id = 'fog-test-snapshot'

View file

@ -1,9 +1,8 @@
Shindo.tests("AWS::RDS | servers", ['aws', 'rds']) do Shindo.tests("AWS::RDS | servers", ['aws', 'rds']) do
params = {:id => uniq_id, :allocated_storage => 5, :engine => 'mysql', pending if Fog.mocking?
:master_username => 'foguser', :password => 'fogpassword',
:backup_retention_period => 0
}
collection_tests(AWS[:rds].servers, params, false) collection_tests(AWS[:rds].servers, rds_default_server_params, false) do
@instance.wait_for { ready? }
end
end end

View file

@ -0,0 +1,15 @@
Shindo.tests("AWS::RDS | snapshot", ['aws', 'rds']) do
pending if Fog.mocking?
@server = AWS[:rds].servers.create(rds_default_server_params)
@server.wait_for { ready? }
params = {:id => uniq_id, :instance_id => @server.id}
model_tests(AWS[:rds].snapshots, params, false) do
@instance.wait_for { ready? }
end
@server.destroy
end

View file

@ -0,0 +1,15 @@
Shindo.tests("AWS::RDS | snapshots", ['aws', 'rds']) do
pending if Fog.mocking?
@server = AWS[:rds].servers.create(rds_default_server_params)
@server.wait_for { ready? }
params = {:id => uniq_id, :instance_id => @server.id}
collection_tests(AWS[:rds].snapshots, params, false) do
@instance.wait_for { ready? }
end
@server.destroy
end

View file

@ -1,98 +0,0 @@
Shindo.tests('AWS::RDS | models', ['aws', 'rds']) do
@db_instance_id='fog-test'
@db_replica_id='fog-replica'
tests('success') do
pending if Fog.mocking?
tests('parametergroups') do
group = nil
tests('create') do
group = AWS[:rds].parameter_groups.create :id => 'testgroup', :family => 'mysql5.1', :description => 'test'
end
tests('#parameters') do
parameters = group.parameters
#search for a sample parameter
tests 'contains parameter' do
returns(true){ !!parameters.detect {|p| p.name == 'query_cache_size'}}
end
end
tests('modify') do
group.modify([{:name => 'query_cache_size', :value => '6553600', :apply_method => 'immediate'}])
tests 'parameter has changed' do
returns('6553600'){group.parameters.detect {|p| p.name == 'query_cache_size'}.value}
end
end
tests('destroy').succeeds do
group.destroy
end
returns(nil){AWS[:rds].parameter_groups.detect {|g| g.id == 'testgroup'}}
end
tests('servers') do
server = nil
tests('create').succeeds do
server = AWS[:rds].servers.create( :id => @db_instance_id, :allocated_storage => 5, :engine => 'mysql',
:master_username => 'foguser', :password => 'fogpassword',
:backup_retention_period => 0)
end
server.wait_for {ready?}
tests('snapshots') do
snapshot = nil
tests('create').succeeds do
snapshot = server.snapshots.create(:id => 'testsnapshot')
end
returns(@db_instance_id){snapshot.instance_id}
server.reload
server.wait_for {ready?}
snapshot.wait_for {ready?}
tests('all') do
returns(['testsnapshot']){server.snapshots.collect {|s| s.id}}
end
tests('destroy').succeeds do
snapshot.destroy
end
returns([]) {server.snapshots}
end
group = AWS[:rds].parameter_groups.create :id => 'some-group', :family => 'mysql5.1', :description => 'test'
tests('modify') do
server.modify(true, 'DBParameterGroupName' => 'some-group')
server.reload
returns('some-group'){server.db_parameter_groups.first['DBParameterGroupName']}
end
tests('reboot').succeeds do
server.reboot
end
server.wait_for {state == 'rebooting'}
server.wait_for {state == 'available'}
tests('destroy').succeeds do
server.destroy('finalsnapshot')
end
Fog.wait_for do
AWS[:rds].servers.length == 0
end
group.destroy
tests("final snapshot was created") do
AWS[:rds].snapshots.get('finalsnapshot').destroy
end
end
end
end

View file

@ -38,7 +38,7 @@ def collection_tests(collection, params = {}, mocks_implemented = true)
tests('failure') do tests('failure') do
if !Fog.mocking? || mocks_implemented if !Fog.mocking? || mocks_implemented
@identity = @identity.to_s.gsub(/\w/, '0') @identity = @identity.to_s.gsub(/\w/, 'a')
end end
tests("#get('#{@identity}')").returns(nil) do tests("#get('#{@identity}')").returns(nil) do

View file

@ -24,3 +24,15 @@ def model_tests(collection, params = {}, mocks_implemented = true)
end end
end end
# Generates a unique identifier with a random differentiator.
# Useful when rapidly re-running tests, so we don't have to wait
# serveral minutes for deleted objects to disappear from the API
# E.g. 'fog-test-1234'
def uniq_id(base_name = 'fog-test')
# random_differentiator
suffix = rand(65536).to_s(16).rjust(4, '0')
[base_name, suffix] * '-'
end