1
0
Fork 0

Modified tests

pull/1036/head
Apple 2022-03-30 13:27:36 +05:30
parent 80a66f3298
commit b602df7c05
1 changed files with 17 additions and 5 deletions

View File

@ -5,6 +5,8 @@ import * as cacheHttpClient from '../src/internal/cacheHttpClient'
import * as cacheUtils from '../src/internal/cacheUtils' import * as cacheUtils from '../src/internal/cacheUtils'
import {CacheFilename, CompressionMethod} from '../src/internal/constants' import {CacheFilename, CompressionMethod} from '../src/internal/constants'
import * as tar from '../src/internal/tar' 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/cacheHttpClient')
jest.mock('../src/internal/cacheUtils') jest.mock('../src/internal/cacheUtils')
@ -55,8 +57,15 @@ test('save with large cache outputs should fail', async () => {
.spyOn(cacheUtils, 'getCompressionMethod') .spyOn(cacheUtils, 'getCompressionMethod')
.mockReturnValueOnce(Promise.resolve(compression)) .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( 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' const archiveFolder = '/foo/bar'
@ -77,7 +86,8 @@ test('save with reserve cache failure should fail', async () => {
const reserveCacheMock = jest const reserveCacheMock = jest
.spyOn(cacheHttpClient, 'reserveCache') .spyOn(cacheHttpClient, 'reserveCache')
.mockImplementation(async () => { .mockImplementation(async () => {
return -1 let response: ITypedResponse<ReserveCacheResponse> = {statusCode:500, result: null, headers:{}}
return response
}) })
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
@ -94,7 +104,7 @@ test('save with reserve cache failure should fail', async () => {
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, {
compressionMethod: compression compressionMethod: compression
}) })
expect(createTarMock).toHaveBeenCalledTimes(0) expect(createTarMock).toHaveBeenCalledTimes(1)
expect(saveCacheMock).toHaveBeenCalledTimes(0) expect(saveCacheMock).toHaveBeenCalledTimes(0)
expect(getCompressionMock).toHaveBeenCalledTimes(1) expect(getCompressionMock).toHaveBeenCalledTimes(1)
}) })
@ -108,7 +118,8 @@ test('save with server error should fail', async () => {
const reserveCacheMock = jest const reserveCacheMock = jest
.spyOn(cacheHttpClient, 'reserveCache') .spyOn(cacheHttpClient, 'reserveCache')
.mockImplementation(async () => { .mockImplementation(async () => {
return cacheId let response: ITypedResponse<ReserveCacheResponse> = {statusCode:500, result: {cacheId}, headers:{}}
return response
}) })
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
@ -155,7 +166,8 @@ test('save with valid inputs uploads a cache', async () => {
const reserveCacheMock = jest const reserveCacheMock = jest
.spyOn(cacheHttpClient, 'reserveCache') .spyOn(cacheHttpClient, 'reserveCache')
.mockImplementation(async () => { .mockImplementation(async () => {
return cacheId let response: ITypedResponse<ReserveCacheResponse> = {statusCode:500, result: {cacheId}, headers:{}}
return response
}) })
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')