Skip to content

Commit

Permalink
Merge pull request #97 from gruntwork-io/yori-fix-panic
Browse files Browse the repository at this point in the history
Fix source of panic in tests
  • Loading branch information
yorinasub17 authored Mar 3, 2020
2 parents 7080434 + d3d748b commit ca64898
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ jobs:
- checkout
- attach_workspace:
at: /go/src/github.com/gruntwork-io/cloud-nuke
- run: go run main.go aws --older-than 1h --force
- run:
command: go run main.go aws --older-than 1h --force
no_output_timeout: 1h

nuke_sandbox:
<<: *defaults
Expand All @@ -60,6 +62,7 @@ jobs:
at: /go/src/github.com/gruntwork-io/cloud-nuke
- run:
command: export AWS_ACCESS_KEY_ID=$SANDBOX_AWS_ACCESS_KEY_ID && export AWS_SECRET_ACCESS_KEY=$SANDBOX_AWS_SECRET_ACCESS_KEY && go run main.go aws --older-than 24h --force
no_output_timeout: 1h

deploy:
<<: *defaults
Expand Down
10 changes: 8 additions & 2 deletions aws/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"errors"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -48,7 +49,12 @@ func getAMIIdByName(svc *ec2.EC2, name string) (string, error) {
return "", gruntworkerrors.WithStackTrace(err)
}

return *imagesResult.Images[0].ImageId, nil
if len(imagesResult.Images) == 0 {
return "", gruntworkerrors.WithStackTrace(fmt.Errorf("No images found with name %s", name))
}

image := imagesResult.Images[0]
return awsgo.StringValue(image.ImageId), nil
}

// runAndWaitForInstance - Given a preconstructed ec2.RunInstancesInput object,
Expand Down Expand Up @@ -114,7 +120,7 @@ func runAndWaitForInstance(svc *ec2.EC2, name string, params *ec2.RunInstancesIn
func createTestEC2Instance(t *testing.T, session *session.Session, name string, protected bool) ec2.Instance {
svc := ec2.New(session)

imageID, err := getAMIIdByName(svc, "amzn-ami-hvm-2017.09.1.20180115-x86_64-gp2")
imageID, err := getAMIIdByName(svc, "amzn-ami-hvm-2018.03.0.20190826-x86_64-gp2")
if err != nil {
assert.Fail(t, err.Error())
}
Expand Down

0 comments on commit ca64898

Please sign in to comment.