Add tests that fail without this change and pass with it

This commit is contained in:
Leigh McCulloch 2020-12-04 09:34:42 -08:00
parent 7267bd9425
commit 82e49b01e9
No known key found for this signature in database
GPG key ID: 02EA740790312BC4
3 changed files with 61 additions and 0 deletions

View file

@ -427,6 +427,61 @@ describe('setup-go', () => {
); );
}); });
it('adds GOBIN to PATH when go-version specified', async () => {
inputs['go-version'] = '1.13.0';
let toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath);
whichSpy.mockImplementation(async () => {
return '/usr/local/go/bin/go';
});
execSpy.mockImplementation(() => {
return '/Users/testuser/go';
});
mkdirpSpy.mockImplementation(async () => { });
existsSpy.mockImplementation(path => {
return false;
});
await main.run();
expect(logSpy).toHaveBeenCalledWith(`Setup go stable version spec 1.13.0`);
expect(logSpy).toHaveBeenCalledWith(`Added go to the path`);
expect(logSpy).toHaveBeenCalledWith(`Added GOBIN to the path`);
let expPath = "/Users/testuser/go/bin";
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('adds GOBIN to PATH when go-version not specified', async () => {
let toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath);
whichSpy.mockImplementation(async () => {
return '/usr/local/go/bin/go';
});
execSpy.mockImplementation(() => {
return '/Users/testuser/go';
});
mkdirpSpy.mockImplementation(async () => { });
existsSpy.mockImplementation(path => {
return false;
});
await main.run();
expect(logSpy).toHaveBeenCalledWith(`Setup go stable version spec undefined`);
expect(logSpy).toHaveBeenCalledWith(`Added GOBIN to the path`);
let expPath = "/Users/testuser/go/bin";
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('does not add BIN if go is not in path', async () => { it('does not add BIN if go is not in path', async () => {
whichSpy.mockImplementation(async () => { whichSpy.mockImplementation(async () => {
return ''; return '';

3
dist/index.js vendored
View file

@ -1511,6 +1511,9 @@ function run() {
// add gobin to path // add gobin to path
let added = yield addBinToPath(); let added = yield addBinToPath();
core.debug(`add bin ${added}`); core.debug(`add bin ${added}`);
if (added) {
core.info('Added GOBIN to the path');
}
// add problem matchers // add problem matchers
const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json'); const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json');
core.info(`##[add-matcher]${matchersPath}`); core.info(`##[add-matcher]${matchersPath}`);

View file

@ -36,6 +36,9 @@ export async function run() {
// add gobin to path // add gobin to path
let added = await addBinToPath(); let added = await addBinToPath();
core.debug(`add bin ${added}`); core.debug(`add bin ${added}`);
if (added) {
core.info('Added GOBIN to the path');
}
// add problem matchers // add problem matchers
const matchersPath = path.join(__dirname, '..', 'matchers.json'); const matchersPath = path.join(__dirname, '..', 'matchers.json');