[Pkg-javascript-commits] [node-hash-base] 03/06: Change ._digest to .digest in ._flush

Bastien Roucariès rouca at moszumanska.debian.org
Thu May 4 10:21:27 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to annotated tag v3.0.1
in repository node-hash-base.

commit fdad9ad23f9a43f388123667e7ba917100e4fe3a
Author: Kirill Fomichev <fanatid at ya.ru>
Date:   Tue Aug 9 16:37:16 2016 +0300

    Change ._digest to .digest in ._flush
---
 index.js      |  2 +-
 test/index.js | 18 ++++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/index.js b/index.js
index 914af68..c917cdf 100644
--- a/index.js
+++ b/index.js
@@ -30,7 +30,7 @@ HashBase.prototype._transform = function (chunk, encoding, callback) {
 HashBase.prototype._flush = function (callback) {
   var error = null
   try {
-    this.push(this._digest())
+    this.push(this.digest())
   } catch (err) {
     error = err
   }
diff --git a/test/index.js b/test/index.js
index 18798d1..3b5ddba 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,5 +1,6 @@
 'use strict'
 var test = require('tape')
+var randomBytes = require('crypto').randomBytes
 var HashBase = require('../')
 
 function beforeEach (t) {
@@ -17,7 +18,7 @@ test('_transform', function (t) {
 
   t.test('should use update', function (t) {
     t.plan(2)
-    var buffer = new Buffer(42)
+    var buffer = new Buffer(randomBytes(42))
     t.base.update = function (data) { t.true(data === buffer) }
     t.base._transform(buffer, 'buffer', function (err) {
       t.same(err, null)
@@ -38,7 +39,7 @@ test('_transform', function (t) {
     t.plan(1)
     var err = new Error('hey')
     t.base.update = function () { throw err }
-    t.base._transform(new Buffer(42), 'buffer', function (_err) {
+    t.base._transform(new Buffer(randomBytes(42)), 'buffer', function (_err) {
       t.true(_err === err)
     })
     t.end()
@@ -52,7 +53,7 @@ test('_flush', function (t) {
 
   t.test('should use _digest', function (t) {
     t.plan(2)
-    var buffer = new Buffer(42)
+    var buffer = new Buffer(randomBytes(42))
     t.base._digest = function () { return buffer }
     t.base.push = function (data) { t.true(data === buffer) }
     t.base._flush(function (err) { t.same(err, null) })
@@ -67,6 +68,15 @@ test('_flush', function (t) {
     t.end()
   })
 
+  t.test('should throw "Digest already called" on second _flush call', function (t) {
+    var buffer = new Buffer(randomBytes(42))
+    t.base._digest = function () { return buffer }
+    t.base._flush(function (err) { t.error(err) })
+    t.base._flush(function (err) { t.same(err.message, 'Digest already called') })
+    t.same(t.base.read(), buffer)
+    t.end()
+  })
+
   t.end()
 })
 
@@ -139,7 +149,7 @@ test('digest', function (t) {
 
   t.test('should return buffer from _digest by default', function (t) {
     t.plan(2)
-    var buffer = new Buffer(42)
+    var buffer = new Buffer(randomBytes(42))
     t.base._digest = function () {
       t.pass()
       return buffer

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-hash-base.git



More information about the Pkg-javascript-commits mailing list