mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-05-01 03:08:07 +08:00
Change variable path to a list
This commit is contained in:
22
packages/cache/__tests__/cacheHttpClient.test.ts
vendored
22
packages/cache/__tests__/cacheHttpClient.test.ts
vendored
@@ -1,17 +1,25 @@
|
||||
import {getCacheVersion} from '../src/internal/cacheHttpClient'
|
||||
import {CompressionMethod} from '../src/internal/constants'
|
||||
|
||||
test('getCacheVersion with path input and compression method undefined returns version', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const result = getCacheVersion(inputPath)
|
||||
test('getCacheVersion with one path returns version', async () => {
|
||||
const paths = ['node_modules']
|
||||
const result = getCacheVersion(paths)
|
||||
expect(result).toEqual(
|
||||
'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985'
|
||||
)
|
||||
})
|
||||
|
||||
test('getCacheVersion with multiple paths returns version', async () => {
|
||||
const paths = ['node_modules', 'dist']
|
||||
const result = getCacheVersion(paths)
|
||||
expect(result).toEqual(
|
||||
'165c3053bc646bf0d4fac17b1f5731caca6fe38e0e464715c0c3c6b6318bf436'
|
||||
)
|
||||
})
|
||||
|
||||
test('getCacheVersion with zstd compression returns version', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const result = getCacheVersion(inputPath, CompressionMethod.Zstd)
|
||||
const paths = ['node_modules']
|
||||
const result = getCacheVersion(paths, CompressionMethod.Zstd)
|
||||
|
||||
expect(result).toEqual(
|
||||
'273877e14fd65d270b87a198edbfa2db5a43de567c9a548d2a2505b408befe24'
|
||||
@@ -19,8 +27,8 @@ test('getCacheVersion with zstd compression returns version', async () => {
|
||||
})
|
||||
|
||||
test('getCacheVersion with gzip compression does not change vesion', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const result = getCacheVersion(inputPath, CompressionMethod.Gzip)
|
||||
const paths = ['node_modules']
|
||||
const result = getCacheVersion(paths, CompressionMethod.Gzip)
|
||||
|
||||
expect(result).toEqual(
|
||||
'b3e0c6cb5ecf32614eeb2997d905b9c297046d7cbf69062698f25b14b4cb0985'
|
||||
|
||||
140
packages/cache/__tests__/cacheUtils.test.ts
vendored
140
packages/cache/__tests__/cacheUtils.test.ts
vendored
@@ -1,9 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as io from '@actions/io'
|
||||
import {promises as fs} from 'fs'
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import {v4 as uuidV4} from 'uuid'
|
||||
import * as cacheUtils from '../src/internal/cacheUtils'
|
||||
|
||||
jest.mock('@actions/core')
|
||||
@@ -26,143 +23,6 @@ test('getArchiveFileSize returns file size', () => {
|
||||
expect(size).toBe(11)
|
||||
})
|
||||
|
||||
test('logWarning logs a message with a warning prefix', () => {
|
||||
const message = 'A warning occurred.'
|
||||
|
||||
const infoMock = jest.spyOn(core, 'info')
|
||||
|
||||
cacheUtils.logWarning(message)
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`)
|
||||
})
|
||||
|
||||
test('resolvePaths with no ~ in path', async () => {
|
||||
const filePath = '.cache'
|
||||
|
||||
// Create the following layout:
|
||||
// cwd
|
||||
// cwd/.cache
|
||||
// cwd/.cache/file.txt
|
||||
|
||||
const root = path.join(getTempDir(), 'no-tilde')
|
||||
// tarball entries will be relative to workspace
|
||||
process.env['GITHUB_WORKSPACE'] = root
|
||||
|
||||
await fs.mkdir(root, {recursive: true})
|
||||
const cache = path.join(root, '.cache')
|
||||
await fs.mkdir(cache, {recursive: true})
|
||||
await fs.writeFile(path.join(cache, 'file.txt'), 'cached')
|
||||
|
||||
const originalCwd = process.cwd()
|
||||
|
||||
try {
|
||||
process.chdir(root)
|
||||
|
||||
const resolvedPath = await cacheUtils.resolvePaths([filePath])
|
||||
|
||||
const expectedPath = [filePath]
|
||||
expect(resolvedPath).toStrictEqual(expectedPath)
|
||||
} finally {
|
||||
process.chdir(originalCwd)
|
||||
}
|
||||
})
|
||||
|
||||
test('resolvePaths with ~ in path', async () => {
|
||||
const cacheDir = uuidV4()
|
||||
const filePath = `~/${cacheDir}`
|
||||
// Create the following layout:
|
||||
// ~/uuid
|
||||
// ~/uuid/file.txt
|
||||
|
||||
const homedir = jest.requireActual('os').homedir()
|
||||
const homedirMock = jest.spyOn(os, 'homedir')
|
||||
homedirMock.mockReturnValue(homedir)
|
||||
|
||||
const target = path.join(homedir, cacheDir)
|
||||
await fs.mkdir(target, {recursive: true})
|
||||
await fs.writeFile(path.join(target, 'file.txt'), 'cached')
|
||||
|
||||
const root = getTempDir()
|
||||
process.env['GITHUB_WORKSPACE'] = root
|
||||
|
||||
try {
|
||||
const resolvedPath = await cacheUtils.resolvePaths([filePath])
|
||||
|
||||
const expectedPath = [path.relative(root, target)]
|
||||
expect(resolvedPath).toStrictEqual(expectedPath)
|
||||
} finally {
|
||||
await io.rmRF(target)
|
||||
}
|
||||
})
|
||||
|
||||
test('resolvePaths with home not found', async () => {
|
||||
const filePath = '~/.cache/yarn'
|
||||
const homedirMock = jest.spyOn(os, 'homedir')
|
||||
homedirMock.mockReturnValue('')
|
||||
|
||||
await expect(cacheUtils.resolvePaths([filePath])).rejects.toThrow(
|
||||
'Unable to determine HOME directory'
|
||||
)
|
||||
})
|
||||
|
||||
test('resolvePaths inclusion pattern returns found', async () => {
|
||||
const pattern = '*.ts'
|
||||
// Create the following layout:
|
||||
// inclusion-patterns
|
||||
// inclusion-patterns/miss.txt
|
||||
// inclusion-patterns/test.ts
|
||||
|
||||
const root = path.join(getTempDir(), 'inclusion-patterns')
|
||||
// tarball entries will be relative to workspace
|
||||
process.env['GITHUB_WORKSPACE'] = root
|
||||
|
||||
await fs.mkdir(root, {recursive: true})
|
||||
await fs.writeFile(path.join(root, 'miss.txt'), 'no match')
|
||||
await fs.writeFile(path.join(root, 'test.ts'), 'match')
|
||||
|
||||
const originalCwd = process.cwd()
|
||||
|
||||
try {
|
||||
process.chdir(root)
|
||||
|
||||
const resolvedPath = await cacheUtils.resolvePaths([pattern])
|
||||
|
||||
const expectedPath = ['test.ts']
|
||||
expect(resolvedPath).toStrictEqual(expectedPath)
|
||||
} finally {
|
||||
process.chdir(originalCwd)
|
||||
}
|
||||
})
|
||||
|
||||
test('resolvePaths exclusion pattern returns not found', async () => {
|
||||
const patterns = ['*.ts', '!test.ts']
|
||||
// Create the following layout:
|
||||
// exclusion-patterns
|
||||
// exclusion-patterns/miss.txt
|
||||
// exclusion-patterns/test.ts
|
||||
|
||||
const root = path.join(getTempDir(), 'exclusion-patterns')
|
||||
// tarball entries will be relative to workspace
|
||||
process.env['GITHUB_WORKSPACE'] = root
|
||||
|
||||
await fs.mkdir(root, {recursive: true})
|
||||
await fs.writeFile(path.join(root, 'miss.txt'), 'no match')
|
||||
await fs.writeFile(path.join(root, 'test.ts'), 'no match')
|
||||
|
||||
const originalCwd = process.cwd()
|
||||
|
||||
try {
|
||||
process.chdir(root)
|
||||
|
||||
const resolvedPath = await cacheUtils.resolvePaths(patterns)
|
||||
|
||||
const expectedPath: string[] = []
|
||||
expect(resolvedPath).toStrictEqual(expectedPath)
|
||||
} finally {
|
||||
process.chdir(originalCwd)
|
||||
}
|
||||
})
|
||||
|
||||
test('unlinkFile unlinks file', async () => {
|
||||
const testDirectory = await fs.mkdtemp('unlinkFileTest')
|
||||
const testFile = path.join(testDirectory, 'test.txt')
|
||||
|
||||
81
packages/cache/__tests__/restoreCache.test.ts
vendored
81
packages/cache/__tests__/restoreCache.test.ts
vendored
@@ -20,112 +20,95 @@ beforeAll(() => {
|
||||
})
|
||||
|
||||
test('restore with no path should fail', async () => {
|
||||
const inputPath = ''
|
||||
const paths: string[] = []
|
||||
const key = 'node-test'
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
await restoreCache(inputPath, key)
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
'Input required and not supplied: path'
|
||||
await expect(restoreCache(paths, key)).rejects.toThrowError(
|
||||
`Path Validation Error: At least one directory or file path is required`
|
||||
)
|
||||
})
|
||||
|
||||
test('restore with too many keys should fail', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
const restoreKeys = [...Array(20).keys()].map(x => x.toString())
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
await restoreCache(inputPath, key, restoreKeys)
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrowError(
|
||||
`Key Validation Error: Keys are limited to a maximum of 10.`
|
||||
)
|
||||
})
|
||||
|
||||
test('restore with large key should fail', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'foo'.repeat(512) // Over the 512 character limit
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
await restoreCache(inputPath, key)
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
await expect(restoreCache(paths, key)).rejects.toThrowError(
|
||||
`Key Validation Error: ${key} cannot be larger than 512 characters.`
|
||||
)
|
||||
})
|
||||
|
||||
test('restore with invalid key should fail', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'comma,comma'
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
await restoreCache(inputPath, key)
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
await expect(restoreCache(paths, key)).rejects.toThrowError(
|
||||
`Key Validation Error: ${key} cannot contain commas.`
|
||||
)
|
||||
})
|
||||
|
||||
test('restore with no cache found', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
|
||||
const infoMock = jest.spyOn(core, 'info')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const clientMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
|
||||
clientMock.mockImplementation(async () => {
|
||||
return Promise.resolve(null)
|
||||
})
|
||||
|
||||
await restoreCache(inputPath, key)
|
||||
const cacheKey = await restoreCache(paths, key)
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(cacheKey).toBe(undefined)
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}`
|
||||
)
|
||||
})
|
||||
|
||||
test('restore with server error should fail', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
|
||||
const logWarningMock = jest.spyOn(cacheUtils, 'logWarning')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const clientMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
|
||||
clientMock.mockImplementation(() => {
|
||||
throw new Error('HTTP Error Occurred')
|
||||
})
|
||||
|
||||
await restoreCache(inputPath, key)
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1)
|
||||
expect(logWarningMock).toHaveBeenCalledWith('HTTP Error Occurred')
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
await expect(restoreCache(paths, key)).rejects.toThrowError(
|
||||
'HTTP Error Occurred'
|
||||
)
|
||||
})
|
||||
|
||||
test('restore with restore keys and no cache found', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
const restoreKey = 'node-'
|
||||
|
||||
const infoMock = jest.spyOn(core, 'info')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const clientMock = jest.spyOn(cacheHttpClient, 'getCacheEntry')
|
||||
clientMock.mockImplementation(async () => {
|
||||
return Promise.resolve(null)
|
||||
})
|
||||
|
||||
await restoreCache(inputPath, key, [restoreKey])
|
||||
const cacheKey = await restoreCache(paths, key, [restoreKey])
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(cacheKey).toBe(undefined)
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||
)
|
||||
})
|
||||
|
||||
test('restore with gzip compressed cache found', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
|
||||
const infoMock = jest.spyOn(core, 'info')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const cacheEntry: ArtifactCacheEntry = {
|
||||
cacheKey: key,
|
||||
@@ -160,9 +143,10 @@ test('restore with gzip compressed cache found', async () => {
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
|
||||
await restoreCache(inputPath, key)
|
||||
const cacheKey = await restoreCache(paths, key)
|
||||
|
||||
expect(getCacheMock).toHaveBeenCalledWith([key], inputPath, {
|
||||
expect(cacheKey).toBe(key)
|
||||
expect(getCacheMock).toHaveBeenCalledWith([key], paths, {
|
||||
compressionMethod: compression
|
||||
})
|
||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
|
||||
@@ -179,16 +163,14 @@ test('restore with gzip compressed cache found', async () => {
|
||||
expect(unlinkFileMock).toHaveBeenCalledWith(archivePath)
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`)
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('restore with a pull request event and zstd compressed cache found', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
|
||||
const infoMock = jest.spyOn(core, 'info')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const cacheEntry: ArtifactCacheEntry = {
|
||||
cacheKey: key,
|
||||
@@ -220,9 +202,10 @@ test('restore with a pull request event and zstd compressed cache found', async
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
|
||||
await restoreCache(inputPath, key)
|
||||
const cacheKey = await restoreCache(paths, key)
|
||||
|
||||
expect(getCacheMock).toHaveBeenCalledWith([key], inputPath, {
|
||||
expect(cacheKey).toBe(key)
|
||||
expect(getCacheMock).toHaveBeenCalledWith([key], paths, {
|
||||
compressionMethod: compression
|
||||
})
|
||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
|
||||
@@ -237,17 +220,15 @@ test('restore with a pull request event and zstd compressed cache found', async
|
||||
expect(extractTarMock).toHaveBeenCalledWith(archivePath, compression)
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`)
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('restore with cache found for restore key', async () => {
|
||||
const inputPath = 'node_modules'
|
||||
const paths = ['node_modules']
|
||||
const key = 'node-test'
|
||||
const restoreKey = 'node-'
|
||||
|
||||
const infoMock = jest.spyOn(core, 'info')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const cacheEntry: ArtifactCacheEntry = {
|
||||
cacheKey: restoreKey,
|
||||
@@ -279,9 +260,10 @@ test('restore with cache found for restore key', async () => {
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
|
||||
await restoreCache(inputPath, key, [restoreKey])
|
||||
const cacheKey = await restoreCache(paths, key, [restoreKey])
|
||||
|
||||
expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey], inputPath, {
|
||||
expect(cacheKey).toBe(restoreKey)
|
||||
expect(getCacheMock).toHaveBeenCalledWith([key, restoreKey], paths, {
|
||||
compressionMethod: compression
|
||||
})
|
||||
expect(createTempDirectoryMock).toHaveBeenCalledTimes(1)
|
||||
@@ -298,6 +280,5 @@ test('restore with cache found for restore key', async () => {
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
)
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
102
packages/cache/__tests__/saveCache.test.ts
vendored
102
packages/cache/__tests__/saveCache.test.ts
vendored
@@ -1,4 +1,3 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import {saveCache} from '../src/cache'
|
||||
import * as cacheHttpClient from '../src/internal/cacheHttpClient'
|
||||
@@ -27,42 +26,31 @@ beforeAll(() => {
|
||||
})
|
||||
})
|
||||
|
||||
test('save with missing input outputs warning', async () => {
|
||||
const logWarningMock = jest.spyOn(cacheUtils, 'logWarning')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const inputPath = ''
|
||||
test('save with missing input should fail', async () => {
|
||||
const paths: string[] = []
|
||||
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
|
||||
|
||||
await saveCache(inputPath, primaryKey)
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
'Input required and not supplied: path'
|
||||
await expect(saveCache(paths, primaryKey)).rejects.toThrowError(
|
||||
`Path Validation Error: At least one directory or file path is required`
|
||||
)
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1)
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
test('save with large cache outputs warning', async () => {
|
||||
const logWarningMock = jest.spyOn(cacheUtils, 'logWarning')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const inputPath = 'node_modules'
|
||||
test('save with large cache outputs should fail', async () => {
|
||||
const filePath = 'node_modules'
|
||||
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
|
||||
const cachePaths = [path.resolve(inputPath)]
|
||||
const cachePaths = [path.resolve(filePath)]
|
||||
|
||||
const createTarMock = jest.spyOn(tar, 'createTar')
|
||||
|
||||
const cacheSize = 6 * 1024 * 1024 * 1024 //~6GB, over the 5GB limit
|
||||
jest.spyOn(cacheUtils, 'getArchiveFileSize').mockImplementationOnce(() => {
|
||||
return cacheSize
|
||||
})
|
||||
jest.spyOn(cacheUtils, 'getArchiveFileSize').mockReturnValue(cacheSize)
|
||||
const compression = CompressionMethod.Gzip
|
||||
const getCompressionMock = jest
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
.mockReturnValueOnce(Promise.resolve(compression))
|
||||
|
||||
await saveCache(inputPath, primaryKey)
|
||||
await expect(saveCache([filePath], primaryKey)).rejects.toThrowError(
|
||||
'Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache.'
|
||||
)
|
||||
|
||||
const archiveFolder = '/foo/bar'
|
||||
|
||||
@@ -72,20 +60,11 @@ test('save with large cache outputs warning', async () => {
|
||||
cachePaths,
|
||||
compression
|
||||
)
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1)
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
'Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache.'
|
||||
)
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('save with reserve cache failure outputs warning', async () => {
|
||||
const infoMock = jest.spyOn(core, 'info')
|
||||
const logWarningMock = jest.spyOn(cacheUtils, 'logWarning')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const inputPath = 'node_modules'
|
||||
test('save with reserve cache failure should fail', async () => {
|
||||
const paths = ['node_modules']
|
||||
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
|
||||
|
||||
const reserveCacheMock = jest
|
||||
@@ -99,33 +78,24 @@ test('save with reserve cache failure outputs warning', async () => {
|
||||
const compression = CompressionMethod.Zstd
|
||||
const getCompressionMock = jest
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
.mockReturnValueOnce(Promise.resolve(compression))
|
||||
|
||||
await saveCache(inputPath, primaryKey)
|
||||
|
||||
expect(reserveCacheMock).toHaveBeenCalledTimes(1)
|
||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, inputPath, {
|
||||
compressionMethod: compression
|
||||
})
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
await expect(saveCache(paths, primaryKey)).rejects.toThrowError(
|
||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||
)
|
||||
|
||||
expect(reserveCacheMock).toHaveBeenCalledTimes(1)
|
||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, {
|
||||
compressionMethod: compression
|
||||
})
|
||||
expect(createTarMock).toHaveBeenCalledTimes(0)
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(0)
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(0)
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('save with server error outputs warning', async () => {
|
||||
const logWarningMock = jest.spyOn(cacheUtils, 'logWarning')
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const inputPath = 'node_modules'
|
||||
test('save with server error should fail', async () => {
|
||||
const filePath = 'node_modules'
|
||||
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
|
||||
const cachePaths = [path.resolve(inputPath)]
|
||||
const cachePaths = [path.resolve(filePath)]
|
||||
|
||||
const cacheId = 4
|
||||
const reserveCacheMock = jest
|
||||
@@ -144,12 +114,13 @@ test('save with server error outputs warning', async () => {
|
||||
const compression = CompressionMethod.Zstd
|
||||
const getCompressionMock = jest
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
|
||||
await saveCache(inputPath, primaryKey)
|
||||
.mockReturnValueOnce(Promise.resolve(compression))
|
||||
|
||||
await expect(await saveCache([filePath], primaryKey)).rejects.toThrowError(
|
||||
'HTTP Error Occurred'
|
||||
)
|
||||
expect(reserveCacheMock).toHaveBeenCalledTimes(1)
|
||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, inputPath, {
|
||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], {
|
||||
compressionMethod: compression
|
||||
})
|
||||
|
||||
@@ -165,20 +136,13 @@ test('save with server error outputs warning', async () => {
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1)
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(cacheId, archiveFile)
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1)
|
||||
expect(logWarningMock).toHaveBeenCalledWith('HTTP Error Occurred')
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('save with valid inputs uploads a cache', async () => {
|
||||
const failedMock = jest.spyOn(core, 'setFailed')
|
||||
|
||||
const inputPath = 'node_modules'
|
||||
const filePath = 'node_modules'
|
||||
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
|
||||
const cachePaths = [path.resolve(inputPath)]
|
||||
const cachePaths = [path.resolve(filePath)]
|
||||
|
||||
const cacheId = 4
|
||||
const reserveCacheMock = jest
|
||||
@@ -194,10 +158,10 @@ test('save with valid inputs uploads a cache', async () => {
|
||||
.spyOn(cacheUtils, 'getCompressionMethod')
|
||||
.mockReturnValue(Promise.resolve(compression))
|
||||
|
||||
await saveCache(inputPath, primaryKey)
|
||||
await saveCache([filePath], primaryKey)
|
||||
|
||||
expect(reserveCacheMock).toHaveBeenCalledTimes(1)
|
||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, inputPath, {
|
||||
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], {
|
||||
compressionMethod: compression
|
||||
})
|
||||
|
||||
@@ -213,7 +177,5 @@ test('save with valid inputs uploads a cache', async () => {
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1)
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(cacheId, archiveFile)
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0)
|
||||
expect(getCompressionMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user