1
0
Fork 0

Attempt to fix the test

pull/448/head
Aiqiao Yan 2020-05-12 14:47:31 -04:00
parent 1413cd0e32
commit b3c8e19a7a
5 changed files with 33 additions and 10 deletions

6
packages/cache/package-lock.json generated vendored
View File

@ -77,6 +77,12 @@
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
},
"typescript": {
"version": "3.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
"integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
"dev": true
},
"uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",

View File

@ -44,6 +44,7 @@
"uuid": "^3.3.3"
},
"devDependencies": {
"typescript": "^3.8.3",
"@types/uuid": "^3.4.5"
}
}

View File

@ -5,9 +5,23 @@ import * as cacheHttpClient from './internal/cacheHttpClient'
import {createTar, extractTar} from './internal/tar'
import {UploadOptions} from './options'
export class ValidationError extends Error {
constructor(message: string) {
super(message)
this.name = 'ValidationError'
}
}
export class ReserveCacheError extends Error {
constructor(message: string) {
super(message)
this.name = 'ReserveCacheError'
}
}
function checkPaths(paths: string[]): void {
if (!paths || paths.length === 0) {
throw new Error(
throw new ValidationError(
`Path Validation Error: At least one directory or file path is required`
)
}
@ -15,13 +29,15 @@ function checkPaths(paths: string[]): void {
function checkKey(key: string): void {
if (key.length > 512) {
throw new Error(
throw new ValidationError(
`Key Validation Error: ${key} cannot be larger than 512 characters.`
)
}
const regex = /^[^,]*$/
if (!regex.test(key)) {
throw new Error(`Key Validation Error: ${key} cannot contain commas.`)
throw new ValidationError(
`Key Validation Error: ${key} cannot contain commas.`
)
}
}
@ -47,7 +63,7 @@ export async function restoreCache(
core.debug(JSON.stringify(keys))
if (keys.length > 10) {
throw new Error(
throw new ValidationError(
`Key Validation Error: Keys are limited to a maximum of 10.`
)
}
@ -121,13 +137,13 @@ export async function saveCache(
compressionMethod
})
if (cacheId === -1) {
throw new Error(
throw new ReserveCacheError(
`Unable to reserve cache with key ${key}, another job may be creating this cache.`
)
}
core.debug(`Cache ID: ${cacheId}`)
const cachePaths = await utils.resolvePaths(paths)
const cachePaths = await utils.resolvePaths(paths)
core.debug('Cache Paths:')
core.debug(`${JSON.stringify(cachePaths)}`)

View File

@ -15,7 +15,7 @@ import * as utils from './cacheUtils'
import {CompressionMethod, SocketTimeout} from './constants'
import {
ArtifactCacheEntry,
CacheOptions,
InternalCacheOptions,
CommitCacheRequest,
ReserveCacheRequest,
ReserveCacheResponse
@ -180,7 +180,7 @@ export async function retryHttpClientResponse<T>(
export async function getCacheEntry(
keys: string[],
paths: string[],
options?: CacheOptions
options?: InternalCacheOptions
): Promise<ArtifactCacheEntry | null> {
const httpClient = createHttpClient()
const version = getCacheVersion(paths, options?.compressionMethod)
@ -258,7 +258,7 @@ export async function downloadCache(
export async function reserveCache(
key: string,
paths: string[],
options?: CacheOptions
options?: InternalCacheOptions
): Promise<number> {
const httpClient = createHttpClient()
const version = getCacheVersion(paths, options?.compressionMethod)

View File

@ -20,6 +20,6 @@ export interface ReserveCacheResponse {
cacheId: number
}
export interface CacheOptions {
export interface InternalCacheOptions {
compressionMethod?: CompressionMethod
}