Skip to content

Commit

Permalink
add test for return single instance id
Browse files Browse the repository at this point in the history
  • Loading branch information
thaim committed Jan 5, 2023
1 parent 40390b0 commit 01d9afe
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ec2id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,33 @@ func TestEc2id(t *testing.T) {
}, nil).
AnyTimes()

mockClient.EXPECT().
DescribeInstances(context.TODO(), &ec2.DescribeInstancesInput{
Filters: []types.Filter{
{
Name: aws.String("tag:Name"),
Values: []string{"test"},
},
{
Name: aws.String("instance-state-name"),
Values: []string{"running"},
},
},
}).
Return(&ec2.DescribeInstancesOutput{
Reservations: []types.Reservation {
{
Instances: []types.Instance {
{
InstanceId: aws.String("i-00000000000abcdef"),
LaunchTime: aws.Time(time.Date(2023, 1, 4, 12, 0, 0, 0, time.UTC)),
},
},
},
},
}, nil).
AnyTimes()

cases := []struct {
name string
client EC2DescribeInstancesAPI
Expand All @@ -98,6 +125,14 @@ func TestEc2id(t *testing.T) {
wantErr: false,
expectErr: "",
},
{
name: "return instance-id",
client: mockClient,
instanceName: "test",
expect: "i-00000000000abcdef",
wantErr: false,
expectErr: "",
},
}

for _, tt := range cases {
Expand Down

0 comments on commit 01d9afe

Please sign in to comment.