Skip to content

Commit

Permalink
catch any errors that may be thrown by removeEC2InstanceProtection fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
tonerdo committed Feb 22, 2018
1 parent 510f7f9 commit f0864b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion aws/ebs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,7 @@ func TestNukeEBSVolumesInUse(t *testing.T) {
// Volumes should still be in returned slice
assert.Contains(t, awsgo.StringValueSlice(volumeIds), awsgo.StringValue(volume.VolumeId))
// remove protection so instance can be cleaned up
removeEC2InstanceProtection(svc, &instance)
if err = removeEC2InstanceProtection(svc, &instance); err != nil {
assert.Fail(t, errors.WithStackTrace(err).Error())
}
}
10 changes: 7 additions & 3 deletions aws/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ func createTestEC2Instance(t *testing.T, session *session.Session, name string,
return *runResult.Instances[0]
}

func removeEC2InstanceProtection(svc *ec2.EC2, instance *ec2.Instance) {
func removeEC2InstanceProtection(svc *ec2.EC2, instance *ec2.Instance) error {
// make instance unprotected so it can be cleaned up
svc.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
_, err := svc.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
DisableApiTermination: &ec2.AttributeBooleanValue{
Value: awsgo.Bool(false),
},
InstanceId: instance.InstanceId,
})

return err
}

func findEC2InstancesByNameTag(output *ec2.DescribeInstancesOutput, name string) []*string {
Expand Down Expand Up @@ -158,7 +160,9 @@ func TestListInstances(t *testing.T) {
assert.Contains(t, instanceIds, instance.InstanceId)
assert.NotContains(t, instanceIds, protectedInstance.InstanceId)

removeEC2InstanceProtection(ec2.New(session), &protectedInstance)
if err = removeEC2InstanceProtection(ec2.New(session), &protectedInstance); err != nil {
assert.Fail(t, errors.WithStackTrace(err).Error())
}
}

func TestNukeInstances(t *testing.T) {
Expand Down

0 comments on commit f0864b0

Please sign in to comment.