From 475afe6a18ccf668a10be0c8d6f3726dbb0c4ac8 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 21 Dec 2013 01:03:48 +0100 Subject: [PATCH] basic test cases --- test/extract.js | 41 +++++++++++++++++++++++++++++++++++++ test/fixtures/index.js | 3 +++ test/fixtures/one-file.tar | Bin 0 -> 2048 bytes test/pack.js | 27 ++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 test/extract.js create mode 100644 test/fixtures/index.js create mode 100644 test/fixtures/one-file.tar create mode 100644 test/pack.js diff --git a/test/extract.js b/test/extract.js new file mode 100644 index 0000000..f144fb1 --- /dev/null +++ b/test/extract.js @@ -0,0 +1,41 @@ +var test = require('tap').test; +var tar = require('../index'); +var fixtures = require('./fixtures'); +var concat = require('concat-stream'); +var fs = require('fs'); + +test('one-file', function(t) { + t.plan(3); + + var extract = tar.extract(); + var noEntries = false; + + extract.on('entry', function(header, stream, callback) { + t.deepEqual(header, { + name: 'test.txt', + mode: 0644, + uid: 501, + gid: 20, + size: 12, + mtime: new Date(1387580181000), + type: 'file', + linkname: null, + uname: 'maf', + gname: 'staff', + devmajor: 0, + devminor: 0 + }); + + stream.pipe(concat(function(data) { + noEntries = true; + t.same(data.toString(), 'hello world\n'); + callback(); + })); + }); + + extract.on('finish', function() { + t.ok(noEntries); + }); + + extract.end(fs.readFileSync(fixtures.ONE_FILE_TAR)); +}); \ No newline at end of file diff --git a/test/fixtures/index.js b/test/fixtures/index.js new file mode 100644 index 0000000..5a59c7e --- /dev/null +++ b/test/fixtures/index.js @@ -0,0 +1,3 @@ +var path = require('path'); + +exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar'); \ No newline at end of file diff --git a/test/fixtures/one-file.tar b/test/fixtures/one-file.tar new file mode 100644 index 0000000000000000000000000000000000000000..12dbd217ec7e9cb8b24ebeb2fa0851c55a2ac469 GIT binary patch literal 2048 zcmXR(EiTb3sVHHfAuup7Ff%bxU;xtQW~N};zzD(z3ITzkiGrb#k*TSniK&T^se*x_ zk*NVlo`!CM8(msll2~M5z>u4m1{cG|04htvrvl;=i02Fp6tEdF7{xMDb8_+(%JYkI ZQn&`A`$pX~8UmvsFd71*AwZiD002;H8TSAH literal 0 HcmV?d00001 diff --git a/test/pack.js b/test/pack.js new file mode 100644 index 0000000..f2ec58d --- /dev/null +++ b/test/pack.js @@ -0,0 +1,27 @@ +var test = require('tap').test; +var tar = require('../index'); +var fixtures = require('./fixtures'); +var concat = require('concat-stream'); +var fs = require('fs'); + +test('one-file', function(t) { + t.plan(1); + + var pack = tar.pack(); + + pack.entry({ + name:'test.txt', + mtime:new Date(1387580181000), + mode:0644, + uname:'maf', + gname:'staff', + uid:501, + gid:20 + }, 'hello world\n'); + + pack.finalize(); + + pack.pipe(concat(function(data) { + t.deepEqual(data, fs.readFileSync(fixtures.ONE_FILE_TAR)); + })); +}); \ No newline at end of file