From b602df7c0584ec4803b8176c88abf07b53239a83 Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 30 Mar 2022 13:27:36 +0530 Subject: [PATCH] Modified tests --- packages/cache/__tests__/saveCache.test.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index d9dd5708..1a6771f0 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -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') @@ -54,9 +56,16 @@ test('save with large cache outputs should fail', async () => { const getCompressionMock = jest .spyOn(cacheUtils, 'getCompressionMethod') .mockReturnValueOnce(Promise.resolve(compression)) + + const reserveCacheMock = jest + .spyOn(cacheHttpClient, 'reserveCache') + .mockImplementation(async () => { + let response: ITypedResponse = {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 = {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 = {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 = {statusCode:500, result: {cacheId}, headers:{}} + return response }) const createTarMock = jest.spyOn(tar, 'createTar')