Skip to content

Commit 5b3907e

Browse files
author
IvanZosimov
committed
Merge branch 'main' of https://github.com/akv-platform/setup-go into apply-reusable-workflows
2 parents e01c74b + c0e82e3 commit 5b3907e

File tree

4 files changed

+5118
-5084
lines changed

4 files changed

+5118
-5084
lines changed

__tests__/cache-utils.test.ts

+39-3
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 => {
@@ -162,18 +197,19 @@ describe('isCacheFeatureAvailable', () => {
162197
expect(functionResult).toBeFalsy();
163198
});
164199

165-
it('should throw when cache feature is unavailable and GHES is used', () => {
200+
it('should warn when cache feature is unavailable and GHES is used', () => {
166201
//Arrange
167202
isFeatureAvailableSpy.mockImplementation(() => {
168203
return false;
169204
});
170205

171206
process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';
172207

173-
let errorMessage =
208+
let warningMessage =
174209
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.';
175210

176211
//Act + Assert
177-
expect(() => cacheUtils.isCacheFeatureAvailable()).toThrow(errorMessage);
212+
expect(cacheUtils.isCacheFeatureAvailable()).toBeFalsy();
213+
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
178214
});
179215
});

0 commit comments

Comments
 (0)