mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
mock instance stop and start properly
This commit is contained in:
parent
7a02ca2318
commit
eef87291d5
5 changed files with 25 additions and 3 deletions
|
@ -199,7 +199,7 @@ module Fog
|
||||||
when 'rebooting'
|
when 'rebooting'
|
||||||
instance['instanceState'] = { 'code' => 16, 'name' => 'running' }
|
instance['instanceState'] = { 'code' => 16, 'name' => 'running' }
|
||||||
when 'stopping'
|
when 'stopping'
|
||||||
instance['instanceState'] = { 'code' => 0, 'name' => 'stopping' }
|
instance['instanceState'] = { 'code' => 0, 'name' => 'stopped' }
|
||||||
instance['stateReason'] = { 'code' => 0 }
|
instance['stateReason'] = { 'code' => 0 }
|
||||||
when 'shutting-down'
|
when 'shutting-down'
|
||||||
if Time.now - self.data[:deleted_at][instance['instanceId']] >= Fog::Mock.delay * 2
|
if Time.now - self.data[:deleted_at][instance['instanceId']] >= Fog::Mock.delay * 2
|
||||||
|
|
|
@ -41,6 +41,7 @@ module Fog
|
||||||
response.status = 200
|
response.status = 200
|
||||||
|
|
||||||
response.body = {
|
response.body = {
|
||||||
|
'requestId' => Fog::AWS::Mock.request_id,
|
||||||
'instancesSet' => instance_set.reduce([]) do |ia, instance|
|
'instancesSet' => instance_set.reduce([]) do |ia, instance|
|
||||||
ia << {'currentState' => { 'code' => 0, 'name' => 'pending' },
|
ia << {'currentState' => { 'code' => 0, 'name' => 'pending' },
|
||||||
'previousState' => instance['instanceState'],
|
'previousState' => instance['instanceState'],
|
||||||
|
|
|
@ -42,6 +42,7 @@ module Fog
|
||||||
response.status = 200
|
response.status = 200
|
||||||
|
|
||||||
response.body = {
|
response.body = {
|
||||||
|
'requestId' => Fog::AWS::Mock.request_id,
|
||||||
'instancesSet' => instance_set.reduce([]) do |ia, instance|
|
'instancesSet' => instance_set.reduce([]) do |ia, instance|
|
||||||
instance['classicLinkSecurityGroups'] = nil
|
instance['classicLinkSecurityGroups'] = nil
|
||||||
instance['classicLinkVpcId'] = nil
|
instance['classicLinkVpcId'] = nil
|
||||||
|
|
|
@ -60,6 +60,17 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do
|
||||||
@instance.associate_public_ip == false
|
@instance.associate_public_ip == false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test('#stop') do
|
||||||
|
@instance.stop
|
||||||
|
@instance.wait_for { state == "stopped" }
|
||||||
|
@instance.state == "stopped"
|
||||||
|
end
|
||||||
|
|
||||||
|
test("#start") do
|
||||||
|
@instance.start
|
||||||
|
@instance.wait_for { ready? }
|
||||||
|
@instance.state == "running"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@instance.destroy
|
@instance.destroy
|
||||||
|
|
|
@ -81,7 +81,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
||||||
'timestamp' => Time
|
'timestamp' => Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@terminate_instances_format = {
|
@instance_state_change_format = {
|
||||||
'instancesSet' => [{
|
'instancesSet' => [{
|
||||||
'currentState' => {'code' => Integer, 'name' => String},
|
'currentState' => {'code' => Integer, 'name' => String},
|
||||||
'instanceId' => String,
|
'instanceId' => String,
|
||||||
|
@ -161,6 +161,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
||||||
'eventsSet' => [Fog::Nullable::Hash],
|
'eventsSet' => [Fog::Nullable::Hash],
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
tests('success') do
|
tests('success') do
|
||||||
|
|
||||||
@instance_id = nil
|
@instance_id = nil
|
||||||
|
@ -246,7 +247,15 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
|
||||||
Fog::Compute[:aws].reboot_instances(@instance_id).body
|
Fog::Compute[:aws].reboot_instances(@instance_id).body
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#terminate_instances('#{@instance_id}')").formats(@terminate_instances_format) do
|
tests("#stop_instances('#{@instance_id}')").formats(@instance_state_change_format) do
|
||||||
|
Fog::Compute[:aws].stop_instances(@instance_id).body
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#start_instances('#{@instance_id}')").formats(@instance_state_change_format) do
|
||||||
|
Fog::Compute[:aws].start_instances(@instance_id).body
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#terminate_instances('#{@instance_id}')").formats(@instance_state_change_format) do
|
||||||
Fog::Compute[:aws].terminate_instances(@instance_id).body
|
Fog::Compute[:aws].terminate_instances(@instance_id).body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue