mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-16 20:59:28 +00:00
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
const fs = require('fs');
|
|
const common = require('../../src/common');
|
|
const verifyAndPlaceBinary = require('../../src/assets/binary');
|
|
const path = require('path');
|
|
|
|
jest.mock('fs');
|
|
jest.mock('../../src/common');
|
|
|
|
describe('verifyAndPlaceBinary()', () => {
|
|
let callback;
|
|
|
|
beforeEach(() => {
|
|
callback = jest.fn();
|
|
});
|
|
|
|
it('should call callback with error if binary downloaded differs from config', () => {
|
|
fs.existsSync.mockReturnValueOnce(false);
|
|
|
|
verifyAndPlaceBinary('command', './bin', callback);
|
|
|
|
expect(callback).toHaveBeenCalledWith('Downloaded binary does not contain the binary specified in configuration - command');
|
|
});
|
|
|
|
it('should call callback with error if installation path cannot be found', () => {
|
|
const error = new Error();
|
|
|
|
fs.existsSync.mockReturnValueOnce(true);
|
|
common.getInstallationPath.mockImplementationOnce((cb) => cb(error));
|
|
|
|
verifyAndPlaceBinary('command', './bin', callback);
|
|
|
|
expect(callback).toHaveBeenCalledWith(error);
|
|
});
|
|
|
|
it('should call callback with null on success', () => {
|
|
fs.existsSync.mockReturnValueOnce(true);
|
|
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
|
|
|
|
verifyAndPlaceBinary('command', './bin', callback);
|
|
|
|
expect(callback).toHaveBeenCalledWith(null);
|
|
});
|
|
|
|
it('should move the binary to installation directory', () => {
|
|
fs.existsSync.mockReturnValueOnce(true);
|
|
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
|
|
|
|
verifyAndPlaceBinary('command', './bin', callback);
|
|
|
|
expect(fs.copyFileSync).toHaveBeenCalledWith(path.join('bin', 'command'), path.sep + path.join('usr', 'local', 'bin', 'command'));
|
|
});
|
|
});
|