-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update deco, dont return terminated instances (#8)
- Loading branch information
Showing
3 changed files
with
91 additions
and
3 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,81 @@ | ||
package ec2 | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/aws/aws-sdk-go/service/ec2/ec2iface" | ||
) | ||
|
||
func (m *mockEC2Client) DescribeInstancesWithContext(ctx context.Context, input *ec2.DescribeInstancesInput, opts ...request.Option) (*ec2.DescribeInstancesOutput, error) { | ||
if m.err != nil { | ||
return nil, m.err | ||
} | ||
|
||
if len(input.InstanceIds) != 0 && aws.StringValue(input.InstanceIds[0]) == "i-notfound" { | ||
return &ec2.DescribeInstancesOutput{}, nil | ||
} else if len(input.InstanceIds) != 0 && aws.StringValue(input.InstanceIds[0]) == "i-multiple" { | ||
return &ec2.DescribeInstancesOutput{ | ||
Reservations: []*ec2.Reservation{}, | ||
}, nil | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func TestEc2_GetInstance(t *testing.T) { | ||
type fields struct { | ||
session *session.Session | ||
Service ec2iface.EC2API | ||
DefaultKMSKeyId string | ||
DefaultSgs []string | ||
DefaultSubnets []string | ||
org string | ||
} | ||
type args struct { | ||
ctx context.Context | ||
id string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *ec2.Instance | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "empty id", | ||
fields: fields{Service: newmockEC2Client(t, nil)}, | ||
args: args{ | ||
ctx: context.TODO(), | ||
id: "", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
e := &Ec2{ | ||
session: tt.fields.session, | ||
Service: tt.fields.Service, | ||
DefaultKMSKeyId: tt.fields.DefaultKMSKeyId, | ||
DefaultSgs: tt.fields.DefaultSgs, | ||
DefaultSubnets: tt.fields.DefaultSubnets, | ||
org: tt.fields.org, | ||
} | ||
got, err := e.GetInstance(tt.args.ctx, tt.args.id) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Ec2.GetInstance() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("Ec2.GetInstance() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |