Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'main' of https://github.com/akv-platform/setup-go into …
…apply-reusable-workflows
  • Loading branch information
IvanZosimov committed Dec 19, 2022
2 parents e01c74b + c0e82e3 commit 5b3907e
Show file tree
Hide file tree
Showing 4 changed files with 5,118 additions and 5,084 deletions.
42 changes: 39 additions & 3 deletions __tests__/cache-utils.test.ts
Expand Up @@ -93,6 +93,41 @@ describe('getCacheDirectoryPath', () => {
.then(data => expect(data).toEqual(expectedResult));
});

it('should return path to the cache folder if one command return empty str', async () => {
//Arrange
getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
resolve({exitCode: 0, stdout: 'path/to/cache/folder', stderr: ''});
});
});

getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
resolve({exitCode: 0, stdout: '', stderr: ''});
});
});

const expectedResult = ['path/to/cache/folder'];

//Act + Assert
return cacheUtils
.getCacheDirectoryPath(validPackageManager)
.then(data => expect(data).toEqual(expectedResult));
});

it('should throw if the both commands return empty str', async () => {
getExecOutputSpy.mockImplementation((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
resolve({exitCode: 10, stdout: '', stderr: ''});
});
});

//Act + Assert
expect(async () => {
await cacheUtils.getCacheDirectoryPath(validPackageManager);
}).rejects.toThrow();
});

it('should throw if the specified package name is invalid', async () => {
getExecOutputSpy.mockImplementation((commandLine: string) => {
return new Promise<exec.ExecOutput>(resolve => {
Expand Down Expand Up @@ -162,18 +197,19 @@ describe('isCacheFeatureAvailable', () => {
expect(functionResult).toBeFalsy();
});

it('should throw when cache feature is unavailable and GHES is used', () => {
it('should warn when cache feature is unavailable and GHES is used', () => {
//Arrange
isFeatureAvailableSpy.mockImplementation(() => {
return false;
});

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

let errorMessage =
let warningMessage =
'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.';

//Act + Assert
expect(() => cacheUtils.isCacheFeatureAvailable()).toThrow(errorMessage);
expect(cacheUtils.isCacheFeatureAvailable()).toBeFalsy();
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
});
});

0 comments on commit 5b3907e

Please sign in to comment.