@@ -5,6 +5,7 @@ package cloudformation
5
5
6
6
import (
7
7
"errors"
8
+ "fmt"
8
9
"io"
9
10
"strings"
10
11
"testing"
@@ -45,6 +46,25 @@ func testDeployWorkload_OnCreateChangeSetFailure(t *testing.T, when func(w progr
45
46
require .True (t , errors .Is (err , wantedErr ), `expected returned error to be wrapped with "some error"` )
46
47
}
47
48
49
+ func testDeployWorkload_ReturnNilOnEmptyChangeSetWhileUpdatingStack (t * testing.T , when func (w progress.FileWriter , cf CloudFormation ) error ) {
50
+ // GIVEN
51
+ ctrl := gomock .NewController (t )
52
+ defer ctrl .Finish ()
53
+ wantedErr := & cloudformation.ErrChangeSetEmpty {}
54
+ m := mocks .NewMockcfnClient (ctrl )
55
+ m .EXPECT ().Create (gomock .Any ()).Return ("" , & cloudformation.ErrStackAlreadyExists {})
56
+ m .EXPECT ().Update (gomock .Any ()).Return ("" , wantedErr )
57
+ m .EXPECT ().ErrorEvents (gomock .Any ()).Return (nil , nil )
58
+ client := CloudFormation {cfnClient : m }
59
+ buf := new (strings.Builder )
60
+
61
+ // WHEN
62
+ err := when (mockFileWriter {Writer : buf }, client )
63
+
64
+ // THEN
65
+ require .Nil (t , err , "should not fail if the changeset is empty" )
66
+ }
67
+
48
68
func testDeployWorkload_OnUpdateChangeSetFailure (t * testing.T , when func (w progress.FileWriter , cf CloudFormation ) error ) {
49
69
// GIVEN
50
70
ctrl := gomock .NewController (t )
@@ -119,7 +139,7 @@ func testDeployWorkload_StackStreamerFailureShouldCancelRenderer(t *testing.T, w
119
139
require .True (t , errors .Is (err , wantedErr ), "expected streamer error to be wrapped and returned" )
120
140
}
121
141
122
- func testDeployWorkload_StreamUntilStackCreationFails (t * testing.T , when func (w progress.FileWriter , cf CloudFormation ) error ) {
142
+ func testDeployWorkload_StreamUntilStackCreationFails (t * testing.T , stackName string , when func (w progress.FileWriter , cf CloudFormation ) error ) {
123
143
// GIVEN
124
144
ctrl := gomock .NewController (t )
125
145
defer ctrl .Finish ()
@@ -131,14 +151,14 @@ func testDeployWorkload_StreamUntilStackCreationFails(t *testing.T, when func(w
131
151
StackEvents : []* sdkcloudformation.StackEvent {
132
152
{
133
153
EventId : aws .String ("2" ),
134
- LogicalResourceId : aws .String ("hello" ),
154
+ LogicalResourceId : aws .String (stackName ),
135
155
PhysicalResourceId : aws .String ("AWS::CloudFormation::Stack" ),
136
156
ResourceStatus : aws .String ("CREATE_FAILED" ), // Send failure event for stack.
137
157
Timestamp : aws .Time (time .Now ()),
138
158
},
139
159
},
140
160
}, nil ).AnyTimes ()
141
- m .EXPECT ().Describe ("hello" ).Return (& cloudformation.StackDescription {
161
+ m .EXPECT ().Describe (stackName ).Return (& cloudformation.StackDescription {
142
162
StackStatus : aws .String ("CREATE_FAILED" ),
143
163
}, nil )
144
164
client := CloudFormation {cfnClient : m }
@@ -148,10 +168,10 @@ func testDeployWorkload_StreamUntilStackCreationFails(t *testing.T, when func(w
148
168
err := when (mockFileWriter {Writer : buf }, client )
149
169
150
170
// THEN
151
- require .EqualError (t , err , "stack hello did not complete successfully and exited with status CREATE_FAILED" )
171
+ require .EqualError (t , err , fmt . Sprintf ( "stack %s did not complete successfully and exited with status CREATE_FAILED" , stackName ) )
152
172
}
153
173
154
- func testDeployWorkload_RenderNewlyCreatedStackWithECSService (t * testing.T , when func (w progress.FileWriter , cf CloudFormation ) error ) {
174
+ func testDeployWorkload_RenderNewlyCreatedStackWithECSService (t * testing.T , stackName string , when func (w progress.FileWriter , cf CloudFormation ) error ) {
155
175
// GIVEN
156
176
ctrl := gomock .NewController (t )
157
177
defer ctrl .Finish ()
@@ -160,7 +180,7 @@ func testDeployWorkload_RenderNewlyCreatedStackWithECSService(t *testing.T, when
160
180
deploymentTime := time .Date (2020 , time .November , 23 , 18 , 0 , 0 , 0 , time .UTC )
161
181
162
182
mockCFN .EXPECT ().Create (gomock .Any ()).Return ("1234" , nil )
163
- mockCFN .EXPECT ().DescribeChangeSet ("1234" , "hello" ).Return (& cloudformation.ChangeSetDescription {
183
+ mockCFN .EXPECT ().DescribeChangeSet ("1234" , stackName ).Return (& cloudformation.ChangeSetDescription {
164
184
Changes : []* sdkcloudformation.Change {
165
185
{
166
186
ResourceChange : & sdkcloudformation.ResourceChange {
@@ -170,15 +190,15 @@ func testDeployWorkload_RenderNewlyCreatedStackWithECSService(t *testing.T, when
170
190
},
171
191
},
172
192
}, nil )
173
- mockCFN .EXPECT ().TemplateBodyFromChangeSet ("1234" , "hello" ).Return (`
193
+ mockCFN .EXPECT ().TemplateBodyFromChangeSet ("1234" , stackName ).Return (`
174
194
Resources:
175
195
Service:
176
196
Metadata:
177
197
'aws:copilot:description': 'My ECS Service'
178
198
Type: AWS::ECS::Service
179
199
` , nil )
180
200
mockCFN .EXPECT ().DescribeStackEvents (& sdkcloudformation.DescribeStackEventsInput {
181
- StackName : aws .String ("hello" ),
201
+ StackName : aws .String (stackName ),
182
202
}).Return (& sdkcloudformation.DescribeStackEventsOutput {
183
203
StackEvents : []* sdkcloudformation.StackEvent {
184
204
{
@@ -199,7 +219,7 @@ Resources:
199
219
},
200
220
{
201
221
EventId : aws .String ("3" ),
202
- LogicalResourceId : aws .String ("hello" ),
222
+ LogicalResourceId : aws .String (stackName ),
203
223
ResourceType : aws .String ("AWS::CloudFormation::Stack" ),
204
224
ResourceStatus : aws .String ("CREATE_COMPLETE" ),
205
225
Timestamp : aws .Time (deploymentTime ),
@@ -216,7 +236,7 @@ Resources:
216
236
},
217
237
},
218
238
}, nil )
219
- mockCFN .EXPECT ().Describe ("hello" ).Return (& cloudformation.StackDescription {
239
+ mockCFN .EXPECT ().Describe (stackName ).Return (& cloudformation.StackDescription {
220
240
StackStatus : aws .String ("CREATE_COMPLETE" ),
221
241
}, nil )
222
242
client := CloudFormation {cfnClient : mockCFN , ecsClient : mockECS }
@@ -232,14 +252,14 @@ Resources:
232
252
require .Contains (t , buf .String (), "[completed]" , "Rollout state of service should be rendered" )
233
253
}
234
254
235
- func testDeployWorkload_RenderNewlyCreatedStackWithAddons (t * testing.T , when func (w progress.FileWriter , cf CloudFormation ) error ) {
255
+ func testDeployWorkload_RenderNewlyCreatedStackWithAddons (t * testing.T , stackName string , when func (w progress.FileWriter , cf CloudFormation ) error ) {
236
256
ctrl := gomock .NewController (t )
237
257
defer ctrl .Finish ()
238
258
m := mocks .NewMockcfnClient (ctrl )
239
259
240
260
// Mocks for the parent stack.
241
261
m .EXPECT ().Create (gomock .Any ()).Return ("1234" , nil )
242
- m .EXPECT ().DescribeChangeSet ("1234" , "hello" ).Return (& cloudformation.ChangeSetDescription {
262
+ m .EXPECT ().DescribeChangeSet ("1234" , stackName ).Return (& cloudformation.ChangeSetDescription {
243
263
Changes : []* sdkcloudformation.Change {
244
264
{
245
265
ResourceChange : & sdkcloudformation.ResourceChange {
@@ -257,7 +277,7 @@ func testDeployWorkload_RenderNewlyCreatedStackWithAddons(t *testing.T, when fun
257
277
},
258
278
}, nil )
259
279
260
- m .EXPECT ().TemplateBodyFromChangeSet ("1234" , "hello" ).Return (`
280
+ m .EXPECT ().TemplateBodyFromChangeSet ("1234" , stackName ).Return (`
261
281
Resources:
262
282
Cluster:
263
283
Metadata:
@@ -270,7 +290,7 @@ Resources:
270
290
` , nil )
271
291
272
292
m .EXPECT ().DescribeStackEvents (& sdkcloudformation.DescribeStackEventsInput {
273
- StackName : aws .String ("hello" ),
293
+ StackName : aws .String (stackName ),
274
294
}).Return (& sdkcloudformation.DescribeStackEventsOutput {
275
295
StackEvents : []* sdkcloudformation.StackEvent {
276
296
{
@@ -289,15 +309,15 @@ Resources:
289
309
},
290
310
{
291
311
EventId : aws .String ("3" ),
292
- LogicalResourceId : aws .String ("hello" ),
312
+ LogicalResourceId : aws .String (stackName ),
293
313
PhysicalResourceId : aws .String ("AWS::CloudFormation::Stack" ),
294
314
ResourceStatus : aws .String ("CREATE_COMPLETE" ),
295
315
Timestamp : aws .Time (time .Now ()),
296
316
},
297
317
},
298
318
}, nil ).AnyTimes ()
299
319
300
- m .EXPECT ().Describe ("hello" ).Return (& cloudformation.StackDescription {
320
+ m .EXPECT ().Describe (stackName ).Return (& cloudformation.StackDescription {
301
321
StackStatus : aws .String ("CREATE_COMPLETE" ),
302
322
}, nil )
303
323
0 commit comments