fix test style

This commit is contained in:
Mathias Buus 2014-11-05 15:05:22 +01:00
parent 97ad73faca
commit cbb5a99775
3 changed files with 476 additions and 476 deletions

View file

@ -1,24 +1,24 @@
var test = require('tape'); var test = require('tape')
var tar = require('../index'); var tar = require('../index')
var fixtures = require('./fixtures'); var fixtures = require('./fixtures')
var concat = require('concat-stream'); var concat = require('concat-stream')
var fs = require('fs'); var fs = require('fs')
var clamp = function(index, len, defaultValue) { var clamp = function(index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue; if (typeof index !== 'number') return defaultValue
index = ~~index; // Coerce to integer. index = ~~index // Coerce to integer.
if (index >= len) return len; if (index >= len) return len
if (index >= 0) return index; if (index >= 0) return index
index += len; index += len
if (index >= 0) return index; if (index >= 0) return index
return 0; return 0
}; }
test('one-file', function(t) { test('one-file', function(t) {
t.plan(3); t.plan(3)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
extract.on('entry', function(header, stream, callback) { extract.on('entry', function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -34,27 +34,27 @@ test('one-file', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
noEntries = true; noEntries = true
t.same(data.toString(), 'hello world\n'); t.same(data.toString(), 'hello world\n')
callback(); callback()
})); }))
}); })
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
extract.end(fs.readFileSync(fixtures.ONE_FILE_TAR)); extract.end(fs.readFileSync(fixtures.ONE_FILE_TAR))
}); })
test('chunked-one-file', function(t) { test('chunked-one-file', function(t) {
t.plan(3); t.plan(3)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
extract.on('entry', function(header, stream, callback) { extract.on('entry', function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -70,33 +70,33 @@ test('chunked-one-file', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
noEntries = true; noEntries = true
t.same(data.toString(), 'hello world\n'); t.same(data.toString(), 'hello world\n')
callback(); callback()
})); }))
}); })
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
var b = fs.readFileSync(fixtures.ONE_FILE_TAR); var b = fs.readFileSync(fixtures.ONE_FILE_TAR)
for (var i = 0; i < b.length; i += 321) { for (var i = 0; i < b.length; i += 321) {
extract.write(b.slice(i, clamp(i+321, b.length, b.length))); extract.write(b.slice(i, clamp(i+321, b.length, b.length)))
} }
extract.end(); extract.end()
}); })
test('multi-file', function(t) { test('multi-file', function(t) {
t.plan(5); t.plan(5)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
var onfile1 = function(header, stream, callback) { var onfile1 = function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -112,14 +112,14 @@ test('multi-file', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
extract.on('entry', onfile2); extract.on('entry', onfile2)
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
t.same(data.toString(), 'i am file-1\n'); t.same(data.toString(), 'i am file-1\n')
callback(); callback()
})); }))
}; }
var onfile2 = function(header, stream, callback) { var onfile2 = function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -135,29 +135,29 @@ test('multi-file', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
noEntries = true; noEntries = true
t.same(data.toString(), 'i am file-2\n'); t.same(data.toString(), 'i am file-2\n')
callback(); callback()
})); }))
}; }
extract.once('entry', onfile1); extract.once('entry', onfile1)
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
extract.end(fs.readFileSync(fixtures.MULTI_FILE_TAR)); extract.end(fs.readFileSync(fixtures.MULTI_FILE_TAR))
}); })
test('chunked-multi-file', function(t) { test('chunked-multi-file', function(t) {
t.plan(5); t.plan(5)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
var onfile1 = function(header, stream, callback) { var onfile1 = function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -173,14 +173,14 @@ test('chunked-multi-file', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
extract.on('entry', onfile2); extract.on('entry', onfile2)
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
t.same(data.toString(), 'i am file-1\n'); t.same(data.toString(), 'i am file-1\n')
callback(); callback()
})); }))
}; }
var onfile2 = function(header, stream, callback) { var onfile2 = function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -196,33 +196,33 @@ test('chunked-multi-file', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
noEntries = true; noEntries = true
t.same(data.toString(), 'i am file-2\n'); t.same(data.toString(), 'i am file-2\n')
callback(); callback()
})); }))
}; }
extract.once('entry', onfile1); extract.once('entry', onfile1)
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
var b = fs.readFileSync(fixtures.MULTI_FILE_TAR); var b = fs.readFileSync(fixtures.MULTI_FILE_TAR)
for (var i = 0; i < b.length; i += 321) { for (var i = 0; i < b.length; i += 321) {
extract.write(b.slice(i, clamp(i+321, b.length, b.length))); extract.write(b.slice(i, clamp(i+321, b.length, b.length)))
} }
extract.end(); extract.end()
}); })
test('types', function(t) { test('types', function(t) {
t.plan(3); t.plan(3)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
var ondir = function(header, stream, callback) { var ondir = function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -238,13 +238,13 @@ test('types', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.on('data', function() { stream.on('data', function() {
t.ok(false); t.ok(false)
}); })
extract.once('entry', onlink); extract.once('entry', onlink)
callback(); callback()
}; }
var onlink = function(header, stream, callback) { var onlink = function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -260,28 +260,28 @@ test('types', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.on('data', function() { stream.on('data', function() {
t.ok(false); t.ok(false)
}); })
noEntries = true; noEntries = true
callback(); callback()
}; }
extract.once('entry', ondir); extract.once('entry', ondir)
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
extract.end(fs.readFileSync(fixtures.TYPES_TAR)); extract.end(fs.readFileSync(fixtures.TYPES_TAR))
}); })
test('long-name', function(t) { test('long-name', function(t) {
t.plan(3); t.plan(3)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
extract.on('entry', function(header, stream, callback) { extract.on('entry', function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -297,27 +297,27 @@ test('long-name', function(t) {
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
noEntries = true; noEntries = true
t.same(data.toString(), 'hello long name\n'); t.same(data.toString(), 'hello long name\n')
callback(); callback()
})); }))
}); })
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
extract.end(fs.readFileSync(fixtures.LONG_NAME_TAR)); extract.end(fs.readFileSync(fixtures.LONG_NAME_TAR))
}); })
test('unicode-bsd', function(t) { // can unpack a bsdtar unicoded tarball test('unicode-bsd', function(t) { // can unpack a bsdtar unicoded tarball
t.plan(3); t.plan(3)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
extract.on('entry', function(header, stream, callback) { extract.on('entry', function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -333,27 +333,27 @@ test('unicode-bsd', function(t) { // can unpack a bsdtar unicoded tarball
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
noEntries = true; noEntries = true
t.same(data.toString(), 'hej\n'); t.same(data.toString(), 'hej\n')
callback(); callback()
})); }))
}); })
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
extract.end(fs.readFileSync(fixtures.UNICODE_BSD_TAR)); extract.end(fs.readFileSync(fixtures.UNICODE_BSD_TAR))
}); })
test('unicode', function(t) { // can unpack a bsdtar unicoded tarball test('unicode', function(t) { // can unpack a bsdtar unicoded tarball
t.plan(3); t.plan(3)
var extract = tar.extract(); var extract = tar.extract()
var noEntries = false; var noEntries = false
extract.on('entry', function(header, stream, callback) { extract.on('entry', function(header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
@ -369,69 +369,69 @@ test('unicode', function(t) { // can unpack a bsdtar unicoded tarball
gname: 'staff', gname: 'staff',
devmajor: 0, devmajor: 0,
devminor: 0 devminor: 0
}); })
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
noEntries = true; noEntries = true
t.same(data.toString(), 'høllø\n'); t.same(data.toString(), 'høllø\n')
callback(); callback()
})); }))
}); })
extract.on('finish', function() { extract.on('finish', function() {
t.ok(noEntries); t.ok(noEntries)
}); })
extract.end(fs.readFileSync(fixtures.UNICODE_TAR)); extract.end(fs.readFileSync(fixtures.UNICODE_TAR))
}); })
test('name-is-100', function(t) { test('name-is-100', function(t) {
t.plan(3); t.plan(3)
var extract = tar.extract(); var extract = tar.extract()
extract.on('entry', function(header, stream, callback) { extract.on('entry', function(header, stream, callback) {
t.same(header.name.length, 100); t.same(header.name.length, 100)
stream.pipe(concat(function(data) { stream.pipe(concat(function(data) {
t.same(data.toString(), 'hello\n'); t.same(data.toString(), 'hello\n')
callback(); callback()
})); }))
}); })
extract.on('finish', function() { extract.on('finish', function() {
t.ok(true); t.ok(true)
}); })
extract.end(fs.readFileSync(fixtures.NAME_IS_100_TAR)); extract.end(fs.readFileSync(fixtures.NAME_IS_100_TAR))
}); })
test('invalid-file', function(t) { test('invalid-file', function(t) {
t.plan(1); t.plan(1)
var extract = tar.extract(); var extract = tar.extract()
extract.on('error', function(err) { extract.on('error', function(err) {
t.ok(!!err); t.ok(!!err)
extract.destroy(); extract.destroy()
}); })
extract.end(fs.readFileSync(fixtures.INVALID_TGZ)); extract.end(fs.readFileSync(fixtures.INVALID_TGZ))
}); })
test('space prefixed', function(t) { test('space prefixed', function(t) {
t.plan(5); t.plan(5)
var extract = tar.extract(); var extract = tar.extract()
extract.on('entry', function(header, stream, callback) { extract.on('entry', function(header, stream, callback) {
t.ok(true) t.ok(true)
callback(); callback()
}); })
extract.on('finish', function() { extract.on('finish', function() {
t.ok(true); t.ok(true)
}); })
extract.end(fs.readFileSync(fixtures.SPACE_TAR_GZ)); extract.end(fs.readFileSync(fixtures.SPACE_TAR_GZ))
}); })

