1
0
Fork 0
pull/1291/head
Sampark Sharma 2022-12-29 11:55:10 +00:00 committed by GitHub
parent ec3a87298b
commit da162e46a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 17 deletions

View File

@ -7,7 +7,7 @@ jest.mock('../src/internal/downloadUtils')
test('getCacheVersion with one path returns version', async () => { test('getCacheVersion with one path returns version', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const result = getCacheVersion(paths) const result = getCacheVersion(paths, undefined, true)
expect(result).toEqual( expect(result).toEqual(
'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985' 'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985'
) )
@ -15,7 +15,7 @@ test('getCacheVersion with one path returns version', async () => {
test('getCacheVersion with multiple paths returns version', async () => { test('getCacheVersion with multiple paths returns version', async () => {
const paths = ['node_modules', 'dist'] const paths = ['node_modules', 'dist']
const result = getCacheVersion(paths) const result = getCacheVersion(paths, undefined, true)
expect(result).toEqual( expect(result).toEqual(
'165c3053bc646bf0d4fac17b1f5731caca6fe38e0e464715c0c3c6b6318bf436' '165c3053bc646bf0d4fac17b1f5731caca6fe38e0e464715c0c3c6b6318bf436'
) )
@ -23,7 +23,7 @@ test('getCacheVersion with multiple paths returns version', async () => {
test('getCacheVersion with zstd compression returns version', async () => { test('getCacheVersion with zstd compression returns version', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const result = getCacheVersion(paths, CompressionMethod.Zstd) const result = getCacheVersion(paths, CompressionMethod.Zstd, true)
expect(result).toEqual( expect(result).toEqual(
'273877e14fd65d270b87a198edbfa2db5a43de567c9a548d2a2505b408befe24' '273877e14fd65d270b87a198edbfa2db5a43de567c9a548d2a2505b408befe24'
@ -32,13 +32,24 @@ test('getCacheVersion with zstd compression returns version', async () => {
test('getCacheVersion with gzip compression does not change vesion', async () => { test('getCacheVersion with gzip compression does not change vesion', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const result = getCacheVersion(paths, CompressionMethod.Gzip) const result = getCacheVersion(paths, CompressionMethod.Gzip, true)
expect(result).toEqual( expect(result).toEqual(
'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985' 'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985'
) )
}) })
test('getCacheVersion with crossOsEnabled as false returns version on windows', async () => {
if (process.platform === 'win32') {
const paths = ['node_modules']
const result = getCacheVersion(paths)
expect(result).toEqual(
'2db19d6596dc34f51f0043120148827a264863f5c6ac857569c2af7119bad14e'
)
}
})
test('downloadCache uses http-client for non-Azure URLs', async () => { test('downloadCache uses http-client for non-Azure URLs', async () => {
const downloadCacheHttpClientMock = jest.spyOn( const downloadCacheHttpClientMock = jest.spyOn(
downloadUtils, downloadUtils,

View File

@ -142,7 +142,8 @@ test('restore with gzip compressed cache found', async () => {
expect(cacheKey).toBe(key) expect(cacheKey).toBe(key)
expect(getCacheMock).toHaveBeenCalledWith([key], paths, { expect(getCacheMock).toHaveBeenCalledWith([key], paths, {
compressionMethod: compression compressionMethod: compression,
crossOsEnabled: false
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(
@ -210,7 +211,8 @@ test('restore with zstd as default but gzip compressed cache found on windows',
expect(cacheKey).toBe(key) expect(cacheKey).toBe(key)
expect(getCacheMock).toHaveBeenNthCalledWith(1, [key], paths, { expect(getCacheMock).toHaveBeenNthCalledWith(1, [key], paths, {
compressionMethod: compression compressionMethod: compression,
crossOsEnabled: false
}) })
expect(getCacheMock).toHaveBeenNthCalledWith(2, [key], paths, { expect(getCacheMock).toHaveBeenNthCalledWith(2, [key], paths, {
compressionMethod: CompressionMethod.Gzip compressionMethod: CompressionMethod.Gzip
@ -276,7 +278,8 @@ test('restore with zstd compressed cache found', async () => {
expect(cacheKey).toBe(key) expect(cacheKey).toBe(key)
expect(getCacheMock).toHaveBeenCalledWith([key], paths, { expect(getCacheMock).toHaveBeenCalledWith([key], paths, {
compressionMethod: compression compressionMethod: compression,
crossOsEnabled: false
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(
@ -333,7 +336,8 @@ test('restore with cache found for restore key', async () => {
expect(cacheKey).toBe(restoreKey) expect(cacheKey).toBe(restoreKey)
expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey], paths, { expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey], paths, {
compressionMethod: compression compressionMethod: compression,
crossOsEnabled: false
}) })
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1) expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
expect(downloadCacheMock).toHaveBeenCalledWith( expect(downloadCacheMock).toHaveBeenCalledWith(

View File

@ -209,7 +209,9 @@ test('save with reserve cache failure should fail', async () => {
expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledTimes(1)
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, {
compressionMethod: compression cacheSize: undefined,
compressionMethod: compression,
crossOsEnabled: false
}) })
expect(createTarMock).toHaveBeenCalledTimes(1) expect(createTarMock).toHaveBeenCalledTimes(1)
expect(saveCacheMock).toHaveBeenCalledTimes(0) expect(saveCacheMock).toHaveBeenCalledTimes(0)
@ -253,7 +255,9 @@ test('save with server error should fail', async () => {
expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledTimes(1)
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], {
compressionMethod: compression cacheSize: undefined,
compressionMethod: compression,
crossOsEnabled: false
}) })
const archiveFolder = '/foo/bar' const archiveFolder = '/foo/bar'
const archiveFile = path.join(archiveFolder, CacheFilename.Zstd) const archiveFile = path.join(archiveFolder, CacheFilename.Zstd)
@ -296,7 +300,9 @@ test('save with valid inputs uploads a cache', async () => {
expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledTimes(1)
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], {
compressionMethod: compression cacheSize: undefined,
compressionMethod: compression,
crossOsEnabled: false
}) })
const archiveFolder = '/foo/bar' const archiveFolder = '/foo/bar'
const archiveFile = path.join(archiveFolder, CacheFilename.Zstd) const archiveFile = path.join(archiveFolder, CacheFilename.Zstd)

View File

@ -61,16 +61,16 @@ export function isFeatureAvailable(): boolean {
* @param paths a list of file paths to restore from the cache * @param paths a list of file paths to restore from the cache
* @param primaryKey an explicit key for restoring the cache * @param primaryKey an explicit key for restoring the cache
* @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key * @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
* @param crossOsEnabled an optional boolean enabled to restore on windows any cache created on any platform
* @param downloadOptions cache download options * @param downloadOptions cache download options
* @param crossOsEnabled an optional boolean enabled to restore on windows any cache created on any platform
* @returns string returns the key for the cache hit, otherwise returns undefined * @returns string returns the key for the cache hit, otherwise returns undefined
*/ */
export async function restoreCache( export async function restoreCache(
paths: string[], paths: string[],
primaryKey: string, primaryKey: string,
restoreKeys?: string[], restoreKeys?: string[],
crossOsEnabled = false, options?: DownloadOptions,
options?: DownloadOptions crossOsEnabled = false
): Promise<string | undefined> { ): Promise<string | undefined> {
checkPaths(paths) checkPaths(paths)
@ -181,8 +181,8 @@ export async function restoreCache(
export async function saveCache( export async function saveCache(
paths: string[], paths: string[],
key: string, key: string,
crossOsEnabled = false, options?: UploadOptions,
options?: UploadOptions crossOsEnabled = false
): Promise<number> { ): Promise<number> {
checkPaths(paths) checkPaths(paths)
checkKey(key) checkKey(key)

View File

@ -34,9 +34,9 @@ export interface ReserveCacheResponse {
} }
export interface InternalCacheOptions { export interface InternalCacheOptions {
cacheSize?: number
compressionMethod?: CompressionMethod compressionMethod?: CompressionMethod
crossOsEnabled?: boolean crossOsEnabled?: boolean
cacheSize?: number
} }
export interface ArchiveTool { export interface ArchiveTool {