forked from ekristen/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecs-clusters_mock_test.go
82 lines (65 loc) · 1.79 KB
/
ecs-clusters_mock_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package resources
import (
"context"
"testing"
"github.com/golang/mock/gomock"
"github.com/gotidy/ptr"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/ekristen/aws-nuke/v3/mocks/mock_ecsiface"
)
func Test_Mock_ECSCluster_List(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockECS := mock_ecsiface.NewMockECSAPI(ctrl)
ecsClusterLister := ECSClusterLister{
mockSvc: mockECS,
}
mockECS.EXPECT().ListClusters(gomock.Any()).Return(&ecs.ListClustersOutput{
ClusterArns: []*string{
aws.String("foobar"),
},
}, nil)
mockECS.EXPECT().DescribeClusters(gomock.Any()).Return(&ecs.DescribeClustersOutput{
Clusters: []*ecs.Cluster{
{
ClusterArn: aws.String("foobar"),
Tags: []*ecs.Tag{
{
Key: aws.String("Name"),
Value: aws.String("foobar"),
},
{
Key: aws.String("aws-nuke"),
Value: aws.String("test"),
},
},
},
},
}, nil)
resources, err := ecsClusterLister.List(context.TODO(), testListerOpts)
a.Nil(err)
a.Len(resources, 1)
ecsCluster := resources[0].(*ECSCluster)
a.Equal("foobar", ecsCluster.String())
a.Equal("foobar", ecsCluster.Properties().Get("tag:Name"))
a.Equal("test", ecsCluster.Properties().Get("tag:aws-nuke"))
}
func Test_Mock_ECSCluster_Remove(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockECS := mock_ecsiface.NewMockECSAPI(ctrl)
ecsCluster := ECSCluster{
svc: mockECS,
ARN: ptr.String("foobar"),
}
a.Equal("foobar", ecsCluster.String())
mockECS.EXPECT().DeleteCluster(gomock.Eq(&ecs.DeleteClusterInput{
Cluster: aws.String("foobar"),
})).Return(&ecs.DeleteClusterOutput{}, nil)
err := ecsCluster.Remove(context.TODO())
a.Nil(err)
}