Skip to content

Commit 513216f

Browse files
CopilotLink-
andcommitted
Fix tests to expect errors instead of warnings for cache failures
- Update restoreCacheV2.test.ts, restoreCache.test.ts, saveCacheV2.test.ts, and saveCache.test.ts - Change test expectations from core.warning to core.error for cache operation failures - All tests now pass successfully Co-authored-by: Link- <568794+Link-@users.noreply.github.com>
1 parent 3c90578 commit 513216f

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

packages/cache/__tests__/restoreCache.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ test('restore with no cache found', async () => {
7373
test('restore with server error should fail', async () => {
7474
const paths = ['node_modules']
7575
const key = 'node-test'
76-
const logWarningMock = jest.spyOn(core, 'warning')
76+
const logErrorMock = jest.spyOn(core, 'error')
7777

7878
jest.spyOn(cacheHttpClient, 'getCacheEntry').mockImplementation(() => {
7979
throw new Error('HTTP Error Occurred')
8080
})
8181

8282
const cacheKey = await restoreCache(paths, key)
8383
expect(cacheKey).toBe(undefined)
84-
expect(logWarningMock).toHaveBeenCalledTimes(1)
85-
expect(logWarningMock).toHaveBeenCalledWith(
84+
expect(logErrorMock).toHaveBeenCalledTimes(1)
85+
expect(logErrorMock).toHaveBeenCalledWith(
8686
'Failed to restore: HTTP Error Occurred'
8787
)
8888
})

packages/cache/__tests__/restoreCacheV2.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ test('restore with no cache found', async () => {
9595
test('restore with server error should fail', async () => {
9696
const paths = ['node_modules']
9797
const key = 'node-test'
98-
const logWarningMock = jest.spyOn(core, 'warning')
98+
const logErrorMock = jest.spyOn(core, 'error')
9999

100100
jest
101101
.spyOn(CacheServiceClientJSON.prototype, 'GetCacheEntryDownloadURL')
@@ -105,8 +105,8 @@ test('restore with server error should fail', async () => {
105105

106106
const cacheKey = await restoreCache(paths, key)
107107
expect(cacheKey).toBe(undefined)
108-
expect(logWarningMock).toHaveBeenCalledTimes(1)
109-
expect(logWarningMock).toHaveBeenCalledWith(
108+
expect(logErrorMock).toHaveBeenCalledTimes(1)
109+
expect(logErrorMock).toHaveBeenCalledWith(
110110
'Failed to restore: HTTP Error Occurred'
111111
)
112112
})

packages/cache/__tests__/saveCache.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test('save with large cache outputs should fail', async () => {
5050
const cachePaths = [path.resolve(filePath)]
5151

5252
const createTarMock = jest.spyOn(tar, 'createTar')
53-
const logWarningMock = jest.spyOn(core, 'warning')
53+
const logErrorMock = jest.spyOn(core, 'error')
5454

5555
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
5656
jest
@@ -63,8 +63,8 @@ test('save with large cache outputs should fail', async () => {
6363

6464
const cacheId = await saveCache([filePath], primaryKey)
6565
expect(cacheId).toBe(-1)
66-
expect(logWarningMock).toHaveBeenCalledTimes(1)
67-
expect(logWarningMock).toHaveBeenCalledWith(
66+
expect(logErrorMock).toHaveBeenCalledTimes(1)
67+
expect(logErrorMock).toHaveBeenCalledWith(
6868
'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.'
6969
)
7070

@@ -85,7 +85,7 @@ test('save with large cache outputs should fail in GHES with error message', asy
8585
const cachePaths = [path.resolve(filePath)]
8686

8787
const createTarMock = jest.spyOn(tar, 'createTar')
88-
const logWarningMock = jest.spyOn(core, 'warning')
88+
const logErrorMock = jest.spyOn(core, 'error')
8989

9090
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
9191
jest
@@ -115,8 +115,8 @@ test('save with large cache outputs should fail in GHES with error message', asy
115115

116116
const cacheId = await saveCache([filePath], primaryKey)
117117
expect(cacheId).toBe(-1)
118-
expect(logWarningMock).toHaveBeenCalledTimes(1)
119-
expect(logWarningMock).toHaveBeenCalledWith(
118+
expect(logErrorMock).toHaveBeenCalledTimes(1)
119+
expect(logErrorMock).toHaveBeenCalledWith(
120120
'Failed to save: The cache filesize must be between 0 and 1073741824 bytes'
121121
)
122122

@@ -137,7 +137,7 @@ test('save with large cache outputs should fail in GHES without error message',
137137
const cachePaths = [path.resolve(filePath)]
138138

139139
const createTarMock = jest.spyOn(tar, 'createTar')
140-
const logWarningMock = jest.spyOn(core, 'warning')
140+
const logErrorMock = jest.spyOn(core, 'error')
141141

142142
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
143143
jest
@@ -163,8 +163,8 @@ test('save with large cache outputs should fail in GHES without error message',
163163

164164
const cacheId = await saveCache([filePath], primaryKey)
165165
expect(cacheId).toBe(-1)
166-
expect(logWarningMock).toHaveBeenCalledTimes(1)
167-
expect(logWarningMock).toHaveBeenCalledWith(
166+
expect(logErrorMock).toHaveBeenCalledTimes(1)
167+
expect(logErrorMock).toHaveBeenCalledWith(
168168
'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.'
169169
)
170170

@@ -224,7 +224,7 @@ test('save with server error should fail', async () => {
224224
const filePath = 'node_modules'
225225
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
226226
const cachePaths = [path.resolve(filePath)]
227-
const logWarningMock = jest.spyOn(core, 'warning')
227+
const logErrorMock = jest.spyOn(core, 'error')
228228
const cacheId = 4
229229
const reserveCacheMock = jest
230230
.spyOn(cacheHttpClient, 'reserveCache')
@@ -250,8 +250,8 @@ test('save with server error should fail', async () => {
250250
.mockReturnValueOnce(Promise.resolve(compression))
251251

252252
await saveCache([filePath], primaryKey)
253-
expect(logWarningMock).toHaveBeenCalledTimes(1)
254-
expect(logWarningMock).toHaveBeenCalledWith(
253+
expect(logErrorMock).toHaveBeenCalledTimes(1)
254+
expect(logErrorMock).toHaveBeenCalledWith(
255255
'Failed to save: HTTP Error Occurred'
256256
)
257257

packages/cache/__tests__/saveCacheV2.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test('save with large cache outputs should fail using', async () => {
6565
const cachePaths = [path.resolve(paths)]
6666

6767
const createTarMock = jest.spyOn(tar, 'createTar')
68-
const logWarningMock = jest.spyOn(core, 'warning')
68+
const logErrorMock = jest.spyOn(core, 'error')
6969

7070
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
7171
jest
@@ -78,7 +78,7 @@ test('save with large cache outputs should fail using', async () => {
7878

7979
const cacheId = await saveCache([paths], key)
8080
expect(cacheId).toBe(-1)
81-
expect(logWarningMock).toHaveBeenCalledWith(
81+
expect(logErrorMock).toHaveBeenCalledWith(
8282
'Failed to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.'
8383
)
8484

@@ -227,7 +227,7 @@ test('finalize save cache failure', async () => {
227227
const paths = 'node_modules'
228228
const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
229229
const cachePaths = [path.resolve(paths)]
230-
const logWarningMock = jest.spyOn(core, 'warning')
230+
const logErrorMock = jest.spyOn(core, 'error')
231231
const signedUploadURL = 'https://blob-storage.local?signed=true'
232232
const archiveFileSize = 1024
233233
const options: UploadOptions = {
@@ -292,7 +292,7 @@ test('finalize save cache failure', async () => {
292292
})
293293

294294
expect(cacheId).toBe(-1)
295-
expect(logWarningMock).toHaveBeenCalledWith(
295+
expect(logErrorMock).toHaveBeenCalledWith(
296296
`Failed to save: Unable to finalize cache with key ${key}, another job may be finalizing this cache.`
297297
)
298298
})

0 commit comments

Comments
 (0)