From b4a0be8bf5ef81563911ab92249ffac940473de4 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Mon, 6 Feb 2017 13:09:39 -0800 Subject: [PATCH] better fix for unset properties in tests will remove a bunch of boilerplate from test setups --- Changes.md | 2 +- index.js | 8 ++++++-- package.json | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Changes.md b/Changes.md index a9ddaf7..db1d1ee 100644 --- a/Changes.md +++ b/Changes.md @@ -1,4 +1,4 @@ -# 1.0.2 - 2017-02-06 +# 1.0.3 - 2017-02-06 - don't break when no [redis] config exists diff --git a/index.js b/index.js index 1fbc06c..eecc38e 100644 --- a/index.js +++ b/index.js @@ -99,9 +99,13 @@ exports.init_redis_plugin = function (next, server) { next(); } + // tests that do not load config + if (!plugin.cfg) plugin.cfg = { redis: {} }; + if (!server) server = { notes: {} }; + // use server-wide redis connection when using default DB id - if (!plugin.cfg.redis || !plugin.cfg.redis.db) { - if (server && server.notes && server.notes.redis) { + if (!plugin.cfg.redis.db) { + if (server.notes.redis) { server.loginfo(plugin, 'using server.notes.redis'); plugin.db = server.notes.redis; return nextOnce(); diff --git a/package.json b/package.json index 0af57f0..6a144a9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "haraka-plugin-redis", - "version": "1.0.2", - "description": "Redis plugin for Haraka & other plugins", + "version": "1.0.3", + "description": "Redis plugin for Haraka & other plugins to inherit from", "main": "index.js", "directories": { "test": "test"