test(rest) cp: coverage

This commit is contained in:
coderaiser 2018-03-07 17:49:35 +02:00
parent d6bd52e866
commit dadc294765
4 changed files with 102 additions and 5 deletions

1
test/fixture/cp.txt Normal file
View file

@ -0,0 +1 @@
hello

51
test/rest/cp.js Normal file
View file

@ -0,0 +1,51 @@
'use strict';
const {
join,
} = require('path');
const fs = require('fs');
const test = require('tape');
const {promisify} = require('es6-promisify');
const pullout = require('pullout');
const request = require('request');
const before = require('../before');
const rimraf = require('rimraf');
const fixtureDir = join(__dirname, '..', 'fixture') + '/';
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
const _pullout = promisify(pullout);
const put = promisify((url, json, fn) => {
fn(null, request.put(url, {
json,
}));
});
test('cloudcmd: rest: cp', (t) => {
before({}, (port, after) => {
const tmp = join(fixtureDir, 'tmp');
const files = {
from: '/fixture/',
to: '/fixture/tmp',
names: [
'cp.txt'
]
};
fs.mkdirSync(tmp);
put(`http://localhost:${port}/api/v1/cp`, files)
.then(warp(_pullout, 'string'))
.then((body) => {
t.equal(body, 'copy: ok("["cp.txt"]")', 'should return result');
t.end();
rimraf.sync(tmp);
after();
})
.catch(console.error);
});
});

View file

@ -4,11 +4,9 @@ const test = require('tape');
const {promisify} = require('es6-promisify');
const pullout = require('pullout');
const request = require('request');
const before = require('../before');
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
const _pullout = promisify(pullout);
const get = promisify((url, fn) => {
@ -25,9 +23,7 @@ test('cloudcmd: rest: fs: path', (t) => {
t.end();
after();
})
.catch((error) => {
console.log(error);
});
.catch(console.error);
});
});

49
test/rest/rest.js Normal file
View file

@ -0,0 +1,49 @@
'use strict';
const test = require('tape');
const rest = require('../../server/rest');
const {
_formatMsg,
_getWin32RootMsg,
_isRootWin32,
_isRootAll,
} = rest;
test('rest: formatMsg', (t) => {
const result = _formatMsg('hello', 'world');
t.equal(result, 'hello: ok("world")', 'should be equal');
t.end();
});
test('rest: formatMsg: json', (t) => {
const result = _formatMsg('hello', {
name: 'world',
});
t.equal(result, 'hello: ok("{"name":"world"}")', 'should parse json');
t.end();
});
test('rest: getWin32RootMsg', (t) => {
const {message} = _getWin32RootMsg();
t.equal(message,'Could not copy from/to root on windows!', 'should return error');
t.end();
});
test('rest: isRootWin32', (t) => {
const result = _isRootWin32('/');
t.notOk(result, 'should equal');
t.end();
});
test('rest: isRootAll', (t) => {
const result = _isRootAll(['/', '/h']);
t.notOk(result, 'should equal');
t.end();
});