setup-go/__tests__/gobin.test.ts
francisco souza 5a59f896b9
gobin: make sure GOPATH gets trimmed before use in path.join
On Windows, `go env GOPATH` keeps the end-line character, making it
unusable (see sample build failure:
https://github.com/fsouza/vod-module-sprite/runs/478762225?check_suite_focus=true#step:5:62).
2020-03-01 23:59:03 -05:00

31 lines
863 B
TypeScript

import * as gobin from '../src/gobin';
import * as path from 'path';
jest.mock('child_process');
describe('gobin', () => {
const childProcess = require('child_process');
let execFileSpy: jest.SpyInstance;
let gopath = path.join('home', 'user', 'go');
beforeEach(() => {
execFileSpy = jest.spyOn(childProcess, 'execFile');
execFileSpy.mockImplementation((_file, _args, callback) => {
callback('', {stdout: gopath, stderr: ''});
});
});
it('should return ${GOPATH}/bin', async () => {
const gobinPath = await gobin.getGOBIN('...');
expect(gobinPath).toBe(path.join(gopath, 'bin'));
});
it('should trim ${GOPATH} before using it', async () => {
let trimmed = gopath;
gopath = `${gopath}\r\n`;
const gobinPath = await gobin.getGOBIN('...');
expect(gobinPath).toBe(path.join(trimmed, 'bin'));
});
});