@@ -52,54 +52,14 @@ func TestBackendService_Template(t *testing.T) {
52
52
wantedTemplate string
53
53
wantedErr error
54
54
}{
55
- "unavailable rule priority lambda template" : {
56
- mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
57
- m := mocks .NewMockbackendSvcReadParser (ctrl )
58
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (nil , errors .New ("some error" ))
59
- svc .parser = m
60
- },
61
- wantedTemplate : "" ,
62
- wantedErr : fmt .Errorf ("read rule priority lambda: some error" ),
63
- },
64
- "unavailable desired count lambda template" : {
65
- mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
66
- m := mocks .NewMockbackendSvcReadParser (ctrl )
67
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
68
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (nil , errors .New ("some error" ))
69
- svc .parser = m
70
- },
71
- wantedTemplate : "" ,
72
- wantedErr : fmt .Errorf ("read desired count lambda: some error" ),
73
- },
74
- "unavailable env controller lambda template" : {
75
- mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
76
- m := mocks .NewMockbackendSvcReadParser (ctrl )
77
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
78
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
79
- m .EXPECT ().Read (envControllerPath ).Return (nil , errors .New ("some error" ))
80
- svc .parser = m
81
- },
82
- wantedTemplate : "" ,
83
- wantedErr : fmt .Errorf ("read env controller lambda: some error" ),
84
- },
85
55
"unexpected addons parsing error" : {
86
56
mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
87
- m := mocks .NewMockbackendSvcReadParser (ctrl )
88
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
89
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
90
- m .EXPECT ().Read (envControllerPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
91
- svc .parser = m
92
57
svc .addons = mockAddons {tplErr : errors .New ("some error" )}
93
58
},
94
59
wantedErr : fmt .Errorf ("generate addons template for %s: %w" , testServiceName , errors .New ("some error" )),
95
60
},
96
61
"unexpected addons parameter parsing error" : {
97
62
mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
98
- m := mocks .NewMockbackendSvcReadParser (ctrl )
99
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
100
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
101
- m .EXPECT ().Read (envControllerPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
102
- svc .parser = m
103
63
svc .addons = mockAddons {paramsErr : errors .New ("some error" )}
104
64
},
105
65
wantedErr : fmt .Errorf ("parse addons parameters for %s: %w" , testServiceName , errors .New ("some error" )),
@@ -116,9 +76,6 @@ func TestBackendService_Template(t *testing.T) {
116
76
},
117
77
mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
118
78
m := mocks .NewMockbackendSvcReadParser (ctrl )
119
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
120
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
121
- m .EXPECT ().Read (envControllerPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
122
79
svc .parser = m
123
80
svc .addons = mockAddons {
124
81
tpl : `
@@ -145,9 +102,6 @@ Outputs:
145
102
},
146
103
mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
147
104
m := mocks .NewMockbackendSvcReadParser (ctrl )
148
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
149
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
150
- m .EXPECT ().Read (envControllerPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
151
105
svc .parser = m
152
106
svc .addons = mockAddons {
153
107
tpl : `
@@ -167,9 +121,6 @@ Outputs:
167
121
},
168
122
mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
169
123
m := mocks .NewMockbackendSvcReadParser (ctrl )
170
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
171
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
172
- m .EXPECT ().Read (envControllerPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
173
124
m .EXPECT ().ParseBackendService (gomock .Any ()).Return (nil , errors .New ("some error" ))
174
125
svc .parser = m
175
126
svc .addons = mockAddons {
@@ -215,9 +166,6 @@ Outputs:
215
166
},
216
167
mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
217
168
m := mocks .NewMockbackendSvcReadParser (ctrl )
218
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
219
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
220
- m .EXPECT ().Read (envControllerPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
221
169
m .EXPECT ().ParseBackendService (gomock .Any ()).DoAndReturn (func (actual template.WorkloadOpts ) (* template.Content , error ) {
222
170
require .Equal (t , template.WorkloadOpts {
223
171
AppName : "phonetool" ,
@@ -237,11 +185,17 @@ Outputs:
237
185
GracePeriod : aws .Int64 (manifest .DefaultHealthCheckGracePeriod ),
238
186
},
239
187
DeregistrationDelay : aws .Int64 (60 ), // defaults to 60
240
- CustomResources : make (map [string ]template.S3ObjectLocation ),
241
- RulePriorityLambda : "something" ,
242
- DesiredCountLambda : "something" ,
243
- EnvControllerLambda : "something" ,
244
- ExecuteCommand : & template.ExecuteCommandOpts {},
188
+ CustomResources : map [string ]template.S3ObjectLocation {
189
+ "EnvControllerFunction" : {
190
+ Bucket : "my-bucket" ,
191
+ Key : "sha1/envcontroller.zip" ,
192
+ },
193
+ "DynamicDesiredCountFunction" : {
194
+ Bucket : "my-bucket" ,
195
+ Key : "sha2/count.zip" ,
196
+ },
197
+ },
198
+ ExecuteCommand : & template.ExecuteCommandOpts {},
245
199
NestedStack : & template.WorkloadNestedStackOpts {
246
200
StackName : addon .StackName ,
247
201
VariableOutputs : []string {"MyTable" },
@@ -324,9 +278,6 @@ Outputs:
324
278
},
325
279
mockDependencies : func (t * testing.T , ctrl * gomock.Controller , svc * BackendService ) {
326
280
m := mocks .NewMockbackendSvcReadParser (ctrl )
327
- m .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
328
- m .EXPECT ().Read (desiredCountGeneratorPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
329
- m .EXPECT ().Read (envControllerPath ).Return (& template.Content {Buffer : bytes .NewBufferString ("something" )}, nil )
330
281
m .EXPECT ().ParseBackendService (gomock .Any ()).DoAndReturn (func (actual template.WorkloadOpts ) (* template.Content , error ) {
331
282
require .Equal (t , template.WorkloadOpts {
332
283
AppName : "phonetool" ,
@@ -353,11 +304,17 @@ Outputs:
353
304
HostedZoneAliases : make (template.AliasesForHostedZone ),
354
305
DeregistrationDelay : aws .Int64 (59 ),
355
306
AllowedSourceIps : []string {"10.0.1.0/24" },
356
- CustomResources : make (map [string ]template.S3ObjectLocation ),
357
- RulePriorityLambda : "something" ,
358
- DesiredCountLambda : "something" ,
359
- EnvControllerLambda : "something" ,
360
- ExecuteCommand : & template.ExecuteCommandOpts {},
307
+ CustomResources : map [string ]template.S3ObjectLocation {
308
+ "EnvControllerFunction" : {
309
+ Bucket : "my-bucket" ,
310
+ Key : "sha1/envcontroller.zip" ,
311
+ },
312
+ "DynamicDesiredCountFunction" : {
313
+ Bucket : "my-bucket" ,
314
+ Key : "sha2/count.zip" ,
315
+ },
316
+ },
317
+ ExecuteCommand : & template.ExecuteCommandOpts {},
361
318
NestedStack : & template.WorkloadNestedStackOpts {
362
319
StackName : addon .StackName ,
363
320
VariableOutputs : []string {"MyTable" },
@@ -409,6 +366,10 @@ Outputs:
409
366
RepoURL : testImageRepoURL ,
410
367
ImageTag : testImageTag ,
411
368
},
369
+ CustomResourcesURL : map [string ]string {
370
+ "EnvControllerFunction" : "https://my-bucket.s3.Region.amazonaws.com/sha1/envcontroller.zip" ,
371
+ "DynamicDesiredCountFunction" : "https://my-bucket.s3.Region.amazonaws.com/sha2/count.zip" ,
372
+ },
412
373
},
413
374
},
414
375
taskDefOverrideFunc : mockCloudFormationOverrideFunc ,
@@ -603,9 +564,6 @@ func TestBackendService_TemplateAndParamsGeneration(t *testing.T) {
603
564
// mock parser for lambda functions
604
565
realParser := serializer .parser
605
566
mockParser := mocks .NewMockbackendSvcReadParser (ctrl )
606
- mockParser .EXPECT ().Read (albRulePriorityGeneratorPath ).Return (templateContent ("albRulePriorityGenerator" ), nil )
607
- mockParser .EXPECT ().Read (desiredCountGeneratorPath ).Return (templateContent ("desiredCountGenerator" ), nil )
608
- mockParser .EXPECT ().Read (envControllerPath ).Return (templateContent ("envController" ), nil )
609
567
mockParser .EXPECT ().ParseBackendService (gomock .Any ()).DoAndReturn (func (data template.WorkloadOpts ) (* template.Content , error ) {
610
568
// pass call to real parser
611
569
return realParser .ParseBackendService (data )
@@ -647,9 +605,3 @@ func TestBackendService_TemplateAndParamsGeneration(t *testing.T) {
647
605
})
648
606
}
649
607
}
650
-
651
- func templateContent (str string ) * template.Content {
652
- return & template.Content {
653
- Buffer : bytes .NewBuffer ([]byte (str )),
654
- }
655
- }
0 commit comments