Skip to content

Commit 1710640

Browse files
Allow to use only GOCACHE for cache (actions#305)
1 parent bb5ff97 commit 1710640

File tree

4 files changed

+5089
-5054
lines changed

4 files changed

+5089
-5054
lines changed

__tests__/cache-utils.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,41 @@ describe('getCacheDirectoryPath', () => {
9393
.then(data => expect(data).toEqual(expectedResult));
9494
});
9595

96+
it('should return path to the cache folder if one command return empty str', async () => {
97+
//Arrange
98+
getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
99+
return new Promise<exec.ExecOutput>(resolve => {
100+
resolve({exitCode: 0, stdout: 'path/to/cache/folder', stderr: ''});
101+
});
102+
});
103+
104+
getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
105+
return new Promise<exec.ExecOutput>(resolve => {
106+
resolve({exitCode: 0, stdout: '', stderr: ''});
107+
});
108+
});
109+
110+
const expectedResult = ['path/to/cache/folder'];
111+
112+
//Act + Assert
113+
return cacheUtils
114+
.getCacheDirectoryPath(validPackageManager)
115+
.then(data => expect(data).toEqual(expectedResult));
116+
});
117+
118+
it('should throw if the both commands return empty str', async () => {
119+
getExecOutputSpy.mockImplementation((commandLine: string) => {
120+
return new Promise<exec.ExecOutput>(resolve => {
121+
resolve({exitCode: 10, stdout: '', stderr: ''});
122+
});
123+
});
124+
125+
//Act + Assert
126+
expect(async () => {
127+
await cacheUtils.getCacheDirectoryPath(validPackageManager);
128+
}).rejects.toThrow();
129+
});
130+
96131
it('should throw if the specified package name is invalid', async () => {
97132
getExecOutputSpy.mockImplementation((commandLine: string) => {
98133
return new Promise<exec.ExecOutput>(resolve => {

0 commit comments

Comments
 (0)