test(cloudcmd) add

This commit is contained in:
coderaiser 2016-10-26 17:31:13 +03:00
parent 5364befc75
commit 2dbbf69a4c
2 changed files with 60 additions and 0 deletions

View file

@ -126,6 +126,7 @@
},
"devDependencies": {
"coveralls": "^2.11.6",
"es6-promisify": "^5.0.0",
"eslint": "^3.1.1",
"jscs": "^3.0.1",
"jshint": "^2.8.0",

59
test/cloudcmd.js Normal file
View file

@ -0,0 +1,59 @@
const http = require('http');
const test = require('tape');
const express = require('express');
const promisify = require('es6-promisify');
const pipe = require('pipe-io');
const wrap = (fn, ...a) => (...b) => fn(...a, ...b);
const success = (fn) => (...args) => fn(null, ...args);
const freeport = promisify(require('freeport'));
const getBody = promisify(pipe.getBody);
const get = promisify((url, fn) => {
http.get(url, success(fn));
});
const cloudcmd = require('..');
const host = '127.0.0.1';
const before = (fn) => {
const app = express();
const server = http.createServer(app);
const after = () => {
server.close();
};
const listen = (port) => {
server.listen(port, host, wrap(fn, port, after));
};
app.use(cloudcmd({
config: {
auth: false,
root: __dirname
}
}));
freeport()
.then(listen)
};
test('cloudcmd: rest: fs: path', (t) => {
before((port, after) => {
console.log(port);
get(`http://${host}:${port}/api/v1/fs`)
.then(wrap(getBody))
.then(JSON.parse)
.then((dir) => {
t.equal('/', dir.path, 'should dir path be "/"');
t.end();
after();
})
.catch((error) => {
console.log(error);
});
});
});