Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
fix(tests): use safe-buffer because omfg (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 12, 2017
1 parent 45ad77a commit 6ab8132
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 51 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"glob": "^7.1.1",
"nyc": "^10.0.0",
"require-inject": "^1.4.0",
"safe-buffer": "^5.0.1",
"standard": "^9.0.0",
"standard-version": "^4.0.0",
"tacks": "^1.2.2",
Expand Down
8 changes: 4 additions & 4 deletions test/content.read.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const Buffer = require('safe-buffer').Buffer
const Promise = require('bluebird')

const bufferise = require('./util/bufferise')
const crypto = require('crypto')
const path = require('path')
const Tacks = require('tacks')
Expand All @@ -15,7 +15,7 @@ const CacheContent = require('./util/cache-content')
const read = require('../lib/content/read')

test('read: returns a Promise with cache content data', function (t) {
const CONTENT = bufferise('foobarbaz')
const CONTENT = Buffer.from('foobarbaz')
const DIGEST = crypto.createHash('sha512').update(CONTENT).digest('hex')
const fixture = new Tacks(CacheContent({
[DIGEST]: CONTENT
Expand All @@ -27,7 +27,7 @@ test('read: returns a Promise with cache content data', function (t) {
})

test('read.stream: returns a stream with cache content data', function (t) {
const CONTENT = bufferise('foobarbaz')
const CONTENT = Buffer.from('foobarbaz')
const DIGEST = crypto.createHash('sha512').update(CONTENT).digest('hex')
const fixture = new Tacks(CacheContent({
[DIGEST]: CONTENT
Expand All @@ -39,7 +39,7 @@ test('read.stream: returns a stream with cache content data', function (t) {
stream.on('data', function (data) { buf += data })
stream.on('end', function () {
t.ok(true, 'stream completed successfully')
t.deepEqual(bufferise(buf), CONTENT, 'cache contents read correctly')
t.deepEqual(Buffer.from(buf), CONTENT, 'cache contents read correctly')
t.end()
})
})
Expand Down
9 changes: 2 additions & 7 deletions test/get.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const Buffer = require('safe-buffer').Buffer
const Promise = require('bluebird')

const crypto = require('crypto')
Expand All @@ -15,20 +16,14 @@ const testDir = require('./util/test-dir')(__filename)
const CacheContent = require('./util/cache-content')

const CACHE = path.join(testDir, 'cache')
const CONTENT = bufferise('foobarbaz')
const CONTENT = Buffer.from('foobarbaz', 'utf8')
const KEY = 'my-test-key'
const ALGO = 'sha512'
const DIGEST = crypto.createHash(ALGO).update(CONTENT).digest('hex')
const METADATA = { foo: 'bar' }

var get = require('../get')

function bufferise (string) {
return Buffer.from
? Buffer.from(string, 'utf8')
: new Buffer(string, 'utf8')
}

// Simple wrapper util cause this gets WORDY
function streamGet (byDigest) {
const args = [].slice.call(arguments, 1)
Expand Down
9 changes: 2 additions & 7 deletions test/put.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const Buffer = require('safe-buffer').Buffer
const Promise = require('bluebird')

const crypto = require('crypto')
Expand All @@ -13,7 +14,7 @@ const test = require('tap').test
const testDir = require('./util/test-dir')(__filename)

const CACHE = path.join(testDir, 'cache')
const CONTENT = bufferise('foobarbaz')
const CONTENT = Buffer.from('foobarbaz', 'utf8')
const KEY = 'my-test-key'
const ALGO = 'sha512'
const DIGEST = crypto.createHash(ALGO).update(CONTENT).digest('hex')
Expand All @@ -22,12 +23,6 @@ const contentPath = require('../lib/content/path')

var put = require('../put')

function bufferise (string) {
return Buffer.from
? Buffer.from(string, 'utf8')
: new Buffer(string, 'utf8')
}

test('basic bulk insertion', t => {
return put(CACHE, KEY, CONTENT).then(digest => {
t.equal(digest, DIGEST, 'returned content digest')
Expand Down
9 changes: 2 additions & 7 deletions test/rm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const Buffer = require('safe-buffer').Buffer
const Promise = require('bluebird')

const crypto = require('crypto')
Expand All @@ -15,7 +16,7 @@ const testDir = require('./util/test-dir')(__filename)

const CacheContent = require('./util/cache-content')
const CACHE = path.join(testDir, 'cache')
const CONTENT = bufferise('foobarbaz')
const CONTENT = Buffer.from('foobarbaz')
const KEY = 'my-test-key'
const ALGO = 'sha512'
const DIGEST = crypto.createHash(ALGO).update(CONTENT).digest('hex')
Expand All @@ -26,12 +27,6 @@ const get = require('../get')

const rm = require('../rm')

function bufferise (string) {
return Buffer.from
? Buffer.from(string, 'utf8')
: new Buffer(string, 'utf8')
}

test('rm.entry removes entries, not content', t => {
const fixture = new Tacks(CacheContent({
[DIGEST]: CONTENT
Expand Down
23 changes: 12 additions & 11 deletions test/strict.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
'use strict'

var fs = require('fs')
var glob = require('glob')
var path = require('path')
var test = require('tap').test
const Buffer = require('safe-buffer').Buffer

const fs = require('fs')
const glob = require('glob')
const path = require('path')
const test = require('tap').test

test('all JavaScript source files use strict mode', function (t) {
var globStr = '**/*.js'
var root = path.resolve(__dirname, '../')
const globStr = '**/*.js'
const root = path.resolve(__dirname, '../')
glob(globStr, {
cwd: root,
ignore: 'node_modules/**/*.js'
}, function (err, files) {
if (err) { throw err }
var line = "'use strict'\n"
var bytecount = line.length
// node@0.12 doesn't have Buffer.alloc
var buf = Buffer.alloc ? Buffer.alloc(bytecount) : new Buffer(bytecount)
const line = "'use strict'\n"
const bytecount = line.length
const buf = new Buffer(bytecount)
files.forEach(function (f) {
var fd = fs.openSync(path.join(root, f), 'r')
const fd = fs.openSync(path.join(root, f), 'r')
fs.readSync(fd, buf, 0, bytecount, 0)
fs.closeSync(fd)
t.equal(buf.toString('utf8'), line, f + ' is using strict mode.')
Expand Down
8 changes: 0 additions & 8 deletions test/util/bufferise.js

This file was deleted.

9 changes: 2 additions & 7 deletions test/verify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const Buffer = require('safe-buffer').Buffer
const Promise = require('bluebird')

const crypto = require('crypto')
Expand All @@ -14,7 +15,7 @@ const testDir = require('./util/test-dir')(__filename)
const CacheContent = require('./util/cache-content')

const CACHE = path.join(testDir, 'cache')
const CONTENT = bufferise('foobarbaz')
const CONTENT = Buffer.from('foobarbaz', 'utf8')
const KEY = 'my-test-key'
const ALGO = 'sha512'
const DIGEST = crypto.createHash(ALGO).update(CONTENT).digest('hex')
Expand All @@ -23,12 +24,6 @@ const BUCKET = index._bucketPath(CACHE, KEY)

const verify = require('../verify')

function bufferise (string) {
return Buffer.from
? Buffer.from(string, 'utf8')
: new Buffer(string, 'utf8')
}

function mockCache () {
const fixture = new Tacks(CacheContent({
[DIGEST]: CONTENT
Expand Down

0 comments on commit 6ab8132

Please sign in to comment.