diff --git a/package.json b/package.json index 850176ed..eedb2be2 100644 --- a/package.json +++ b/package.json @@ -137,6 +137,7 @@ "nsp": "^2.2.1", "nyc": "^8.1.0", "place": "^1.1.4", + "pullout": "^1.0.0", "recess": "^1.1.9", "redrun": "^5.0.0", "shortdate": "^1.0.1", diff --git a/test/cloudcmd.js b/test/cloudcmd.js index a2da439e..2e3b2ba8 100644 --- a/test/cloudcmd.js +++ b/test/cloudcmd.js @@ -5,14 +5,14 @@ const fs = require('fs'); const test = require('tape'); const express = require('express'); const promisify = require('es6-promisify'); -const pipe = require('pipe-io'); +const pullout = require('pullout'); const wrap = (fn, ...a) => (...b) => fn(...a, ...b); +const warp = (fn, ...a) => (...b) => fn(...b, ...a); const success = (fn) => (...args) => fn(null, ...args); const freeport = promisify(require('freeport')); -const getBody = promisify(pipe.getBody); -const getBuffer = promisify(_getBuffer); +const _pullout = promisify(pullout); const get = promisify((url, fn) => { http.get(url, success(fn)); @@ -48,7 +48,7 @@ test('cloudcmd: rest: fs: path', (t) => { before((port, after) => { console.log(port); get(`http://${host}:${port}/api/v1/fs`) - .then(wrap(getBody)) + .then(warp(_pullout, 'string')) .then(JSON.parse) .then((dir) => { t.equal('/', dir.path, 'should dir path be "/"'); @@ -65,7 +65,7 @@ test('cloudcmd: rest: pack', (t) => { before((port, after) => { console.log(port); get(`http://${host}:${port}/api/v1/pack/fixture/pack`) - .then(wrap(getBuffer)) + .then(warp(_pullout, 'buffer')) .then((pack) => { const fixture = fs.readFileSync(__dirname + '/fixture/pack.tar.gz'); t.ok(fixture.compare(pack), 'should pack data'); @@ -78,33 +78,3 @@ test('cloudcmd: rest: pack', (t) => { }); }); -/** - * get body of readStream - * - * @param readStream - * @param callback - */ -function _getBuffer(readStream, callback) { - var error, - body = []; - - assert(readStream, 'could not be empty!'); - assert(callback, 'could not be empty!'); - - readStream.on('data', onData); - readStream.on('error', onEnd); - readStream.on('end', onEnd); - - function onData(chunk) { - body.push(chunk); - } - - function onEnd(error) { - readStream.removeListener('data', onData); - readStream.removeListener('error', onEnd); - readStream.removeListener('end', onEnd); - - callback(error, Buffer.from(body)); - } -} -