2024-11-14 10:08:24 +00:00
|
|
|
import {downloadCache, getCacheVersion} from '../src/internal/cacheHttpClient'
|
|
|
|
import {CompressionMethod} from '../src/internal/constants'
|
2020-07-10 15:09:32 +00:00
|
|
|
import * as downloadUtils from '../src/internal/downloadUtils'
|
2024-11-14 10:08:24 +00:00
|
|
|
import {DownloadOptions, getDownloadOptions} from '../src/options'
|
2020-07-10 15:09:32 +00:00
|
|
|
|
|
|
|
jest.mock('../src/internal/downloadUtils')
|
2020-05-06 15:10:18 +00:00
|
|
|
|
2023-11-27 12:53:26 +00:00
|
|
|
test('getCacheVersion does not mutate arguments', async () => {
|
|
|
|
const paths = ['node_modules']
|
|
|
|
getCacheVersion(paths, undefined, true)
|
|
|
|
expect(paths).toEqual(['node_modules'])
|
|
|
|
})
|
|
|
|
|
2020-05-06 21:53:22 +00:00
|
|
|
test('getCacheVersion with one path returns version', async () => {
|
|
|
|
const paths = ['node_modules']
|
2023-01-04 06:46:25 +00:00
|
|
|
const result = getCacheVersion(paths, undefined, true)
|
2020-05-06 15:10:18 +00:00
|
|
|
expect(result).toEqual(
|
|
|
|
'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-06 21:53:22 +00:00
|
|
|
test('getCacheVersion with multiple paths returns version', async () => {
|
|
|
|
const paths = ['node_modules', 'dist']
|
2023-01-04 06:46:25 +00:00
|
|
|
const result = getCacheVersion(paths, undefined, true)
|
2020-05-06 21:53:22 +00:00
|
|
|
expect(result).toEqual(
|
|
|
|
'165c3053bc646bf0d4fac17b1f5731caca6fe38e0e464715c0c3c6b6318bf436'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-05-06 15:10:18 +00:00
|
|
|
test('getCacheVersion with zstd compression returns version', async () => {
|
2020-05-06 21:53:22 +00:00
|
|
|
const paths = ['node_modules']
|
2023-01-04 06:46:25 +00:00
|
|
|
const result = getCacheVersion(paths, CompressionMethod.Zstd, true)
|
2020-05-06 15:10:18 +00:00
|
|
|
|
|
|
|
expect(result).toEqual(
|
|
|
|
'273877e14fd65d270b87a198edbfa2db5a43de567c9a548d2a2505b408befe24'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-01-04 06:46:25 +00:00
|
|
|
test('getCacheVersion with gzip compression returns version', async () => {
|
2020-05-06 21:53:22 +00:00
|
|
|
const paths = ['node_modules']
|
2023-01-04 06:46:25 +00:00
|
|
|
const result = getCacheVersion(paths, CompressionMethod.Gzip, true)
|
2020-05-06 15:10:18 +00:00
|
|
|
|
|
|
|
expect(result).toEqual(
|
2023-01-04 06:46:25 +00:00
|
|
|
'470e252814dbffc9524891b17cf4e5749b26c1b5026e63dd3f00972db2393117'
|
2020-05-06 15:10:18 +00:00
|
|
|
)
|
|
|
|
})
|
2020-05-12 16:37:03 +00:00
|
|
|
|
2023-01-04 06:46:25 +00:00
|
|
|
test('getCacheVersion with enableCrossOsArchive as false returns version on windows', async () => {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
const paths = ['node_modules']
|
|
|
|
const result = getCacheVersion(paths)
|
|
|
|
|
|
|
|
expect(result).toEqual(
|
|
|
|
'2db19d6596dc34f51f0043120148827a264863f5c6ac857569c2af7119bad14e'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
test('downloadCache uses http-client for non-Azure URLs', async () => {
|
|
|
|
const downloadCacheHttpClientMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheHttpClient'
|
2020-05-12 16:37:03 +00:00
|
|
|
)
|
2020-07-10 15:09:32 +00:00
|
|
|
const downloadCacheStorageSDKMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheStorageSDK'
|
|
|
|
)
|
|
|
|
|
|
|
|
const archiveLocation = 'http://www.actionscache.test/download'
|
|
|
|
const archivePath = '/foo/bar'
|
2020-05-12 16:37:03 +00:00
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
await downloadCache(archiveLocation, archivePath)
|
|
|
|
|
|
|
|
expect(downloadCacheHttpClientMock).toHaveBeenCalledTimes(1)
|
|
|
|
expect(downloadCacheHttpClientMock).toHaveBeenCalledWith(
|
|
|
|
archiveLocation,
|
|
|
|
archivePath
|
2020-05-12 16:37:03 +00:00
|
|
|
)
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
expect(downloadCacheStorageSDKMock).toHaveBeenCalledTimes(0)
|
2020-05-12 16:37:03 +00:00
|
|
|
})
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
test('downloadCache uses storage SDK for Azure storage URLs', async () => {
|
|
|
|
const downloadCacheHttpClientMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheHttpClient'
|
|
|
|
)
|
|
|
|
const downloadCacheStorageSDKMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheStorageSDK'
|
|
|
|
)
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
const downloadCacheHttpClientConcurrentMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheHttpClientConcurrent'
|
|
|
|
)
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
const archiveLocation = 'http://foo.blob.core.windows.net/bar/baz'
|
|
|
|
const archivePath = '/foo/bar'
|
|
|
|
|
|
|
|
await downloadCache(archiveLocation, archivePath)
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
expect(downloadCacheHttpClientConcurrentMock).toHaveBeenCalledTimes(1)
|
|
|
|
expect(downloadCacheHttpClientConcurrentMock).toHaveBeenCalledWith(
|
2020-07-10 15:09:32 +00:00
|
|
|
archiveLocation,
|
|
|
|
archivePath,
|
|
|
|
getDownloadOptions()
|
|
|
|
)
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
expect(downloadCacheStorageSDKMock).toHaveBeenCalledTimes(0)
|
2020-07-10 15:09:32 +00:00
|
|
|
expect(downloadCacheHttpClientMock).toHaveBeenCalledTimes(0)
|
2020-05-12 16:37:03 +00:00
|
|
|
})
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
test('downloadCache passes options to download methods', async () => {
|
|
|
|
const downloadCacheHttpClientMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheHttpClient'
|
2020-05-12 16:37:03 +00:00
|
|
|
)
|
2020-07-10 15:09:32 +00:00
|
|
|
const downloadCacheStorageSDKMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheStorageSDK'
|
|
|
|
)
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
const downloadCacheHttpClientConcurrentMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheHttpClientConcurrent'
|
|
|
|
)
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
const archiveLocation = 'http://foo.blob.core.windows.net/bar/baz'
|
|
|
|
const archivePath = '/foo/bar'
|
2024-11-14 10:08:24 +00:00
|
|
|
const options: DownloadOptions = {downloadConcurrency: 4}
|
2020-07-10 15:09:32 +00:00
|
|
|
|
|
|
|
await downloadCache(archiveLocation, archivePath, options)
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
expect(downloadCacheHttpClientConcurrentMock).toHaveBeenCalledTimes(1)
|
|
|
|
expect(downloadCacheHttpClientConcurrentMock).toHaveBeenCalled()
|
|
|
|
expect(downloadCacheHttpClientConcurrentMock).toHaveBeenCalledWith(
|
2020-07-10 15:09:32 +00:00
|
|
|
archiveLocation,
|
|
|
|
archivePath,
|
|
|
|
getDownloadOptions(options)
|
|
|
|
)
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
expect(downloadCacheStorageSDKMock).toHaveBeenCalledTimes(0)
|
2020-07-10 15:09:32 +00:00
|
|
|
expect(downloadCacheHttpClientMock).toHaveBeenCalledTimes(0)
|
2020-05-12 16:37:03 +00:00
|
|
|
})
|
|
|
|
|
2020-07-10 15:09:32 +00:00
|
|
|
test('downloadCache uses http-client when overridden', async () => {
|
|
|
|
const downloadCacheHttpClientMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheHttpClient'
|
2020-05-12 16:37:03 +00:00
|
|
|
)
|
2020-07-10 15:09:32 +00:00
|
|
|
const downloadCacheStorageSDKMock = jest.spyOn(
|
|
|
|
downloadUtils,
|
|
|
|
'downloadCacheStorageSDK'
|
|
|
|
)
|
|
|
|
|
|
|
|
const archiveLocation = 'http://foo.blob.core.windows.net/bar/baz'
|
|
|
|
const archivePath = '/foo/bar'
|
2023-08-07 17:25:56 +00:00
|
|
|
const options: DownloadOptions = {
|
|
|
|
useAzureSdk: false,
|
|
|
|
concurrentBlobDownloads: false
|
|
|
|
}
|
2020-07-10 15:09:32 +00:00
|
|
|
|
|
|
|
await downloadCache(archiveLocation, archivePath, options)
|
|
|
|
|
|
|
|
expect(downloadCacheHttpClientMock).toHaveBeenCalledTimes(1)
|
|
|
|
expect(downloadCacheHttpClientMock).toHaveBeenCalledWith(
|
|
|
|
archiveLocation,
|
|
|
|
archivePath
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(downloadCacheStorageSDKMock).toHaveBeenCalledTimes(0)
|
2020-05-12 16:37:03 +00:00
|
|
|
})
|