mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-20 13:58:04 +08:00
Cache package release for compression change in windows (#1281)
* bsd + zstd fallback implementation * bsd + zstd fallback implementation * Fix tar operations * Add -v option for testing * Fix order of args for tar * Add GNUtar as default on windows * Fix test * Fix tar tests * Fix lint issues * Fix windows gnutar test case * Temporarily remove thhe condition that prevents zstd usage on windows unless with GNUtar * Address some comments and correct compression commands * Add windows bsdtar test * Fix windows test * Fix test * Separate args * Fix old tests * Add new tests * Fix tests * Fix lint test * Refactor code * Address review comments * Fix test * Fix tar test * Add await to async function calls * Fix test * Update for beta release * Fix audit issues * Add fallback to gzip compression if cache not found * Fix test * Add test * Address review comments * Revert Address review comments * Release 3.1.0-beta.2 cache package * Fix issues * Reconfigure catch block * Add debug logging for gzip fall back * Fix test * Add end to end test for cache using bsd on windows and address review comments * Fix test * Fix test * Fix tests * Add better comments * Update packages/cache/src/internal/cacheHttpClient.ts Co-authored-by: Bishal Prasad <bishal-pdmsft@github.com> * Address review comments * Update for new beta cache package release * Address bugbash issues * Fix tests * Release new actions/cache minor version Co-authored-by: Lovepreet Singh <pdotl@github.com> Co-authored-by: Bishal Prasad <bishal-pdmsft@github.com>
This commit is contained in:
75
packages/cache/__tests__/restoreCache.test.ts
vendored
75
packages/cache/__tests__/restoreCache.test.ts
vendored
@@ -161,6 +161,81 @@ test('restore with gzip compressed cache found', async () => {
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('restore with zstd as default but gzip compressed cache found on windows', async () => {
|
||||
if (process.platform === 'win32') {
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
|
||||
const cacheEntry: ArtifactCacheEntry = {
|
||||
cacheKey: key,
|
||||
scope: 'refs/heads/main',
|
||||
archiveLocation: 'www.actionscache.test/download'
|
||||
}
|
||||
const getCacheMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
|
||||
getCacheMock
|
||||
.mockImplementationOnce(async () => {
|
||||
return Promise.resolve(null)
|
||||
})
|
||||
.mockImplementationOnce(async () => {
|
||||
return Promise.resolve(cacheEntry)
|
||||
})
|
||||
|
||||
const tempPath = '/foo/bar'
|
||||
|
||||
const createTempDirectoryMock = jest.spyOn(
|
||||
cacheUtils,
|
||||
'createTempDirectory'
|
||||
)
|
||||
createTempDirectoryMock.mockImplementation(async () => {
|
||||
return Promise.resolve(tempPath)
|
||||
})
|
||||
|
||||
const archivePath = path.join(tempPath, CacheFilename.Gzip)
|
||||
const downloadCacheMock = jest.spyOn(cacheHttpClient, 'downloadCache')
|
||||
|
||||
const fileSize = 142
|
||||
const getArchiveFileSizeInBytesMock = jest
|
||||
.spyOn(cacheUtils, 'getArchiveFileSizeInBytes')
|
||||
.mockReturnValue(fileSize)
|
||||
|
||||
const extractTarMock = jest.spyOn(tar, 'extractTar')
|
||||
const unlinkFileMock = jest.spyOn(cacheUtils, 'unlinkFile')
|
||||
|
||||
const compression = CompressionMethod.Zstd
|
||||
const getCompressionMock = jest
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
|
||||
const cacheKey = await restoreCache(paths, key)
|
||||
|
||||
expect(cacheKey).toBe(key)
|
||||
expect(getCacheMock).toHaveBeenNthCalledWith(1, [key], paths, {
|
||||
compressionMethod: compression
|
||||
})
|
||||
expect(getCacheMock).toHaveBeenNthCalledWith(2, [key], paths, {
|
||||
compressionMethod: CompressionMethod.Gzip
|
||||
})
|
||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
|
||||
expect(downloadCacheMock).toHaveBeenCalledWith(
|
||||
cacheEntry.archiveLocation,
|
||||
archivePath,
|
||||
undefined
|
||||
)
|
||||
expect(getArchiveFileSizeInBytesMock).toHaveBeenCalledWith(archivePath)
|
||||
|
||||
expect(extractTarMock).toHaveBeenCalledTimes(1)
|
||||
expect(extractTarMock).toHaveBeenCalledWith(
|
||||
archivePath,
|
||||
CompressionMethod.Gzip
|
||||
)
|
||||
|
||||
expect(unlinkFileMock).toHaveBeenCalledTimes(1)
|
||||
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
|
||||
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
})
|
||||
|
||||
test('restore with zstd compressed cache found', async () => {
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
|
||||
Reference in New Issue
Block a user