fix(terminal) config: terminal and terminalPath checked before set

This commit is contained in:
coderaiser 2017-04-25 11:56:49 +03:00
parent a260a921ba
commit 10307291a3
3 changed files with 21 additions and 10 deletions

View file

@ -180,7 +180,7 @@ function listen(prefix, socket) {
prefix: prefix + '/console',
});
config('terminal') && terminal.listen(socket, {
config('terminal') && terminal().listen(socket, {
authCheck,
prefix: prefix + '/gritty',
});

View file

@ -6,9 +6,11 @@ const config = require('./config');
const noop = () => {};
noop.listen = noop;
module.exports = getTerminal(config('terminal'));
module.exports = (arg) => {
return getTerminal(config('terminal'), arg);
};
function getTerminal(term) {
function getTerminal(term, arg) {
if (!term)
return noop;
@ -18,9 +20,12 @@ function getTerminal(term) {
result = require(config('terminalPath'));
});
if (!e)
if (!e && !arg)
return result;
if (!e)
return result(arg);
config('terminal', false);
console.log(`cloudcmd --terminal: ${e.message}`);

View file

@ -7,16 +7,19 @@ const sinon = diff(require('sinon'));
const configPath = '../../server/config';
const terminalPath = '../../server/terminal';
test('cloudcmd: terminal: disabled', (t) => {
clean(terminalPath);
stub(configPath, () => {
return false;
});
const terminal = require(terminalPath);
const fn = terminal();
const terminal = require('../../server/terminal');
t.notOk(fn, 'should return noop');
const fn = terminal();
const noop = () => {};
t.equal(String(fn), String(noop), 'should return noop');
clean(configPath);
require(configPath);
@ -28,8 +31,9 @@ test('cloudcmd: terminal: disabled: listen', (t) => {
clean(terminalPath);
stub(configPath, () => false);
const terminal = require('../../server/terminal');
const fn = terminal.listen();
const terminal = require(terminalPath);
const fn = terminal().listen();
t.notOk(fn, 'should return noop');
@ -45,7 +49,9 @@ test('cloudcmd: terminal: enabled', (t) => {
clean(terminalPath);
stub(configPath, () => true);
require(terminalPath);
const terminal = require(terminalPath);
terminal();
const msg = 'cloudcmd --terminal: path must be a string';