basic test cases

This commit is contained in:
Mathias Buus 2013-12-21 01:03:48 +01:00
parent 52af22db8d
commit 475afe6a18
4 changed files with 71 additions and 0 deletions

41
test/extract.js Normal file
View file

@ -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));
});

3
test/fixtures/index.js vendored Normal file
View file

@ -0,0 +1,3 @@
var path = require('path');
exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar');

BIN
test/fixtures/one-file.tar vendored Normal file

Binary file not shown.

27
test/pack.js Normal file
View file

@ -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));
}));
});