From e2f30c1450bce6700d8b3e58de46c61fd34d6699 Mon Sep 17 00:00:00 2001
From: Evgenii Korolevskii <e-korolevskii@github.com>
Date: Mon, 4 Jul 2022 22:48:10 +0200
Subject: [PATCH] test(cache): Add test for cachetool v 3.0

Not to fail workflow on cache service errors
---
 __tests__/cache.test.ts | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts
index 2b42a521..43eb913e 100644
--- a/__tests__/cache.test.ts
+++ b/__tests__/cache.test.ts
@@ -153,6 +153,27 @@ describe('dependency cache', () => {
       return expect(save('ant')).rejects.toThrowError('unknown package manager specified: ant');
     });
 
+    it('save with -1 cacheId , should not fail workflow', async () => {
+      spyCacheSave.mockImplementation(() => Promise.resolve(-1));
+      createStateForMissingBuildFile();
+
+      await save('maven');
+      expect(spyCacheSave).toBeCalled();
+      expect(spyWarning).not.toBeCalled();
+      expect(spyInfo).toBeCalled();
+      expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
+    });
+
+    it('saves with error from toolkit, should fail workflow', async () => {
+      spyCacheSave.mockImplementation(() =>
+        Promise.reject(new cache.ValidationError('Validation failed'))
+      );
+      createStateForMissingBuildFile();
+
+      expect.assertions(1);
+      await expect(save('maven')).rejects.toEqual(new cache.ValidationError('Validation failed'));
+    });
+
     describe('for maven', () => {
       it('uploads cache even if no pom.xml found', async () => {
         createStateForMissingBuildFile();