View file

@ -1,11 +1,11 @@
var path = require('path'); var path = require('path')
exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar'); exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar')
exports.MULTI_FILE_TAR = path.join(__dirname, 'multi-file.tar'); exports.MULTI_FILE_TAR = path.join(__dirname, 'multi-file.tar')
exports.TYPES_TAR = path.join(__dirname, 'types.tar'); exports.TYPES_TAR = path.join(__dirname, 'types.tar')
exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar'); exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar')
exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar'); exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar')
exports.UNICODE_TAR = path.join(__dirname, 'unicode.tar'); exports.UNICODE_TAR = path.join(__dirname, 'unicode.tar')
exports.NAME_IS_100_TAR = path.join(__dirname, 'name-is-100.tar'); exports.NAME_IS_100_TAR = path.join(__dirname, 'name-is-100.tar')
exports.INVALID_TGZ = path.join(__dirname, 'invalid.tgz'); exports.INVALID_TGZ = path.join(__dirname, 'invalid.tgz')
exports.SPACE_TAR_GZ = path.join(__dirname, 'space.tar'); exports.SPACE_TAR_GZ = path.join(__dirname, 'space.tar')

View file

@ -1,13 +1,13 @@
var test = require('tape'); var test = require('tape')
var tar = require('../index'); var tar = require('../index')
var fixtures = require('./fixtures'); var fixtures = require('./fixtures')
var concat = require('concat-stream'); var concat = require('concat-stream')
var fs = require('fs'); var fs = require('fs')
test('one-file', function(t) { test('one-file', function(t) {
t.plan(2); t.plan(2)
var pack = tar.pack(); var pack = tar.pack()
pack.entry({ pack.entry({
name:'test.txt', name:'test.txt',
@ -17,20 +17,20 @@ test('one-file', function(t) {
gname:'staff', gname:'staff',
uid:501, uid:501,
gid:20 gid:20
}, 'hello world\n'); }, 'hello world\n')
pack.finalize(); pack.finalize()
pack.pipe(concat(function(data) { pack.pipe(concat(function(data) {
t.same(data.length & 511, 0); t.same(data.length & 511, 0)
t.deepEqual(data, fs.readFileSync(fixtures.ONE_FILE_TAR)); t.deepEqual(data, fs.readFileSync(fixtures.ONE_FILE_TAR))
})); }))
}); })
test('multi-file', function(t) { test('multi-file', function(t) {
t.plan(2); t.plan(2)
var pack = tar.pack(); var pack = tar.pack()
pack.entry({ pack.entry({
name:'file-1.txt', name:'file-1.txt',
@ -40,7 +40,7 @@ test('multi-file', function(t) {
gname:'staff', gname:'staff',
uid:501, uid:501,
gid:20 gid:20
}, 'i am file-1\n'); }, 'i am file-1\n')
pack.entry({ pack.entry({
name:'file-2.txt', name:'file-2.txt',
@ -51,19 +51,19 @@ test('multi-file', function(t) {
gname:'staff', gname:'staff',
uid:501, uid:501,
gid:20 gid:20
}).end('i am file-2\n'); }).end('i am file-2\n')
pack.finalize(); pack.finalize()
pack.pipe(concat(function(data) { pack.pipe(concat(function(data) {
t.same(data.length & 511, 0); t.same(data.length & 511, 0)
t.deepEqual(data, fs.readFileSync(fixtures.MULTI_FILE_TAR)); t.deepEqual(data, fs.readFileSync(fixtures.MULTI_FILE_TAR))
})); }))
}); })
test('types', function(t) { test('types', function(t) {
t.plan(2); t.plan(2)
var pack = tar.pack(); var pack = tar.pack()
pack.entry({ pack.entry({
name:'directory', name:'directory',
@ -74,7 +74,7 @@ test('types', function(t) {
gname:'staff', gname:'staff',
uid:501, uid:501,
gid:20 gid:20
}); })
pack.entry({ pack.entry({
name:'directory-link', name:'directory-link',
@ -86,20 +86,20 @@ test('types', function(t) {
gname:'staff', gname:'staff',
uid:501, uid:501,
gid:20 gid:20
}); })
pack.finalize(); pack.finalize()
pack.pipe(concat(function(data) { pack.pipe(concat(function(data) {
t.equal(data.length & 511, 0); t.equal(data.length & 511, 0)
t.deepEqual(data, fs.readFileSync(fixtures.TYPES_TAR)); t.deepEqual(data, fs.readFileSync(fixtures.TYPES_TAR))
})); }))
}); })
test('long-name', function(t) { test('long-name', function(t) {
t.plan(2); t.plan(2)
var pack = tar.pack(); var pack = tar.pack()
pack.entry({ pack.entry({
name:'my/file/is/longer/than/100/characters/and/should/use/the/prefix/header/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/filename.txt', name:'my/file/is/longer/than/100/characters/and/should/use/the/prefix/header/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/filename.txt',
@ -110,19 +110,19 @@ test('long-name', function(t) {
gname:'staff', gname:'staff',
uid:501, uid:501,
gid:20 gid:20
}, 'hello long name\n'); }, 'hello long name\n')
pack.finalize(); pack.finalize()
pack.pipe(concat(function(data) { pack.pipe(concat(function(data) {
t.equal(data.length & 511, 0); t.equal(data.length & 511, 0)
t.deepEqual(data, fs.readFileSync(fixtures.LONG_NAME_TAR)); t.deepEqual(data, fs.readFileSync(fixtures.LONG_NAME_TAR))
})); }))
}); })
test('unicode', function(t) { test('unicode', function(t) {
t.plan(2); t.plan(2)
var pack = tar.pack(); var pack = tar.pack()
pack.entry({ pack.entry({
name:'høstål.txt', name:'høstål.txt',
@ -133,12 +133,12 @@ test('unicode', function(t) {
gname:'staff', gname:'staff',
uid:501, uid:501,
gid:20 gid:20
}, 'høllø\n'); }, 'høllø\n')
pack.finalize(); pack.finalize()
pack.pipe(concat(function(data) { pack.pipe(concat(function(data) {
t.equal(data.length & 511, 0); t.equal(data.length & 511, 0)
t.deepEqual(data, fs.readFileSync(fixtures.UNICODE_TAR)); t.deepEqual(data, fs.readFileSync(fixtures.UNICODE_TAR))
})); }))
}); })