mirror of
https://github.com/actions/cache.git
synced 2024-11-22 09:51:25 +01:00
Merge pull request #1029 from actions/kotewar/test-case-fixes
Added StateProvider mock implementations for states
This commit is contained in:
commit
8955114d15
1 changed files with 7 additions and 6 deletions
|
@ -25,16 +25,15 @@ afterEach(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("StateProvider saves states", async () => {
|
test("StateProvider saves states", async () => {
|
||||||
|
const states = new Map<string, string>();
|
||||||
const getStateMock = jest
|
const getStateMock = jest
|
||||||
.spyOn(core, "getState")
|
.spyOn(core, "getState")
|
||||||
.mockImplementation(name =>
|
.mockImplementation(key => states.get(key) || "");
|
||||||
jest.requireActual("@actions/core").getState(name)
|
|
||||||
);
|
|
||||||
|
|
||||||
const saveStateMock = jest
|
const saveStateMock = jest
|
||||||
.spyOn(core, "saveState")
|
.spyOn(core, "saveState")
|
||||||
.mockImplementation((key, value) => {
|
.mockImplementation((key, value) => {
|
||||||
return jest.requireActual("@actions/core").saveState(key, value);
|
states.set(key, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const setOutputMock = jest
|
const setOutputMock = jest
|
||||||
|
@ -48,9 +47,11 @@ test("StateProvider saves states", async () => {
|
||||||
const stateProvider: IStateProvider = new StateProvider();
|
const stateProvider: IStateProvider = new StateProvider();
|
||||||
stateProvider.setState("stateKey", "stateValue");
|
stateProvider.setState("stateKey", "stateValue");
|
||||||
stateProvider.setState(State.CacheMatchedKey, cacheMatchedKey);
|
stateProvider.setState(State.CacheMatchedKey, cacheMatchedKey);
|
||||||
stateProvider.getState("stateKey");
|
const stateValue = stateProvider.getState("stateKey");
|
||||||
stateProvider.getCacheState();
|
const cacheStateValue = stateProvider.getCacheState();
|
||||||
|
|
||||||
|
expect(stateValue).toBe("stateValue");
|
||||||
|
expect(cacheStateValue).toBe(cacheMatchedKey);
|
||||||
expect(getStateMock).toHaveBeenCalledTimes(2);
|
expect(getStateMock).toHaveBeenCalledTimes(2);
|
||||||
expect(saveStateMock).toHaveBeenCalledTimes(2);
|
expect(saveStateMock).toHaveBeenCalledTimes(2);
|
||||||
expect(setOutputMock).toHaveBeenCalledTimes(0);
|
expect(setOutputMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
Loading…
Reference in a new issue