-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch latest E2E test AMI ID dynamically
- Loading branch information
1 parent
8e85e1e
commit c27d8d3
Showing
5 changed files
with
150 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ec2 | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
) | ||
|
||
const incorrectTimeLayout = time.RFC1123 | ||
|
||
func TestGetLatestAMIID(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
images []*ec2.Image | ||
wantAMIID string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Get latest image ID success", | ||
images: []*ec2.Image{ | ||
{ | ||
ImageId: aws.String("ami-01234"), | ||
CreationDate: aws.String(time.Now().Format(timeLayout)), | ||
}, | ||
{ | ||
ImageId: aws.String("ami-56789"), | ||
CreationDate: aws.String(time.Time{}.Format(timeLayout)), | ||
}, | ||
}, | ||
wantAMIID: "ami-01234", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Get latest image ID failure - incorrect time layout", | ||
images: []*ec2.Image{ | ||
{ | ||
ImageId: aws.String("ami-01234"), | ||
CreationDate: aws.String(time.Now().Format(timeLayout)), | ||
}, | ||
{ | ||
ImageId: aws.String("ami-56789"), | ||
CreationDate: aws.String(time.Time{}.Format(incorrectTimeLayout)), | ||
}, | ||
}, | ||
wantAMIID: "", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Get latest image ID failure - empty images list", | ||
images: []*ec2.Image{}, | ||
wantAMIID: "", | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotImageID, err := getLatestAMIID(tt.images) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("getLatestAMIID() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if err == nil { | ||
if gotImageID != tt.wantAMIID { | ||
t.Errorf("getLatestAMIID() got = %v, want %v", gotImageID, tt.wantAMIID) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters