test(before) config, plugin -> options

This commit is contained in:
coderaiser 2016-11-29 15:41:31 +02:00
parent 4d14071ede
commit ba93a87eed
5 changed files with 38 additions and 50 deletions

View file

@ -14,8 +14,12 @@ const {assign} = Object;
const pathConfig = os.homedir() + '/.cloudcmd.json';
const currentConfig = readjson.sync.try(pathConfig);
module.exports = (_config, _plugins, _fn) => {
const {config, plugins, fn} = parse(_config, _plugins, _fn);
module.exports = (options, fn = options) => {
if (fn === options) {
options = {};
}
const {config, plugins} = options;
const app = express();
const server = http.createServer(app);
@ -46,25 +50,3 @@ function defaultConfig() {
};
}
function parse(config, plugins, fn) {
if (typeof plugins === 'undefined')
return {
fn: config,
config: undefined,
plugins: undefined
}
if (typeof fn === 'undefined')
return {
config,
fn: plugins,
plugins: undefined
}
return {
config,
plugins,
fn
};
}

View file

@ -21,7 +21,7 @@ test('cloudcmd: console: enabled by default', (t) => {
test('cloudcmd: console: enabled', (t) => {
const config = {console: true};
before(config, (port, after) => {
before({config}, (port, after) => {
const socket = io(`http://localhost:${port}/console`)
socket.once('data', (data) => {
@ -36,7 +36,7 @@ test('cloudcmd: console: enabled', (t) => {
test('cloudcmd: console: disabled', (t) => {
const config = {console: false};
before(config, (port, after) => {
before({config}, (port, after) => {
const socket = io(`http://localhost:${port}/console`);
socket.on('error', (error) => {

View file

@ -17,10 +17,9 @@ const get = promisify((url, fn) => {
});
test('cloudcmd: plugins', (t) => {
const config = {};
const plugins = [];
before(config, plugins, (port, after) => {
before({plugins}, (port, after) => {
get(`http://localhost:${port}/plugins.js`)
.then(warp(_pullout, 'string'))
.then((content) => {
@ -35,12 +34,11 @@ test('cloudcmd: plugins', (t) => {
});
test('cloudcmd: plugins', (t) => {
const config = {};
const plugins = [
__filename
];
before(config, plugins, (port, after) => {
before({plugins}, (port, after) => {
get(`http://localhost:${port}/plugins.js`)
.then(warp(_pullout, 'string'))
.then((content) => {
@ -56,7 +54,6 @@ test('cloudcmd: plugins', (t) => {
});
test('cloudcmd: plugins: load error', (t) => {
const config = {};
const noEntry = __filename + Math.random();
const plugins = [
__filename,
@ -65,7 +62,7 @@ test('cloudcmd: plugins: load error', (t) => {
const msg = `ENOENT: no such file or directory, open '${noEntry}'`;
before(config, plugins, (port, after) => {
before({plugins}, (port, after) => {
get(`http://localhost:${port}/plugins.js`)
.then(warp(_pullout, 'string'))
.then((content) => {

View file

@ -57,9 +57,11 @@ test('cloudcmd: rest: config: patch', (t) => {
});
test('cloudcmd: rest: config: patch: no configDialog', (t) => {
const configDialog = false;
const config = {
configDialog: false
};
before({configDialog}, (port, after) => {
before({config}, (port, after) => {
const json = {
ip: null
};
@ -78,9 +80,11 @@ test('cloudcmd: rest: config: patch: no configDialog', (t) => {
});
test('cloudcmd: rest: config: patch: no configDialog: statusCode', (t) => {
const configDialog = false;
const config = {
configDialog: false
};
before({configDialog}, (port, after) => {
before({config}, (port, after) => {
const json = {
ip: null
};

View file

@ -33,8 +33,9 @@ const put = promisify((options, fn) => {
});
test('cloudcmd: rest: pack: tar: get', (t) => {
const options = {packer: 'tar'};
before(options, (port, after) => {
const config = {packer: 'tar'};
before({config}, (port, after) => {
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
.then((pack) => {
const extract = tar.extract();
@ -57,8 +58,9 @@ test('cloudcmd: rest: pack: tar: get', (t) => {
});
test('cloudcmd: rest: pack: tar: put: file', (t) => {
const options = {packer: 'tar'};
before(options, (port, after) => {
const config = {packer: 'tar'};
before({config}, (port, after) => {
const name = String(Math.random()) + '.tar.gz';
const options = getPackOptions(port, name);
@ -110,8 +112,9 @@ test('cloudcmd: rest: pack: tar: put: response', (t) => {
});
test('cloudcmd: rest: pack: tar: put: error', (t) => {
const options = {packer: 'tar'};
before(options, (port, after) => {
const config = {packer: 'tar'};
before({config}, (port, after) => {
const options = getPackOptions(port, 'name', [
'not found'
]);
@ -131,8 +134,8 @@ test('cloudcmd: rest: pack: tar: put: error', (t) => {
});
test('cloudcmd: rest: pack: zip: get', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
const config = {packer: 'zip'};
before({config}, (port, after) => {
get(`http://localhost:${port}/api/v1/pack/fixture/pack`)
.then(_pullout)
.then((pack) => {
@ -147,8 +150,9 @@ test('cloudcmd: rest: pack: zip: get', (t) => {
});
test('cloudcmd: rest: pack: zip: put: file', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
const config = {packer: 'zip'};
before({config}, (port, after) => {
const name = String(Math.random()) + '.zip';
const options = getPackOptions(port, name);
@ -170,8 +174,9 @@ test('cloudcmd: rest: pack: zip: put: file', (t) => {
});
test('cloudcmd: rest: pack: zip: put: response', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
const config = {packer: 'zip'};
before({config}, (port, after) => {
const name = String(Math.random()) + '.zip';
const options = getPackOptions(port, name);
@ -192,8 +197,8 @@ test('cloudcmd: rest: pack: zip: put: response', (t) => {
});
test('cloudcmd: rest: pack: zip: put: error', (t) => {
const options = {packer: 'zip'};
before(options, (port, after) => {
const config = {packer: 'zip'};
before({config}, (port, after) => {
const options = getPackOptions(port, 'name', [
'not found'
]);