forked from ekristen/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelasticache-subnetgroups_mock_test.go
117 lines (91 loc) · 3.31 KB
/
elasticache-subnetgroups_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package resources
import (
"context"
"testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elasticache"
"github.com/ekristen/aws-nuke/v3/mocks/mock_elasticacheiface"
)
func Test_Mock_ElastiCache_SubnetGroup_Remove(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl)
subnetGroup := ElasticacheSubnetGroup{
svc: mockElastiCache,
name: aws.String("foobar"),
}
mockElastiCache.EXPECT().DeleteCacheSubnetGroup(&elasticache.DeleteCacheSubnetGroupInput{
CacheSubnetGroupName: aws.String("foobar"),
}).Return(&elasticache.DeleteCacheSubnetGroupOutput{}, nil)
err := subnetGroup.Remove(context.TODO())
a.Nil(err)
a.Equal("foobar", *subnetGroup.name)
}
func Test_Mock_ElastiCache_SubnetGroup_List_NoTags(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl)
subnetGroupsLister := ElasticacheSubnetGroupLister{
mockSvc: mockElastiCache,
}
mockElastiCache.EXPECT().DescribeCacheSubnetGroups(gomock.Any()).Return(&elasticache.DescribeCacheSubnetGroupsOutput{
CacheSubnetGroups: []*elasticache.CacheSubnetGroup{
{
ARN: aws.String("arn:aws:elasticache:us-west-2:123456789012:subnet-group:foobar"),
CacheSubnetGroupName: aws.String("foobar"),
},
},
}, nil)
mockElastiCache.EXPECT().ListTagsForResource(&elasticache.ListTagsForResourceInput{
ResourceName: aws.String("arn:aws:elasticache:us-west-2:123456789012:subnet-group:foobar"),
}).Return(&elasticache.TagListMessage{}, nil)
resources, err := subnetGroupsLister.List(context.TODO(), testListerOpts)
a.Nil(err)
a.Len(resources, 1)
resource := resources[0].(*ElasticacheSubnetGroup)
a.Len(resource.Tags, 0)
a.Equal("foobar", resource.String())
}
func Test_Mock_ElastiCache_SubnetGroup_List_WithTags(t *testing.T) {
a := assert.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl)
subnetGroupsLister := ElasticacheSubnetGroupLister{
mockSvc: mockElastiCache,
}
mockElastiCache.EXPECT().DescribeCacheSubnetGroups(gomock.Any()).Return(&elasticache.DescribeCacheSubnetGroupsOutput{
CacheSubnetGroups: []*elasticache.CacheSubnetGroup{
{
ARN: aws.String("arn:aws:elasticache:us-west-2:123456789012:subnet-group:foobar"),
CacheSubnetGroupName: aws.String("foobar"),
},
},
}, nil)
mockElastiCache.EXPECT().ListTagsForResource(&elasticache.ListTagsForResourceInput{
ResourceName: aws.String("arn:aws:elasticache:us-west-2:123456789012:subnet-group:foobar"),
}).Return(&elasticache.TagListMessage{
TagList: []*elasticache.Tag{
{
Key: aws.String("Name"),
Value: aws.String("foobar"),
},
{
Key: aws.String("aws-nuke"),
Value: aws.String("test"),
},
},
}, nil)
resources, err := subnetGroupsLister.List(context.TODO(), testListerOpts)
a.Nil(err)
a.Len(resources, 1)
resource := resources[0].(*ElasticacheSubnetGroup)
a.Len(resource.Tags, 2)
a.Equal("foobar", resource.String())
a.Equal("foobar", resource.Properties().Get("tag:Name"))
a.Equal("test", resource.Properties().Get("tag:aws-nuke"))
}