This commit is contained in:
Salman Muin Kayser Chishti
2025-07-31 23:48:44 +01:00
parent 717b895584
commit ece2273b24
5 changed files with 113 additions and 46 deletions
+12 -8
View File
@@ -225,20 +225,25 @@ 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')
// Removing the unused variable logWarningMock
// Mock cache service version to V2
const getCacheServiceVersionMock = jest.spyOn(config, 'getCacheServiceVersion').mockReturnValue('v2')
const getCacheServiceVersionMock = jest
.spyOn(config, 'getCacheServiceVersion')
.mockReturnValue('v2')
// Mock V2 CreateCacheEntry to succeed
const createCacheEntryMock = jest
.spyOn(CacheServiceClientJSON.prototype, 'CreateCacheEntry')
.mockReturnValue(
Promise.resolve({ok: true, signedUploadUrl: 'https://blob-storage.local?signed=true'})
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
jest
.spyOn(CacheServiceClientJSON.prototype, 'FinalizeCacheEntryUpload')
.mockReturnValue(Promise.resolve({ok: true, entryId: '4'}))
@@ -257,7 +262,7 @@ test('save with server error should fail', async () => {
.mockReturnValueOnce(Promise.resolve(compression))
await saveCache([filePath], primaryKey)
expect(logErrorMock).toHaveBeenCalledTimes(1)
expect(logErrorMock).toHaveBeenCalledWith(
'Failed to save: HTTP Error Occurred'
@@ -266,7 +271,7 @@ test('save with server error should fail', async () => {
expect(createCacheEntryMock).toHaveBeenCalledTimes(1)
const archiveFolder = '/foo/bar'
const cachePaths = [path.resolve(filePath)]
const archiveFile = path.join(archiveFolder, CacheFilename.Zstd)
// Removing the unused variable archiveFile
expect(createTarMock).toHaveBeenCalledTimes(1)
expect(createTarMock).toHaveBeenCalledWith(
archiveFolder,
@@ -275,8 +280,7 @@ test('save with server error should fail', async () => {
)
expect(saveCacheMock).toHaveBeenCalledTimes(1)
expect(getCompressionMock).toHaveBeenCalledTimes(1)
expect(getCompressionMock).toHaveBeenCalledTimes(1)
// Restore the getCacheServiceVersion mock to its original state
getCacheServiceVersionMock.mockRestore()
})