From 132dcdeb438a2d08cd4ef5883d9d1598a84669cf Mon Sep 17 00:00:00 2001 From: hbeeken Date: Mon, 28 Jul 2014 14:29:35 +0100 Subject: [PATCH] Add test for case if loading credentials from storage has an error --- test/red/nodes/credentials_spec.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/red/nodes/credentials_spec.js b/test/red/nodes/credentials_spec.js index f0b38144f..76cf7c279 100644 --- a/test/red/nodes/credentials_spec.js +++ b/test/red/nodes/credentials_spec.js @@ -26,7 +26,6 @@ describe('Credentials', function() { var storage = { getCredentials: function() { - console.log("ONE"); return when.promise(function(resolve,reject) { resolve({"a":{"b":1,"c":2}}); }); @@ -114,6 +113,34 @@ describe('Credentials', function() { }); }); + it('handle error loading from storage', function(done) { + var util = require("util"); + var storage = { + getCredentials: function() { + return when.promise(function(resolve,reject) { + reject("test forcing failure"); + }); + }, + saveCredentials: function(creds) { + return when(true); + } + }; + var logmsg = 'no errors yet'; + sinon.stub(util, 'log', function(msg) { + logmsg = msg; + }); + + credentials.init(storage); + credentials.load().then(function() { + should.equal('[red] Error loading credentials : test forcing failure', logmsg); + util.log.restore(); + done(); + }).otherwise(function(err){ + util.log.restore(); + done(err); + }); + }); + })