@@ -72,6 +72,18 @@ const getIamRoleSucceeds = {
72
72
}
73
73
}
74
74
75
+ const waitForSucceeds = {
76
+ promise : function ( ) {
77
+ return { }
78
+ }
79
+ }
80
+
81
+ const waitForFails = {
82
+ promise : function ( ) {
83
+ throw new Error ( 'waited too long' )
84
+ }
85
+ }
86
+
75
87
describe ( 'Lambda Deploy Function' , ( ) => {
76
88
// TODO https://github.com/aws/aws-vsts-tools/issues/167
77
89
beforeAll ( ( ) => {
@@ -120,47 +132,124 @@ describe('Lambda Deploy Function', () => {
120
132
} )
121
133
122
134
test ( 'Deploy only Function exists calls update' , async ( ) => {
123
- expect . assertions ( 2 )
135
+ expect . assertions ( 3 )
124
136
const taskParameters = { ...baseTaskParameters }
125
137
taskParameters . deploymentMode = deployCodeOnly
126
138
taskParameters . roleARN = 'arn:yes'
127
139
const lambda = new Lambda ( ) as any
128
140
lambda . getFunction = jest . fn ( ( ) => getFunctionSucceeds )
129
141
lambda . updateFunctionCode = jest . fn ( ( ) => updateFunctionSucceeds )
142
+ lambda . waitFor = jest . fn ( ( ) => waitForSucceeds )
130
143
const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
131
144
await taskOperations . execute ( )
132
145
expect ( lambda . getFunction ) . toBeCalledTimes ( 1 )
133
146
expect ( lambda . updateFunctionCode ) . toBeCalledTimes ( 1 )
147
+ expect ( lambda . waitFor ) . toBeCalledTimes ( 1 )
148
+ } )
149
+
150
+ test ( 'Deploy only Function exists calls update but fails if status does not update' , async ( ) => {
151
+ expect . assertions ( 4 )
152
+ const taskParameters = { ...baseTaskParameters }
153
+ taskParameters . deploymentMode = deployCodeOnly
154
+ taskParameters . roleARN = 'arn:yes'
155
+ const lambda = new Lambda ( ) as any
156
+ lambda . getFunction = jest . fn ( ( ) => getFunctionSucceeds )
157
+ lambda . updateFunctionCode = jest . fn ( ( ) => updateFunctionSucceeds )
158
+ lambda . waitFor = jest . fn ( ( ) => waitForFails )
159
+ const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
160
+ await taskOperations . execute ( ) . catch ( e => expect ( `${ e } ` ) . toContain ( 'waited too long' ) )
161
+ expect ( lambda . getFunction ) . toBeCalledTimes ( 1 )
162
+ expect ( lambda . updateFunctionCode ) . toBeCalledTimes ( 1 )
163
+ expect ( lambda . waitFor ) . toBeCalledTimes ( 1 )
134
164
} )
135
165
136
166
test ( 'Deploy and config does not exist calls create' , async ( ) => {
137
- expect . assertions ( 2 )
167
+ expect . assertions ( 3 )
138
168
const taskParameters = { ...baseTaskParameters }
139
169
taskParameters . deploymentMode = deployCodeAndConfig
140
170
taskParameters . roleARN = 'arn:yes'
141
171
const lambda = new Lambda ( ) as any
142
172
lambda . getFunction = jest . fn ( ( ) => getFunctionFails )
143
173
lambda . createFunction = jest . fn ( ( ) => updateFunctionSucceeds )
174
+ lambda . waitFor = jest . fn ( ( ) => waitForSucceeds )
144
175
const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
145
176
await taskOperations . execute ( )
146
177
expect ( lambda . getFunction ) . toBeCalledTimes ( 1 )
147
178
expect ( lambda . createFunction ) . toBeCalledTimes ( 1 )
179
+ expect ( lambda . waitFor ) . toBeCalledTimes ( 1 )
180
+ } )
181
+
182
+ test ( 'Deploy and config does not exist calls create but fails if status does not update' , async ( ) => {
183
+ expect . assertions ( 4 )
184
+ const taskParameters = { ...baseTaskParameters }
185
+ taskParameters . deploymentMode = deployCodeAndConfig
186
+ taskParameters . roleARN = 'arn:yes'
187
+ const lambda = new Lambda ( ) as any
188
+ lambda . getFunction = jest . fn ( ( ) => getFunctionFails )
189
+ lambda . createFunction = jest . fn ( ( ) => updateFunctionSucceeds )
190
+ lambda . waitFor = jest . fn ( ( ) => waitForFails )
191
+ const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
192
+ await taskOperations . execute ( ) . catch ( e => expect ( `${ e } ` ) . toContain ( 'waited too long' ) )
193
+ expect ( lambda . getFunction ) . toBeCalledTimes ( 1 )
194
+ expect ( lambda . createFunction ) . toBeCalledTimes ( 1 )
195
+ expect ( lambda . waitFor ) . toBeCalledTimes ( 1 )
148
196
} )
149
197
150
198
test ( 'Deploy and config exists calls update' , async ( ) => {
151
- expect . assertions ( 3 )
199
+ expect . assertions ( 4 )
152
200
const taskParameters = { ...baseTaskParameters }
153
201
taskParameters . deploymentMode = deployCodeAndConfig
154
202
taskParameters . roleARN = 'arn:yes'
155
203
const lambda = new Lambda ( ) as any
156
204
lambda . getFunction = jest . fn ( ( ) => getFunctionSucceeds )
157
205
lambda . updateFunctionCode = jest . fn ( ( ) => updateFunctionSucceeds )
158
206
lambda . updateFunctionConfiguration = jest . fn ( ( ) => updateFunctionSucceeds )
207
+ lambda . waitFor = jest . fn ( ( ) => waitForSucceeds )
159
208
const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
160
209
await taskOperations . execute ( )
161
210
expect ( lambda . getFunction ) . toBeCalledTimes ( 1 )
162
211
expect ( lambda . updateFunctionCode ) . toBeCalledTimes ( 1 )
163
212
expect ( lambda . updateFunctionConfiguration ) . toBeCalledTimes ( 1 )
213
+ expect ( lambda . waitFor ) . toBeCalledTimes ( 2 )
214
+ } )
215
+
216
+ test ( 'Deploy and config exists calls update but fails if status does not update after config update' , async ( ) => {
217
+ expect . assertions ( 5 )
218
+ const taskParameters = { ...baseTaskParameters }
219
+ taskParameters . deploymentMode = deployCodeAndConfig
220
+ taskParameters . roleARN = 'arn:yes'
221
+ const lambda = new Lambda ( ) as any
222
+ lambda . getFunction = jest . fn ( ( ) => getFunctionSucceeds )
223
+ lambda . updateFunctionCode = jest . fn ( ( ) => updateFunctionSucceeds )
224
+ lambda . updateFunctionConfiguration = jest . fn ( ( ) => updateFunctionSucceeds )
225
+ lambda . waitFor = jest . fn ( ( ) => waitForFails )
226
+ const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
227
+ await taskOperations . execute ( ) . catch ( e => expect ( `${ e } ` ) . toContain ( 'waited too long' ) )
228
+ expect ( lambda . getFunction ) . toBeCalledTimes ( 1 )
229
+ expect ( lambda . updateFunctionCode ) . toBeCalledTimes ( 0 )
230
+ expect ( lambda . updateFunctionConfiguration ) . toBeCalledTimes ( 1 )
231
+ expect ( lambda . waitFor ) . toBeCalledTimes ( 1 )
232
+ } )
233
+
234
+ test ( 'Deploy and config exists calls update but fails if status does not update after code update' , async ( ) => {
235
+ expect . assertions ( 5 )
236
+ const taskParameters = { ...baseTaskParameters }
237
+ taskParameters . deploymentMode = deployCodeAndConfig
238
+ taskParameters . roleARN = 'arn:yes'
239
+ const lambda = new Lambda ( ) as any
240
+ lambda . getFunction = jest . fn ( ( ) => getFunctionSucceeds )
241
+ lambda . updateFunctionCode = jest . fn ( ( ) => updateFunctionSucceeds )
242
+ lambda . updateFunctionConfiguration = jest . fn ( ( ) => updateFunctionSucceeds )
243
+ lambda . waitFor = jest
244
+ . fn ( )
245
+ . mockReturnValueOnce ( waitForSucceeds )
246
+ . mockReturnValueOnce ( waitForFails )
247
+ const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
248
+ await taskOperations . execute ( ) . catch ( e => expect ( `${ e } ` ) . toContain ( 'waited too long' ) )
249
+ expect ( lambda . getFunction ) . toBeCalledTimes ( 1 )
250
+ expect ( lambda . updateFunctionCode ) . toBeCalledTimes ( 1 )
251
+ expect ( lambda . updateFunctionConfiguration ) . toBeCalledTimes ( 1 )
252
+ expect ( lambda . waitFor ) . toBeCalledTimes ( 2 )
164
253
} )
165
254
166
255
test ( 'Create function adds fields if they exist' , async ( ) => {
@@ -184,6 +273,7 @@ describe('Lambda Deploy Function', () => {
184
273
185
274
return updateFunctionSucceeds
186
275
} )
276
+ lambda . waitFor = jest . fn ( ( ) => waitForSucceeds )
187
277
const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
188
278
await taskOperations . execute ( )
189
279
} )
@@ -207,6 +297,7 @@ describe('Lambda Deploy Function', () => {
207
297
208
298
return updateFunctionSucceeds
209
299
} )
300
+ lambda . waitFor = jest . fn ( ( ) => waitForSucceeds )
210
301
lambda . tagResource = jest . fn ( args => {
211
302
expect ( args . Tags ) . toStrictEqual ( { tag1 : '5' , tag : 'abc' } )
212
303
@@ -227,6 +318,7 @@ describe('Lambda Deploy Function', () => {
227
318
lambda . getFunction = jest . fn ( ( ) => getFunctionSucceeds )
228
319
lambda . updateFunctionCode = jest . fn ( ( ) => updateFunctionSucceeds )
229
320
lambda . updateFunctionConfiguration = jest . fn ( ( ) => updateFunctionSucceeds )
321
+ lambda . waitFor = jest . fn ( ( ) => waitForSucceeds )
230
322
const tagResourceFunction = jest . fn ( )
231
323
lambda . tagResource = tagResourceFunction
232
324
const taskOperations = new TaskOperations ( new IAM ( ) , lambda , taskParameters )
0 commit comments