mirror of https://github.com/actions/toolkit
Add test
parent
c0085d7739
commit
d1094e1523
|
@ -161,6 +161,81 @@ test('restore with gzip compressed cache found', async () => {
|
||||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
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(<ArtifactCacheEntry>{})
|
||||||
|
})
|
||||||
|
.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 () => {
|
test('restore with zstd compressed cache found', async () => {
|
||||||
const paths = ['node_modules']
|
const paths = ['node_modules']
|
||||||
const key = 'node-test'
|
const key = 'node-test'
|
||||||
|
|
|
@ -106,9 +106,8 @@ export async function restoreCache(
|
||||||
process.platform === 'win32' &&
|
process.platform === 'win32' &&
|
||||||
compressionMethod !== CompressionMethod.Gzip
|
compressionMethod !== CompressionMethod.Gzip
|
||||||
) {
|
) {
|
||||||
// On windows, we will try to download the cache entry with the same key
|
// This is to support the old cache entry created
|
||||||
// but with different compression method. This is to support the old cache entry created
|
// by the old version of the cache action on windows.
|
||||||
// by the old version of the cache action.
|
|
||||||
compressionMethod = CompressionMethod.Gzip
|
compressionMethod = CompressionMethod.Gzip
|
||||||
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
|
||||||
compressionMethod
|
compressionMethod
|
||||||
|
|
Loading…
Reference in New Issue