2020-03-01 21:18:28 -05:00
|
|
|
import * as gobin from '../src/gobin';
|
2020-03-01 21:34:51 -05:00
|
|
|
import * as path from 'path';
|
2020-03-01 21:18:28 -05:00
|
|
|
|
|
|
|
jest.mock('child_process');
|
|
|
|
|
|
|
|
describe('gobin', () => {
|
|
|
|
const childProcess = require('child_process');
|
|
|
|
|
|
|
|
let execSpy: jest.SpyInstance;
|
2020-03-01 21:34:51 -05:00
|
|
|
let gopath = path.join('home', 'user', 'go');
|
2020-03-01 21:18:28 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
execSpy = jest.spyOn(childProcess, 'exec');
|
|
|
|
execSpy.mockImplementation((_command, callback) => {
|
2020-03-01 21:34:51 -05:00
|
|
|
callback('', {stdout: gopath, stderr: ''});
|
2020-03-01 21:18:28 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return ${GOPATH}/bin', async () => {
|
|
|
|
const gobinPath = await gobin.getGOBIN('...');
|
2020-03-01 21:34:51 -05:00
|
|
|
expect(gobinPath).toBe(path.join(gopath, 'bin'));
|
2020-03-01 21:18:28 -05:00
|
|
|
});
|
|
|
|
});
|