Add cli tests

This commit is contained in:
Nick O'Leary
2014-09-23 00:14:30 +01:00
parent af0b740fbd
commit 723a3e628e
4 changed files with 88 additions and 4 deletions

View File

@@ -44,6 +44,10 @@ function save() {
}
fs.writeFileSync(configFile,JSON.stringify(config,null,4));
}
module.exports = {};
module.exports = {
unload: function() {
config = null;
}
};
module.exports.__defineGetter__('target',function() { load(); return config.target|| "http://localhost:1880" });
module.exports.__defineSetter__('target',function(v) { load(); config.target = v; save();});

View File

@@ -27,7 +27,18 @@ module.exports = function(path, options) {
options.headers['content-type'] = 'application/json';
}
options.url = basePath+path;
request(options, function(error,response,body) {
// Pull out the request function so we can stub it in the tests
var requestFunc = request.get;
if (options.method == 'PUT') {
requestFunc = request.put;
} else if (options.method == 'POST') {
requestFunc = request.post;
} else if (options.method == 'DELETE') {
requestFunc = request.delete;
}
requestFunc(options, function(error,response,body) {
if (!error && response.statusCode == 200) {
resolve(JSON.parse(body));
} else if (error) {