mirror of https://github.com/actions/toolkit
Refactor cache upload functionality and improve test cases
parent
c5a5de05f6
commit
df166709a3
|
@ -6,7 +6,7 @@ import {CacheFilename, CompressionMethod} from '../src/internal/constants'
|
|||
import * as config from '../src/internal/config'
|
||||
import * as tar from '../src/internal/tar'
|
||||
import { CacheServiceClientJSON } from '../src/generated/results/api/v1/cache.twirp'
|
||||
import * as uploadCacheModule from '../src/internal/blob/upload-cache'
|
||||
import * as uploadCacheModule from '../src/internal/uploadUtils'
|
||||
import { BlobUploadCommonResponse } from '@azure/storage-blob'
|
||||
import { InvalidResponseError } from '../src/internal/shared/errors'
|
||||
|
||||
|
@ -116,8 +116,8 @@ test('create cache entry failure', async () => {
|
|||
.spyOn(cacheUtils, 'getArchiveFileSizeInBytes')
|
||||
.mockReturnValueOnce(archiveFileSize)
|
||||
const cacheVersion = cacheUtils.getCacheVersion(paths, compression)
|
||||
const uploadCacheFileMock = jest
|
||||
.spyOn(uploadCacheModule, 'uploadCacheFile')
|
||||
const uploadCacheArchiveSDKMock = jest
|
||||
.spyOn(uploadCacheModule, 'uploadCacheArchiveSDK')
|
||||
.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
_response: {
|
||||
|
@ -139,7 +139,7 @@ test('create cache entry failure', async () => {
|
|||
expect(createTarMock).toHaveBeenCalledTimes(1)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
expect(finalizeCacheEntryMock).toHaveBeenCalledTimes(0)
|
||||
expect(uploadCacheFileMock).toHaveBeenCalledTimes(0)
|
||||
expect(uploadCacheArchiveSDKMock).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
test('finalize save cache failure', async () => {
|
||||
|
@ -157,7 +157,7 @@ test('finalize save cache failure', async () => {
|
|||
|
||||
const createTarMock = jest.spyOn(tar, 'createTar')
|
||||
|
||||
const uploadCacheMock = jest.spyOn(uploadCacheModule, 'uploadCacheFile')
|
||||
const uploadCacheMock = jest.spyOn(uploadCacheModule, 'uploadCacheArchiveSDK')
|
||||
uploadCacheMock.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
_response: {
|
||||
|
@ -226,7 +226,7 @@ test('save with uploadCache Server error will fail', async () => {
|
|||
.spyOn(cacheUtils, 'getArchiveFileSizeInBytes')
|
||||
.mockReturnValueOnce(archiveFileSize)
|
||||
jest
|
||||
.spyOn(uploadCacheModule, 'uploadCacheFile')
|
||||
.spyOn(uploadCacheModule, 'uploadCacheArchiveSDK')
|
||||
.mockRejectedValueOnce(new InvalidResponseError('boom'))
|
||||
|
||||
const cacheId = await saveCache([paths], key)
|
||||
|
@ -248,7 +248,7 @@ test('uploadFile returns 500', async () => {
|
|||
jest
|
||||
.spyOn(cacheUtils, 'getArchiveFileSizeInBytes')
|
||||
.mockReturnValueOnce(archiveFileSize)
|
||||
jest.spyOn(uploadCacheModule, 'uploadCacheFile').mockRestore()
|
||||
jest.spyOn(uploadCacheModule, 'uploadCacheArchiveSDK').mockRestore()
|
||||
|
||||
uploadFileMock = jest.fn().mockResolvedValueOnce({
|
||||
_response: {
|
||||
|
@ -283,7 +283,7 @@ test('save with valid inputs uploads a cache', async () => {
|
|||
)
|
||||
|
||||
const uploadCacheMock = jest
|
||||
.spyOn(uploadCacheModule, 'uploadCacheFile')
|
||||
.spyOn(uploadCacheModule, 'uploadCacheArchiveSDK')
|
||||
.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
_response: {
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
GetCacheEntryDownloadURLRequest
|
||||
} from './generated/results/api/v1/cache'
|
||||
import { CacheFileSizeLimit } from './internal/constants'
|
||||
import {uploadCacheFile} from './internal/blob/upload-cache'
|
||||
import { uploadCacheArchiveSDK } from './internal/uploadUtils'
|
||||
export class ValidationError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
|
@ -521,7 +521,7 @@ async function saveCacheV2(
|
|||
}
|
||||
|
||||
core.debug(`Attempting to upload cache located at: ${archivePath}`)
|
||||
const uploadResponse = await uploadCacheFile(
|
||||
const uploadResponse = await uploadCacheArchiveSDK(
|
||||
response.signedUploadUrl,
|
||||
archivePath
|
||||
)
|
||||
|
|
|
@ -5,9 +5,10 @@ import {
|
|||
BlockBlobClient,
|
||||
BlockBlobParallelUploadOptions
|
||||
} from '@azure/storage-blob'
|
||||
import {InvalidResponseError} from '../shared/errors'
|
||||
import { InvalidResponseError } from './shared/errors'
|
||||
|
||||
export async function uploadCacheFile(
|
||||
export async function uploadCacheArchiveSDK
|
||||
(
|
||||
signedUploadURL: string,
|
||||
archivePath: string
|
||||
): Promise<BlobUploadCommonResponse> {
|
Loading…
Reference in New Issue