@@ -294,6 +294,63 @@ describe('run', () => {
294
294
) ;
295
295
expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
296
296
} ) ;
297
+
298
+ it ( 'save with -1 cacheId , should not fail workflow' , async ( ) => {
299
+ inputs [ 'cache' ] = 'npm' ;
300
+ getStateSpy . mockImplementation ( ( name : string ) => {
301
+ if ( name === State . CacheMatchedKey ) {
302
+ return npmFileHash ;
303
+ } else {
304
+ return yarnFileHash ;
305
+ }
306
+ } ) ;
307
+ getCommandOutputSpy . mockImplementationOnce ( ( ) => `${ commonPath } /npm` ) ;
308
+ saveCacheSpy . mockImplementation ( ( ) => {
309
+ return - 1 ;
310
+ } ) ;
311
+
312
+ await run ( ) ;
313
+
314
+ expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
315
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
316
+ expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
317
+ expect ( debugSpy ) . toHaveBeenCalledWith ( `npm path is ${ commonPath } /npm` ) ;
318
+ expect ( infoSpy ) . not . toHaveBeenCalledWith (
319
+ `Cache hit occurred on the primary key ${ npmFileHash } , not saving cache.`
320
+ ) ;
321
+ expect ( saveCacheSpy ) . toHaveBeenCalled ( ) ;
322
+ expect ( infoSpy ) . not . toHaveBeenLastCalledWith (
323
+ `Cache saved with the key: ${ yarnFileHash } `
324
+ ) ;
325
+ expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
326
+ } ) ;
327
+
328
+ it ( 'saves with error from toolkit, should fail workflow' , async ( ) => {
329
+ inputs [ 'cache' ] = 'npm' ;
330
+ getStateSpy . mockImplementation ( ( name : string ) => {
331
+ if ( name === State . CacheMatchedKey ) {
332
+ return npmFileHash ;
333
+ } else {
334
+ return yarnFileHash ;
335
+ }
336
+ } ) ;
337
+ getCommandOutputSpy . mockImplementationOnce ( ( ) => `${ commonPath } /npm` ) ;
338
+ saveCacheSpy . mockImplementation ( ( ) => {
339
+ throw new cache . ValidationError ( 'Validation failed' ) ;
340
+ } ) ;
341
+
342
+ await run ( ) ;
343
+
344
+ expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
345
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
346
+ expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
347
+ expect ( debugSpy ) . toHaveBeenCalledWith ( `npm path is ${ commonPath } /npm` ) ;
348
+ expect ( infoSpy ) . not . toHaveBeenCalledWith (
349
+ `Cache hit occurred on the primary key ${ npmFileHash } , not saving cache.`
350
+ ) ;
351
+ expect ( saveCacheSpy ) . toHaveBeenCalled ( ) ;
352
+ expect ( setFailedSpy ) . toHaveBeenCalled ( ) ;
353
+ } ) ;
297
354
} ) ;
298
355
299
356
afterEach ( ( ) => {
0 commit comments