From dd406da3e2f99a3b716ffd19402f4bef9c9adcc7 Mon Sep 17 00:00:00 2001
From: "trent.earl" <trent.earl@malauzai.com>
Date: Sat, 30 Jul 2016 14:02:50 -0500
Subject: [PATCH] Fix tests for node 6

Node 6 introduced two breaking changes to verdaccio/sinopia
Path functions now throw on null/undefined arguments
Buffer defaults to binary now A lot of test code explicitly converted data to utf8 which broke on checksum
---
 lib/config.js                  | 2 +-
 lib/local-storage.js           | 2 +-
 test/functional/basic.js       | 2 +-
 test/functional/gh29.js        | 2 +-
 test/functional/lib/server.js  | 1 +
 test/functional/mirror.js      | 2 +-
 test/functional/newnpmreg.js   | 4 ++--
 test/functional/nullstorage.js | 2 +-
 test/functional/scoped.js      | 9 +++++++--
 9 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/lib/config.js b/lib/config.js
index ef4fdaf48..6386a0cac 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -36,7 +36,7 @@ function Config(config) {
   assert(self.storage, 'CONFIG: storage path not defined')
   self.localList = LocalData(
     Path.join(
-      Path.resolve(Path.dirname(self.self_path), self.storage),
+      Path.resolve(Path.dirname(self.self_path || ''), self.storage),
       '.sinopia-db.json'
     )
   )
diff --git a/lib/local-storage.js b/lib/local-storage.js
index b5544d5e4..bccc1f268 100644
--- a/lib/local-storage.js
+++ b/lib/local-storage.js
@@ -663,7 +663,7 @@ Storage.prototype.storage = function(package) {
   }
   return Path_Wrapper(
     Path.join(
-      Path.resolve(Path.dirname(this.config.self_path), path),
+      Path.resolve(Path.dirname(this.config.self_path || ''), path),
       package
     )
   )
diff --git a/test/functional/basic.js b/test/functional/basic.js
index 785113406..542c5fa9c 100644
--- a/test/functional/basic.js
+++ b/test/functional/basic.js
@@ -43,7 +43,7 @@ module.exports = function () {
         return server.get_tarball('testpkg', 'blahblah')
                  .status(200)
                  .then(function (body) {
-                   assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
+                   assert.deepEqual(body, readfile('fixtures/binary'))
                  })
       })
 
diff --git a/test/functional/gh29.js b/test/functional/gh29.js
index b26e97f1a..f130c84c4 100644
--- a/test/functional/gh29.js
+++ b/test/functional/gh29.js
@@ -54,7 +54,7 @@ module.exports = function() {
           return server2.get_tarball('testpkg-gh29', 'blahblah')
                    .status(200)
                    .then(function (body) {
-                     assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
+                     assert.deepEqual(body, readfile('fixtures/binary'))
                    })
         })
       })
diff --git a/test/functional/lib/server.js b/test/functional/lib/server.js
index 3e33a9f30..8b21d7097 100644
--- a/test/functional/lib/server.js
+++ b/test/functional/lib/server.js
@@ -76,6 +76,7 @@ Server.prototype.get_tarball = function(name, filename) {
   return this.request({
     uri: '/'+encodeURIComponent(name)+'/-/'+encodeURIComponent(filename),
     method: 'GET',
+    encoding: null
   })
 }
 
diff --git a/test/functional/mirror.js b/test/functional/mirror.js
index 9fdd97c96..d1105ca1c 100644
--- a/test/functional/mirror.js
+++ b/test/functional/mirror.js
@@ -53,7 +53,7 @@ module.exports = function() {
             return server.get_tarball(pkg, pkg+'.file')
                      .status(200)
                      .then(function (body) {
-                       assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
+                       assert.deepEqual(body, readfile('fixtures/binary'))
                      })
           })
         })
diff --git a/test/functional/newnpmreg.js b/test/functional/newnpmreg.js
index 2565950d0..ee9311420 100644
--- a/test/functional/newnpmreg.js
+++ b/test/functional/newnpmreg.js
@@ -32,7 +32,7 @@ module.exports = function() {
                .status(200)
                .then(function (body) {
                  // not real sha due to utf8 conversion
-                 assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
+                 assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863')
                })
     })
 
@@ -41,7 +41,7 @@ module.exports = function() {
                .status(200)
                .then(function (body) {
                  // not real sha due to utf8 conversion
-                 assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
+                 assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863')
                })
     })
 
diff --git a/test/functional/nullstorage.js b/test/functional/nullstorage.js
index 330820c30..11857a422 100644
--- a/test/functional/nullstorage.js
+++ b/test/functional/nullstorage.js
@@ -51,7 +51,7 @@ module.exports = function() {
         return server.get_tarball('test-nullstorage2', 'blahblah')
                  .status(200)
                  .then(function (body) {
-                   assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
+                   assert.deepEqual(body, readfile('fixtures/binary'))
                  })
       })
 
diff --git a/test/functional/scoped.js b/test/functional/scoped.js
index 250853c7b..06b40e102 100644
--- a/test/functional/scoped.js
+++ b/test/functional/scoped.js
@@ -31,7 +31,7 @@ module.exports = function() {
                .status(200)
                .then(function (body) {
                  // not real sha due to utf8 conversion
-                 assert.strictEqual(sha(body), 'c59298948907d077c3b42f091554bdeea9208964')
+                 assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790')
                })
     })
 
@@ -40,7 +40,12 @@ module.exports = function() {
                .status(200)
                .then(function (body) {
                  // not real sha due to utf8 conversion
-                 assert.strictEqual(sha(body), 'c59298948907d077c3b42f091554bdeea9208964')
+                 require('fs').writeFileSync(
+                     '/Users/trent.earl/what.tgz',
+                     body
+                     );
+
+                 assert.strictEqual(sha(body), '6e67b14e2c0e450b942e2bc8086b49e90f594790')
                })
     })