mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
test(cloudcmd) add
This commit is contained in:
parent
5364befc75
commit
2dbbf69a4c
2 changed files with 60 additions and 0 deletions
|
|
@ -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
59
test/cloudcmd.js
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue