mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
test(before) config, plugin -> options
This commit is contained in:
parent
4d14071ede
commit
ba93a87eed
5 changed files with 38 additions and 50 deletions
|
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue