From 32371bf2a7c107f75d31d763d119c085f557c474 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 23 Nov 2016 10:57:54 +0200 Subject: [PATCH] test(pack) add tar-stream, gunzip-maybe --- package.json | 2 ++ test/rest/pack.js | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6d80bcb2..45792829 100644 --- a/package.json +++ b/package.json @@ -135,6 +135,7 @@ "coveralls": "^2.11.6", "es6-promisify": "^5.0.0", "eslint": "^3.1.1", + "gunzip-maybe": "^1.3.1", "jscs": "^3.0.1", "jshint": "^2.8.0", "minor": "^1.2.2", @@ -151,6 +152,7 @@ "stylelint": "^7.0.2", "stylelint-config-standard": "^15.0.0", "tape": "^4.4.0", + "tar-stream": "^1.5.2", "version-io": "^1.2.5", "yaspeller": "^3.0.0" }, diff --git a/test/rest/pack.js b/test/rest/pack.js index dfb93035..94047b9e 100644 --- a/test/rest/pack.js +++ b/test/rest/pack.js @@ -7,6 +7,8 @@ const test = require('tape'); const promisify = require('es6-promisify'); const pullout = require('pullout'); const request = require('request'); +const tar = require('tar-stream'); +const gunzip = require('gunzip-maybe'); const before = require('../before'); @@ -34,11 +36,19 @@ test('cloudcmd: rest: pack: tar: get', (t) => { const options = {packer: 'tar'}; before(options, (port, after) => { get(`http://localhost:${port}/api/v1/pack/fixture/pack`) - .then(_pullout) .then((pack) => { - t.equal(Buffer.byteLength(fixture.tar), Buffer.byteLength(pack), 'should pack data'); - t.end(); - after(); + const extract = tar.extract(); + + pack.pipe(gunzip()).pipe(extract); + + extract.on('entry', (header, stream) => { + pullout(stream, 'string', (e, data) => { + const file = fs.readFileSync(__dirname + '/../fixture/pack', 'utf8'); + t.equal(file, data, 'should pack data'); + t.end(); + after(); + }); + }); }) .catch((error) => { console.log(error); @@ -53,15 +63,23 @@ test('cloudcmd: rest: pack: tar: put: file', (t) => { const options = getPackOptions(port, name); put(options) - .then(warp(_pullout, 'string')) + .then(_pullout) .then(() => { - const file = fs.readFileSync(__dirname + '/../' + name, 'utf8'); + const file = fs.createReadStream(__dirname + '/../' + name); + const extract = tar.extract(); - fs.unlinkSync(`${__dirname}/../${name}`); - t.equal(Buffer.byteLength(file), Buffer.byteLength(fixture.tar), 'should create archive'); + file.pipe(gunzip()).pipe(extract); - t.end(); - after(); + extract.on('entry', (header, stream) => { + pullout(stream, 'string', (e, data) => { + const file = fs.readFileSync(__dirname + '/../fixture/pack', 'utf8'); + fs.unlinkSync(`${__dirname}/../${name}`); + + t.equal(file, data, 'should create archive'); + t.end(); + after(); + }); + }); }) .catch((error) => { console.log(error);