mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 02:16:45 +00:00
integrate the cache logic to entry points
This commit is contained in:
parent
fef7d5836a
commit
4a7bf9903c
8 changed files with 116152 additions and 578 deletions
51
__tests__/cleanup-java.test.ts
Normal file
51
__tests__/cleanup-java.test.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { mkdtempSync } from 'fs';
|
||||
import { tmpdir } from 'os';
|
||||
import { join } from 'path';
|
||||
import { restore, save } from '../src/cache';
|
||||
import { run as cleanup } from '../src/cleanup-java';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
import * as cache from '@actions/cache';
|
||||
|
||||
describe('cleanup', () => {
|
||||
let spyInfo: jest.SpyInstance<void, Parameters<typeof core.info>>;
|
||||
let spyWarning: jest.SpyInstance<void, Parameters<typeof core.warning>>;
|
||||
|
||||
let spyCacheSave: jest.SpyInstance<
|
||||
ReturnType<typeof cache.saveCache>,
|
||||
Parameters<typeof cache.saveCache>
|
||||
>;
|
||||
beforeEach(() => {
|
||||
spyInfo = jest.spyOn(core, 'info');
|
||||
spyWarning = jest.spyOn(core, 'warning');
|
||||
spyCacheSave = jest.spyOn(cache, 'saveCache');
|
||||
});
|
||||
|
||||
it('does not fail nor warn even when the save provess throws a ReserveCacheError', async () => {
|
||||
spyCacheSave.mockImplementation((paths: string[], key: string) =>
|
||||
Promise.reject(
|
||||
new cache.ReserveCacheError(
|
||||
'Unable to reserve cache with key, another job may be creating this cache.'
|
||||
)
|
||||
)
|
||||
);
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
return name === 'cache' ? 'gradle' : '';
|
||||
});
|
||||
await cleanup();
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('does not fail even though the save process throws error', async () => {
|
||||
spyCacheSave.mockImplementation((paths: string[], key: string) =>
|
||||
Promise.reject(new Error('Unexpected error'))
|
||||
);
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
return name === 'cache' ? 'gradle' : '';
|
||||
});
|
||||
await cleanup();
|
||||
expect(spyCacheSave).toBeCalled();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue