@@ -212,6 +212,59 @@ describe('run', () => {
212
212
) ;
213
213
expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
214
214
} ) ;
215
+
216
+ it ( 'saves with -1 cacheId , should not fail workflow' , async ( ) => {
217
+ inputs [ 'cache' ] = 'poetry' ;
218
+ getStateSpy . mockImplementation ( ( name : string ) => {
219
+ if ( name === State . STATE_CACHE_PRIMARY_KEY ) {
220
+ return poetryLockHash ;
221
+ } else if ( name === State . CACHE_PATHS ) {
222
+ return JSON . stringify ( [ __dirname ] ) ;
223
+ } else {
224
+ return requirementsHash ;
225
+ }
226
+ } ) ;
227
+
228
+ saveCacheSpy . mockImplementation ( ( ) => {
229
+ return - 1 ;
230
+ } ) ;
231
+
232
+ await run ( ) ;
233
+
234
+ expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
235
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
236
+ expect ( infoSpy ) . not . toHaveBeenCalled ( ) ;
237
+ expect ( saveCacheSpy ) . toHaveBeenCalled ( ) ;
238
+ expect ( infoSpy ) . not . toHaveBeenLastCalledWith (
239
+ `Cache saved with the key: ${ poetryLockHash } `
240
+ ) ;
241
+ expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
242
+ } ) ;
243
+
244
+ it ( 'saves with error from toolkit, should fail workflow' , async ( ) => {
245
+ inputs [ 'cache' ] = 'npm' ;
246
+ getStateSpy . mockImplementation ( ( name : string ) => {
247
+ if ( name === State . STATE_CACHE_PRIMARY_KEY ) {
248
+ return poetryLockHash ;
249
+ } else if ( name === State . CACHE_PATHS ) {
250
+ return JSON . stringify ( [ __dirname ] ) ;
251
+ } else {
252
+ return requirementsHash ;
253
+ }
254
+ } ) ;
255
+
256
+ saveCacheSpy . mockImplementation ( ( ) => {
257
+ throw new cache . ValidationError ( 'Validation failed' ) ;
258
+ } ) ;
259
+
260
+ await run ( ) ;
261
+
262
+ expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
263
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
264
+ expect ( infoSpy ) . not . toHaveBeenCalledWith ( ) ;
265
+ expect ( saveCacheSpy ) . toHaveBeenCalled ( ) ;
266
+ expect ( setFailedSpy ) . toHaveBeenCalled ( ) ;
267
+ } ) ;
215
268
} ) ;
216
269
217
270
afterEach ( ( ) => {
0 commit comments