mirror of https://github.com/actions/toolkit
Modified tests
parent
80a66f3298
commit
b602df7c05
|
@ -5,6 +5,8 @@ import * as cacheHttpClient from '../src/internal/cacheHttpClient'
|
|||
import * as cacheUtils from '../src/internal/cacheUtils'
|
||||
import {CacheFilename, CompressionMethod} from '../src/internal/constants'
|
||||
import * as tar from '../src/internal/tar'
|
||||
import {ITypedResponse} from '@actions/http-client/interfaces'
|
||||
import {ReserveCacheResponse} from '../src/internal/contracts'
|
||||
|
||||
jest.mock('../src/internal/cacheHttpClient')
|
||||
jest.mock('../src/internal/cacheUtils')
|
||||
|
@ -55,8 +57,15 @@ test('save with large cache outputs should fail', async () => {
|
|||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValueOnce(Promise.resolve(compression))
|
||||
|
||||
const reserveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, 'reserveCache')
|
||||
.mockImplementation(async () => {
|
||||
let response: ITypedResponse<ReserveCacheResponse> = {statusCode:400, result: null, headers:{}}
|
||||
return response
|
||||
})
|
||||
|
||||
await expect(saveCache([filePath], primaryKey)).rejects.toThrowError(
|
||||
'Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.'
|
||||
'Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.'
|
||||
)
|
||||
|
||||
const archiveFolder = '/foo/bar'
|
||||
|
@ -77,7 +86,8 @@ test('save with reserve cache failure should fail', async () => {
|
|||
const reserveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, 'reserveCache')
|
||||
.mockImplementation(async () => {
|
||||
return -1
|
||||
let response: ITypedResponse<ReserveCacheResponse> = {statusCode:500, result: null, headers:{}}
|
||||
return response
|
||||
})
|
||||
|
||||
const createTarMock = jest.spyOn(tar, 'createTar')
|
||||
|
@ -94,7 +104,7 @@ test('save with reserve cache failure should fail', async () => {
|
|||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, {
|
||||
compressionMethod: compression
|
||||
})
|
||||
expect(createTarMock).toHaveBeenCalledTimes(0)
|
||||
expect(createTarMock).toHaveBeenCalledTimes(1)
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
@ -108,7 +118,8 @@ test('save with server error should fail', async () => {
|
|||
const reserveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, 'reserveCache')
|
||||
.mockImplementation(async () => {
|
||||
return cacheId
|
||||
let response: ITypedResponse<ReserveCacheResponse> = {statusCode:500, result: {cacheId}, headers:{}}
|
||||
return response
|
||||
})
|
||||
|
||||
const createTarMock = jest.spyOn(tar, 'createTar')
|
||||
|
@ -155,7 +166,8 @@ test('save with valid inputs uploads a cache', async () => {
|
|||
const reserveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, 'reserveCache')
|
||||
.mockImplementation(async () => {
|
||||
return cacheId
|
||||
let response: ITypedResponse<ReserveCacheResponse> = {statusCode:500, result: {cacheId}, headers:{}}
|
||||
return response
|
||||
})
|
||||
const createTarMock = jest.spyOn(tar, 'createTar')
|
||||
|
||||
|
|
Loading…
Reference in New Issue