mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-23 03:45:31 +00:00
Add unit tests for restore (#62)
* Move archive file size to utils * Disable net connect with nock * Add unit tests for restore * Fix test names and test URL
This commit is contained in:
parent
ecf6eea708
commit
4b0709a0d5
8 changed files with 469 additions and 26 deletions
|
@ -2,7 +2,6 @@ import * as core from "@actions/core";
|
|||
import { exec } from "@actions/exec";
|
||||
import * as io from "@actions/io";
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import * as cacheHttpClient from "./cacheHttpClient";
|
||||
|
@ -72,6 +71,9 @@ async function run() {
|
|||
// Download the cache from the cache entry
|
||||
await cacheHttpClient.downloadCache(cacheEntry, archivePath);
|
||||
|
||||
const archiveFileSize = utils.getArchiveFileSize(archivePath);
|
||||
core.debug(`File Size: ${archiveFileSize}`);
|
||||
|
||||
io.mkdirP(cachePath);
|
||||
|
||||
// http://man7.org/linux/man-pages/man1/tar.1.html
|
||||
|
@ -89,9 +91,6 @@ async function run() {
|
|||
const tarPath = await io.which("tar", true);
|
||||
core.debug(`Tar Path: ${tarPath}`);
|
||||
|
||||
const archiveFileSize = fs.statSync(archivePath).size;
|
||||
core.debug(`File Size: ${archiveFileSize}`);
|
||||
|
||||
await exec(`"${tarPath}"`, args);
|
||||
|
||||
const isExactKeyMatch = utils.isExactKeyMatch(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as io from "@actions/io";
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import * as uuidV4 from "uuid/v4";
|
||||
|
@ -32,6 +33,10 @@ export async function createTempDirectory(): Promise<string> {
|
|||
return dest;
|
||||
}
|
||||
|
||||
export function getArchiveFileSize(path: string): number {
|
||||
return fs.statSync(path).size;
|
||||
}
|
||||
|
||||
export function isExactKeyMatch(
|
||||
key: string,
|
||||
cacheResult?: ArtifactCacheEntry
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import { Inputs } from "../constants";
|
||||
|
||||
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
|
||||
function getInputName(name: string): string {
|
||||
return `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
|
||||
}
|
||||
|
@ -5,3 +8,22 @@ function getInputName(name: string): string {
|
|||
export function setInput(name: string, value: string) {
|
||||
process.env[getInputName(name)] = value;
|
||||
}
|
||||
|
||||
interface CacheInput {
|
||||
path: string;
|
||||
key: string;
|
||||
restoreKeys?: string[];
|
||||
}
|
||||
|
||||
export function setInputs(input: CacheInput) {
|
||||
setInput(Inputs.Path, input.path);
|
||||
setInput(Inputs.Key, input.key);
|
||||
input.restoreKeys &&
|
||||
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
||||
}
|
||||
|
||||
export function clearInputs() {
|
||||
delete process.env[getInputName(Inputs.Path)];
|
||||
delete process.env[getInputName(Inputs.Key)];
|
||||
delete process.env[getInputName(Inputs.RestoreKeys)];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue