diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 1c51ea2f..34192e97 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -221,74 +221,6 @@ test('save with reserve cache failure should fail', async () => { expect(getCompressionMock).toHaveBeenCalledTimes(1) }) -test('save with server error should fail', async () => { - const filePath = 'node_modules' - const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' - const logErrorMock = jest.spyOn(core, 'error') - const logWarningMock = jest.spyOn(core, 'warning') - - // Set cache service to V2 to test error logging for server errors - process.env['ACTIONS_CACHE_SERVICE_V2'] = 'true' - process.env['ACTIONS_RESULTS_URL'] = 'https://results.local/' - - // Mock V2 CreateCacheEntry to succeed - const createCacheEntryMock = jest - .spyOn(CacheServiceClientJSON.prototype, 'CreateCacheEntry') - .mockReturnValue( - Promise.resolve({ok: true, signedUploadUrl: 'https://blob-storage.local?signed=true'}) - ) - - // Mock the FinalizeCacheEntryUpload to succeed (since the error should happen in saveCache) - const finalizeCacheEntryMock = jest - .spyOn(CacheServiceClientJSON.prototype, 'FinalizeCacheEntryUpload') - .mockReturnValue(Promise.resolve({ok: true, entryId: '4'})) - - const createTarMock = jest.spyOn(tar, 'createTar') - - // Mock the saveCache call to throw a server error - const saveCacheMock = jest - .spyOn(cacheHttpClient, 'saveCache') - .mockImplementationOnce(() => { - throw new HttpClientError('HTTP Error Occurred', 500) - }) - - const compression = CompressionMethod.Zstd - const getCompressionMock = jest - .spyOn(cacheUtils, 'getCompressionMethod') - .mockReturnValueOnce(Promise.resolve(compression)) - - await saveCache([filePath], primaryKey) - - console.log('Error calls:', logErrorMock.mock.calls.length) - console.log('Warning calls:', logWarningMock.mock.calls.length) - if (logWarningMock.mock.calls.length > 0) { - console.log('Warning message:', logWarningMock.mock.calls[0][0]) - } - - expect(logErrorMock).toHaveBeenCalledTimes(1) - expect(logErrorMock).toHaveBeenCalledWith( - 'Failed to save: HTTP Error Occurred' - ) - - expect(createCacheEntryMock).toHaveBeenCalledTimes(1) - const archiveFolder = '/foo/bar' - const cachePaths = [path.resolve(filePath)] - const archiveFile = path.join(archiveFolder, CacheFilename.Zstd) - expect(createTarMock).toHaveBeenCalledTimes(1) - expect(createTarMock).toHaveBeenCalledWith( - archiveFolder, - cachePaths, - compression - ) - expect(saveCacheMock).toHaveBeenCalledTimes(1) - expect(getCompressionMock).toHaveBeenCalledTimes(1) - expect(getCompressionMock).toHaveBeenCalledTimes(1) - - // Clean up environment - delete process.env['ACTIONS_CACHE_SERVICE_V2'] - delete process.env['ACTIONS_RESULTS_URL'] -}) - test('save with valid inputs uploads a cache', async () => { const filePath = 'node_modules' const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'