stateinputprovider with pending test cases fix

This commit is contained in:
Sankalp Kotewar 2023-01-02 07:29:20 +00:00 committed by GitHub
parent 365406cb70
commit 5b7eeecaeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 28 deletions

View file

@ -28,9 +28,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
// If restore has stored a primary key in state, reuse that
// Else re-evaluate from inputs
const primaryKey =
stateProvider.getState(State.CachePrimaryKey) ||
core.getInput(Inputs.Key);
const primaryKey = stateProvider.getState(State.CachePrimaryKey);
if (!primaryKey) {
utils.logWarning(`Key is not specified.`);

View file

@ -1,6 +1,6 @@
import * as core from "@actions/core";
import { Outputs, State } from "./constants";
import { Inputs, Outputs, State } from "./constants";
export interface IStateProvider {
setState(key: string, value: string): void;
@ -33,6 +33,10 @@ export class StateProvider extends StateProviderBase {
}
export class NullStateProvider extends StateProviderBase {
stateToInputMap = new Map<string, string>([
[State.CachePrimaryKey, Inputs.Key]
]);
stateToOutputMap = new Map<string, string>([
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
@ -41,6 +45,8 @@ export class NullStateProvider extends StateProviderBase {
setState = (key: string, value: string) => {
core.setOutput(this.stateToOutputMap.get(key) as string, value);
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getState = (key: string) => "";
getState = (key: string) => {
return core.getInput(this.stateToInputMap.get(key) as string);
};
}

View file

@ -9,6 +9,10 @@ export function setInput(name: string, value: string): void {
process.env[getInputName(name)] = value;
}
export function getInput(name: string): string {
return process.env[getInputName(name)] as string;
}
interface CacheInput {
path: string;
key: string;