rearrange and refactor specs to make more sense
This commit is contained in:
parent
b463901f98
commit
55e60a989e
|
@ -1,5 +1,5 @@
|
|||
class AwsHaRelease
|
||||
attr_reader :max_size_change
|
||||
attr_reader :group
|
||||
|
||||
def initialize(opts)
|
||||
AWS.config(access_key_id: opts[:aws_access_key], secret_access_key: opts[:aws_secret_key], region: opts[:region])
|
||||
|
@ -20,7 +20,7 @@ class AwsHaRelease
|
|||
|
||||
if @group.max_size == @group.desired_capacity
|
||||
@group.update(max_size: @group.max_size + 1)
|
||||
@max_size_change += 1
|
||||
@max_size_change = 1
|
||||
end
|
||||
|
||||
@group.update(desired_capacity: @group.desired_capacity + 1)
|
||||
|
@ -39,6 +39,7 @@ class AwsHaRelease
|
|||
|
||||
if @max_size_change > 0
|
||||
@group.update(max_size: @group.max_size - @max_size_change)
|
||||
@max_size_change = 0
|
||||
end
|
||||
|
||||
@group.resume_all_processes
|
||||
|
|
|
@ -43,23 +43,29 @@ describe 'aws-ha-release' do
|
|||
@aws_ha_release.execute!
|
||||
end
|
||||
|
||||
it 'adjusts the maximum size if the desired capacity is equal to it' do
|
||||
it 'adjusts the max size as well as the desired capacity if the desired capacity is equal to it' do
|
||||
@group.update(max_size: 1, desired_capacity: 1)
|
||||
expect(@aws_ha_release.max_size_change).to eq 0
|
||||
|
||||
@aws_ha_release.group.should_receive(:update).with(max_size: 2).ordered.and_call_original
|
||||
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 2).ordered.and_call_original
|
||||
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 1).ordered.and_call_original
|
||||
@aws_ha_release.group.should_receive(:update).with(max_size: 1).ordered.and_call_original
|
||||
@aws_ha_release.execute!
|
||||
|
||||
expect(@group.max_size).to eq 2
|
||||
expect(@aws_ha_release.max_size_change).to eq 1
|
||||
end
|
||||
|
||||
it 'increases the desired capacity by 1' do
|
||||
it 'only adjusts the desired capacity if max size does not equal desired capacity' do
|
||||
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 2).ordered.and_call_original
|
||||
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 1).ordered.and_call_original
|
||||
@aws_ha_release.execute!
|
||||
|
||||
expect(@group.desired_capacity).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
describe 'determining if instances are in service' do
|
||||
before do
|
||||
@group = as.groups.create opts[:as_group_name]
|
||||
@aws_ha_release = AwsHaRelease.new(opts)
|
||||
end
|
||||
|
||||
context 'determining if instances are in service' do
|
||||
it 'checks all instances across a given load balancer' do
|
||||
load_balancer = AWS::FakeELB::LoadBalancer.new 'test_load_balancer_01'
|
||||
|
||||
|
@ -99,7 +105,6 @@ describe 'aws-ha-release' do
|
|||
expect(@aws_ha_release.all_instances_inservice?(load_balancers)).to eq true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#deregister_instance' do
|
||||
before do
|
||||
|
|
|
@ -37,6 +37,10 @@ module AWS
|
|||
end
|
||||
end
|
||||
|
||||
def resume_all_processes
|
||||
@suspended_processes.clear
|
||||
end
|
||||
|
||||
def update(options = {})
|
||||
options.each do |key, value|
|
||||
self.instance_variable_set "@#{key}", value
|
||||
|
|
Loading…
Reference in New Issue
Block a user