mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(config) manage
This commit is contained in:
parent
10ecf62ed5
commit
cc78d19fc9
2 changed files with 50 additions and 8 deletions
|
|
@ -59,15 +59,13 @@ module.exports.listen = function(socket, authCheck) {
|
|||
};
|
||||
|
||||
function manage(key, value) {
|
||||
var result;
|
||||
if (!key)
|
||||
return;
|
||||
|
||||
if (value === undefined)
|
||||
return config[key];
|
||||
|
||||
if (key)
|
||||
if (value === undefined)
|
||||
result = config[key];
|
||||
else
|
||||
config[key] = value;
|
||||
|
||||
return result;
|
||||
config[key] = value;
|
||||
}
|
||||
|
||||
function save(callback) {
|
||||
|
|
|
|||
44
test/lib/config.js
Normal file
44
test/lib/config.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
const root = '../../';
|
||||
const config = require(root + 'lib/server/config');
|
||||
|
||||
const promisify = require('es6-promisify');
|
||||
const pullout = require('pullout');
|
||||
const request = require('request');
|
||||
|
||||
const before = require('../before');
|
||||
|
||||
test('config: manage', (t) => {
|
||||
t.equal(undefined, config(), 'should return "undefined"');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('config: manage: get', (t) => {
|
||||
const editor = 'deepword';
|
||||
const conf = {
|
||||
editor
|
||||
};
|
||||
|
||||
before({config: conf}, (port, after) => {
|
||||
t.equal(editor, config('editor'), 'should get config');
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
});
|
||||
|
||||
test('config: manage: get', (t) => {
|
||||
const editor = 'deepword';
|
||||
const conf = {
|
||||
editor
|
||||
};
|
||||
|
||||
before({config: conf}, (port, after) => {
|
||||
config('editor', 'dword');
|
||||
t.equal('dword', config('editor'), 'should set config');
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue