@@ -34,14 +34,7 @@ import (
34
34
)
35
35
36
36
var (
37
- bp = infrav1.BuildParams {
38
- Lifecycle : infrav1 .ResourceLifecycleOwned ,
39
- ClusterName : "testcluster" ,
40
- Name : aws .String ("test" ),
41
- Role : aws .String ("testrole" ),
42
- Additional : map [string ]string {"k1" : "v1" },
43
- }
44
- tags = []* ec2.Tag {
37
+ expectedTags = []* ec2.Tag {
45
38
{
46
39
Key : aws .String ("Name" ),
47
40
Value : aws .String ("test" ),
@@ -140,30 +133,64 @@ func TestTagsEnsureWithEC2(t *testing.T) {
140
133
expect func (m * mocks.MockEC2APIMockRecorder )
141
134
}{
142
135
{
143
- name : "Should return error when create tag fails" ,
144
- builder : Builder {params : & bp },
136
+ name : "Should return error when create tag fails" ,
137
+ builder : Builder {params : & infrav1.BuildParams {
138
+ Lifecycle : infrav1 .ResourceLifecycleOwned ,
139
+ ClusterName : "testcluster" ,
140
+ Name : aws .String ("test" ),
141
+ Role : aws .String ("testrole" ),
142
+ Additional : map [string ]string {"k1" : "v1" },
143
+ }},
145
144
expect : func (m * mocks.MockEC2APIMockRecorder ) {
146
145
m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
147
146
Resources : aws .StringSlice ([]string {"" }),
148
- Tags : tags ,
147
+ Tags : expectedTags ,
149
148
})).Return (nil , errors .New ("failed to create tag" ))
150
149
},
151
150
},
152
151
{
153
- name : "Should return error when optional configuration for builder is nil" ,
154
- builder : Builder {params : & bp , applyFunc : nil },
152
+ name : "Should return error when optional configuration for builder is nil" ,
153
+ builder : Builder {params : & infrav1.BuildParams {
154
+ Lifecycle : infrav1 .ResourceLifecycleOwned ,
155
+ ClusterName : "testcluster" ,
156
+ Name : aws .String ("test" ),
157
+ Role : aws .String ("testrole" ),
158
+ Additional : map [string ]string {"k1" : "v1" },
159
+ }, applyFunc : nil },
155
160
},
156
161
{
157
162
name : "Should return error when build params is nil" ,
158
163
builder : Builder {params : nil },
159
164
},
160
165
{
161
- name : "Should ensure tags successfully" ,
162
- builder : Builder {params : & bp },
166
+ name : "Should ensure tags successfully" ,
167
+ builder : Builder {params : & infrav1.BuildParams {
168
+ Lifecycle : infrav1 .ResourceLifecycleOwned ,
169
+ ClusterName : "testcluster" ,
170
+ Name : aws .String ("test" ),
171
+ Role : aws .String ("testrole" ),
172
+ Additional : map [string ]string {"k1" : "v1" },
173
+ }},
174
+ expect : func (m * mocks.MockEC2APIMockRecorder ) {
175
+ m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
176
+ Resources : aws .StringSlice ([]string {"" }),
177
+ Tags : expectedTags ,
178
+ })).Return (nil , nil )
179
+ },
180
+ },
181
+ {
182
+ name : "Should filter internal aws tags" ,
183
+ builder : Builder {params : & infrav1.BuildParams {
184
+ Lifecycle : infrav1 .ResourceLifecycleOwned ,
185
+ ClusterName : "testcluster" ,
186
+ Name : aws .String ("test" ),
187
+ Role : aws .String ("testrole" ),
188
+ Additional : map [string ]string {"k1" : "v1" , "aws:cloudformation:stack-name" : "cloudformation-stack-name" },
189
+ }},
163
190
expect : func (m * mocks.MockEC2APIMockRecorder ) {
164
191
m .CreateTagsWithContext (context .TODO (), gomock .Eq (& ec2.CreateTagsInput {
165
192
Resources : aws .StringSlice ([]string {"" }),
166
- Tags : tags ,
193
+ Tags : expectedTags ,
167
194
})).Return (nil , nil )
168
195
},
169
196
},
@@ -198,8 +225,14 @@ func TestTagsEnsureWithEKS(t *testing.T) {
198
225
expect func (m * mock_eksiface.MockEKSAPIMockRecorder )
199
226
}{
200
227
{
201
- name : "Should return error when tag resources fails" ,
202
- builder : Builder {params : & bp },
228
+ name : "Should return error when tag resources fails" ,
229
+ builder : Builder {params : & infrav1.BuildParams {
230
+ Lifecycle : infrav1 .ResourceLifecycleOwned ,
231
+ ClusterName : "testcluster" ,
232
+ Name : aws .String ("test" ),
233
+ Role : aws .String ("testrole" ),
234
+ Additional : map [string ]string {"k1" : "v1" },
235
+ }},
203
236
expect : func (m * mock_eksiface.MockEKSAPIMockRecorder ) {
204
237
m .TagResource (gomock .Eq (& eks.TagResourceInput {
205
238
ResourceArn : aws .String ("" ),
@@ -208,8 +241,14 @@ func TestTagsEnsureWithEKS(t *testing.T) {
208
241
},
209
242
},
210
243
{
211
- name : "Should ensure tags successfully" ,
212
- builder : Builder {params : & bp },
244
+ name : "Should ensure tags successfully" ,
245
+ builder : Builder {params : & infrav1.BuildParams {
246
+ Lifecycle : infrav1 .ResourceLifecycleOwned ,
247
+ ClusterName : "testcluster" ,
248
+ Name : aws .String ("test" ),
249
+ Role : aws .String ("testrole" ),
250
+ Additional : map [string ]string {"k1" : "v1" },
251
+ }},
213
252
expect : func (m * mock_eksiface.MockEKSAPIMockRecorder ) {
214
253
m .TagResource (gomock .Eq (& eks.TagResourceInput {
215
254
ResourceArn : aws .String ("" ),
@@ -243,10 +282,16 @@ func TestTagsEnsureWithEKS(t *testing.T) {
243
282
244
283
func TestTagsBuildParamsToTagSpecification (t * testing.T ) {
245
284
g := NewWithT (t )
246
- tagSpec := BuildParamsToTagSpecification ("test-resource" , bp )
285
+ tagSpec := BuildParamsToTagSpecification ("test-resource" , infrav1.BuildParams {
286
+ Lifecycle : infrav1 .ResourceLifecycleOwned ,
287
+ ClusterName : "testcluster" ,
288
+ Name : aws .String ("test" ),
289
+ Role : aws .String ("testrole" ),
290
+ Additional : map [string ]string {"k1" : "v1" },
291
+ })
247
292
expectedTagSpec := & ec2.TagSpecification {
248
293
ResourceType : aws .String ("test-resource" ),
249
- Tags : tags ,
294
+ Tags : expectedTags ,
250
295
}
251
296
g .Expect (expectedTagSpec ).To (Equal (tagSpec ))
252
297
}
0 commit comments