1
0
Fork 0

Respect download options for restore

pull/1882/head
Bassem Dghaidi 2024-11-28 04:56:37 -08:00 committed by GitHub
parent c1fb081674
commit eaf0083ee2
2 changed files with 16 additions and 39 deletions

View File

@ -3,7 +3,7 @@ import * as path from 'path'
import * as tar from '../src/internal/tar' import * as tar from '../src/internal/tar'
import * as config from '../src/internal/config' import * as config from '../src/internal/config'
import * as cacheUtils from '../src/internal/cacheUtils' import * as cacheUtils from '../src/internal/cacheUtils'
import * as downloadUtils from '../src/internal/downloadUtils' import * as cacheHttpClient from '../src/internal/cacheHttpClient'
import {restoreCache} from '../src/cache' import {restoreCache} from '../src/cache'
import {CacheFilename, CompressionMethod} from '../src/internal/constants' import {CacheFilename, CompressionMethod} from '../src/internal/constants'
import {CacheServiceClientJSON} from '../src/generated/results/api/v1/cache.twirp' import {CacheServiceClientJSON} from '../src/generated/results/api/v1/cache.twirp'
@ -142,7 +142,6 @@ test('restore with gzip compressed cache found', async () => {
const signedDownloadUrl = 'https://blob-storage.local?signed=true' const signedDownloadUrl = 'https://blob-storage.local?signed=true'
const cacheVersion = const cacheVersion =
'd90f107aaeb22920dba0c637a23c37b5bc497b4dfa3b07fe3f79bf88a273c11b' 'd90f107aaeb22920dba0c637a23c37b5bc497b4dfa3b07fe3f79bf88a273c11b'
const options: DownloadOptions = {timeoutInMs: 30000}
const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion') const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion')
getCacheVersionMock.mockReturnValue(cacheVersion) getCacheVersionMock.mockReturnValue(cacheVersion)
@ -170,11 +169,7 @@ test('restore with gzip compressed cache found', async () => {
}) })
const archivePath = path.join(tempPath, CacheFilename.Gzip) const archivePath = path.join(tempPath, CacheFilename.Gzip)
const downloadCacheStorageSDKMock = jest.spyOn( const downloadCacheMock = jest.spyOn(cacheHttpClient, 'downloadCache')
downloadUtils,
'downloadCacheStorageSDK'
)
downloadCacheStorageSDKMock.mockReturnValue(Promise.resolve())
const fileSize = 142 const fileSize = 142
const getArchiveFileSizeInBytesMock = jest const getArchiveFileSizeInBytesMock = jest
@ -198,10 +193,10 @@ test('restore with gzip compressed cache found', async () => {
version: cacheVersion version: cacheVersion
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheStorageSDKMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(
signedDownloadUrl, signedDownloadUrl,
archivePath, archivePath,
options undefined
) )
expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath) expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath)
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`) expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)
@ -222,7 +217,6 @@ test('restore with zstd compressed cache found', async () => {
const signedDownloadUrl = 'https://blob-storage.local?signed=true' const signedDownloadUrl = 'https://blob-storage.local?signed=true'
const cacheVersion = const cacheVersion =
'8e2e96a184cb0cd6b48285b176c06a418f3d7fce14c29d9886fd1bb4f05c513d' '8e2e96a184cb0cd6b48285b176c06a418f3d7fce14c29d9886fd1bb4f05c513d'
const options: DownloadOptions = {timeoutInMs: 30000}
const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion') const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion')
getCacheVersionMock.mockReturnValue(cacheVersion) getCacheVersionMock.mockReturnValue(cacheVersion)
@ -250,11 +244,7 @@ test('restore with zstd compressed cache found', async () => {
}) })
const archivePath = path.join(tempPath, CacheFilename.Zstd) const archivePath = path.join(tempPath, CacheFilename.Zstd)
const downloadCacheStorageSDKMock = jest.spyOn( const downloadCacheMock = jest.spyOn(cacheHttpClient, 'downloadCache')
downloadUtils,
'downloadCacheStorageSDK'
)
downloadCacheStorageSDKMock.mockReturnValue(Promise.resolve())
const fileSize = 62915000 const fileSize = 62915000
const getArchiveFileSizeInBytesMock = jest const getArchiveFileSizeInBytesMock = jest
@ -278,10 +268,10 @@ test('restore with zstd compressed cache found', async () => {
version: cacheVersion version: cacheVersion
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheStorageSDKMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(
signedDownloadUrl, signedDownloadUrl,
archivePath, archivePath,
options undefined
) )
expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath) expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath)
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`) expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~60 MB (62915000 B)`)
@ -303,7 +293,6 @@ test('restore with cache found for restore key', async () => {
const signedDownloadUrl = 'https://blob-storage.local?signed=true' const signedDownloadUrl = 'https://blob-storage.local?signed=true'
const cacheVersion = const cacheVersion =
'b8b58e9bd7b1e8f83d9f05c7e06ea865ba44a0330e07a14db74ac74386677bed' 'b8b58e9bd7b1e8f83d9f05c7e06ea865ba44a0330e07a14db74ac74386677bed'
const options: DownloadOptions = {timeoutInMs: 30000}
const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion') const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion')
getCacheVersionMock.mockReturnValue(cacheVersion) getCacheVersionMock.mockReturnValue(cacheVersion)
@ -331,11 +320,7 @@ test('restore with cache found for restore key', async () => {
}) })
const archivePath = path.join(tempPath, CacheFilename.Gzip) const archivePath = path.join(tempPath, CacheFilename.Gzip)
const downloadCacheStorageSDKMock = jest.spyOn( const downloadCacheMock = jest.spyOn(cacheHttpClient, 'downloadCache')
downloadUtils,
'downloadCacheStorageSDK'
)
downloadCacheStorageSDKMock.mockReturnValue(Promise.resolve())
const fileSize = 142 const fileSize = 142
const getArchiveFileSizeInBytesMock = jest const getArchiveFileSizeInBytesMock = jest
@ -359,10 +344,10 @@ test('restore with cache found for restore key', async () => {
version: cacheVersion version: cacheVersion
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheStorageSDKMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(
signedDownloadUrl, signedDownloadUrl,
archivePath, archivePath,
options undefined
) )
expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath) expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath)
expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`) expect(logInfoMock).toHaveBeenCalledWith(`Cache Size: ~0 MB (142 B)`)
@ -376,14 +361,14 @@ test('restore with cache found for restore key', async () => {
expect(compressionMethodMock).toHaveBeenCalledTimes(1) expect(compressionMethodMock).toHaveBeenCalledTimes(1)
}) })
test('restore with dry run', async () => { test('restore with lookup only enabled', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'node-test' const key = 'node-test'
const compressionMethod = CompressionMethod.Gzip const compressionMethod = CompressionMethod.Gzip
const signedDownloadUrl = 'https://blob-storage.local?signed=true' const signedDownloadUrl = 'https://blob-storage.local?signed=true'
const cacheVersion = const cacheVersion =
'd90f107aaeb22920dba0c637a23c37b5bc497b4dfa3b07fe3f79bf88a273c11b' 'd90f107aaeb22920dba0c637a23c37b5bc497b4dfa3b07fe3f79bf88a273c11b'
const options: DownloadOptions = {lookupOnly: true, timeoutInMs: 30000} const options = {lookupOnly: true} as DownloadOptions
const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion') const getCacheVersionMock = jest.spyOn(cacheUtils, 'getCacheVersion')
getCacheVersionMock.mockReturnValue(cacheVersion) getCacheVersionMock.mockReturnValue(cacheVersion)
@ -404,11 +389,7 @@ test('restore with dry run', async () => {
) )
const createTempDirectoryMock = jest.spyOn(cacheUtils, 'createTempDirectory') const createTempDirectoryMock = jest.spyOn(cacheUtils, 'createTempDirectory')
const downloadCacheStorageSDKMock = jest.spyOn( const downloadCacheMock = jest.spyOn(cacheHttpClient, 'downloadCache')
downloadUtils,
'downloadCacheStorageSDK'
)
downloadCacheStorageSDKMock.mockReturnValue(Promise.resolve())
const cacheKey = await restoreCache(paths, key, undefined, options) const cacheKey = await restoreCache(paths, key, undefined, options)
@ -427,5 +408,5 @@ test('restore with dry run', async () => {
// creating a tempDir and downloading the cache are skipped // creating a tempDir and downloading the cache are skipped
expect(createTempDirectoryMock).toHaveBeenCalledTimes(0) expect(createTempDirectoryMock).toHaveBeenCalledTimes(0)
expect(downloadCacheStorageSDKMock).toHaveBeenCalledTimes(0) expect(downloadCacheMock).toHaveBeenCalledTimes(0)
}) })

View File

@ -3,7 +3,6 @@ import * as path from 'path'
import * as utils from './internal/cacheUtils' import * as utils from './internal/cacheUtils'
import * as cacheHttpClient from './internal/cacheHttpClient' import * as cacheHttpClient from './internal/cacheHttpClient'
import * as cacheTwirpClient from './internal/shared/cacheTwirpClient' import * as cacheTwirpClient from './internal/shared/cacheTwirpClient'
import {downloadCacheStorageSDK} from './internal/downloadUtils'
import {getCacheServiceVersion, isGhes} from './internal/config' import {getCacheServiceVersion, isGhes} from './internal/config'
import {DownloadOptions, UploadOptions} from './options' import {DownloadOptions, UploadOptions} from './options'
import {createTar, extractTar, listTar} from './internal/tar' import {createTar, extractTar, listTar} from './internal/tar'
@ -271,13 +270,10 @@ async function restoreCacheV2(
core.debug(`Archive path: ${archivePath}`) core.debug(`Archive path: ${archivePath}`)
core.debug(`Starting download of archive to: ${archivePath}`) core.debug(`Starting download of archive to: ${archivePath}`)
await downloadCacheStorageSDK( await cacheHttpClient.downloadCache(
response.signedDownloadUrl, response.signedDownloadUrl,
archivePath, archivePath,
options || options
({
timeoutInMs: 30000
} as DownloadOptions)
) )
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath) const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)