Skip to content

Commit

Permalink
Merge pull request #28 from haraka/v1.0.12
Browse files Browse the repository at this point in the history
release 1.0.12
  • Loading branch information
msimerson authored Mar 17, 2020
2 parents fe02b26 + 11cf531 commit af1bc26
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 105 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ globals:
DENYSOFT: true
DENYDISCONNECT: true
DENYSOFTDISCONNECT: true
connection: true
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

### 1.0.12 - 2020-03-16

- replace nodeunit with mocha
- update redis lib to v3
- appveyor: test on node 10

### 1.0.11 - 2019-04-11

- create custom connection only after: all 3 conditions match
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1.0.{build}

environment:
nodejs_version: "8"
nodejs_version: "10"

# Install scripts. (runs after repo cloning)
install:
Expand All @@ -18,5 +18,5 @@ before_test:
- npm --version

test_script:
- node run_tests
- npm test

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ exports.register = function () {

plugin.load_redis_ini();

// another plugin doing: inherits('haraka-plugin-redis')
// another plugin has called us with: inherits('haraka-plugin-redis')
if (plugin.name !== 'redis') return;

// do register these when 'redis' is declared in config/plugins
// register these when 'redis' is declared in config/plugins
plugin.register_hook('init_master', 'init_redis_shared');
plugin.register_hook('init_child', 'init_redis_shared');
}
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "haraka-plugin-redis",
"version": "1.0.11",
"version": "1.0.12",
"description": "Redis plugin for Haraka & other plugins to inherit from",
"main": "index.js",
"directories": {
"test": "test"
},
"dependencies": {
"redis": "^2.8.0"
"redis": "^3.0.2"
},
"devDependencies": {
"eslint": "*",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"nodeunit": "*"
"mocha": "*"
},
"scripts": {
"lint": "./node_modules/.bin/eslint *.js test/*.js",
"lintfix": "./node_modules/.bin/eslint --fix *.js test/*.js",
"test": "node run_tests"
"lint": "npx eslint *.js test/*.js",
"lintfix": "npx eslint --fix *.js test/*.js",
"test": "npx mocha --exit"
},
"repository": {
"type": "git",
Expand Down
33 changes: 0 additions & 33 deletions run_tests

This file was deleted.

124 changes: 62 additions & 62 deletions test/redis.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
'use strict';

const path = require('path');
const assert = require('assert')
const path = require('path')

const fixtures = require('haraka-test-fixtures');

function _set_up_redis (done) {

this.plugin = new fixtures.plugin('index');
this.plugin.register();

done();
}
const fixtures = require('haraka-test-fixtures')

function retry (options) {
if (options.error) {
Expand All @@ -19,24 +12,28 @@ function retry (options) {
return undefined;
}

exports.config = {
setUp : _set_up_redis,
'loads' : function (test) {
test.expect(1);
test.equal(this.plugin.name, 'index');
test.done();
},
'config defaults' : function (test) {
test.expect(2);
test.equal(this.plugin.redisCfg.server.host, '127.0.0.1');
test.equal(this.plugin.redisCfg.server.port, 6379);
test.done();
},
'merges [opts] into server config': function (test) {
describe('config', function () {
before(function (done) {
this.plugin = new fixtures.plugin('index')
this.plugin.register()
done()
})

it('loads', function (done) {
assert.equal(this.plugin.name, 'index');
done()
})

it('config defaults', function (done) {
assert.equal(this.plugin.redisCfg.server.host, '127.0.0.1')
assert.equal(this.plugin.redisCfg.server.port, 6379)
done()
})

it('merges [opts] into server config', function (done) {
this.plugin.config = this.plugin.config.module_config(path.resolve('test'));
this.plugin.load_redis_ini();
test.expect(1);
test.deepEqual(this.plugin.redisCfg, {
assert.deepEqual(this.plugin.redisCfg, {
main: {},
pubsub: {
host: '127.0.0.1',
Expand All @@ -52,63 +49,66 @@ exports.config = {
password: 'dontUseThisOne'
}
});
test.done();
},
'merges redis.ini [opts] into plugin config': function (test) {
done();
})

it('merges redis.ini [opts] into plugin config', function (done) {
this.plugin.config = this.plugin.config.module_config(path.resolve('test'));
this.plugin.load_redis_ini();
this.plugin.cfg = {};
this.plugin.merge_redis_ini();
test.expect(1);
test.deepEqual(this.plugin.cfg, {
assert.deepEqual(this.plugin.cfg, {
redis: {
host: '127.0.0.1',
port: '6379',
db: 5,
password: 'dontUseThisOne'
}
});
test.done();
},
}
})
done()
})
})

describe('connects', function () {
before(function (done) {
this.plugin = new fixtures.plugin('index')
this.plugin.register()
done()
})

it('loads', function (done) {
assert.equal(this.plugin.name, 'index');
done();
})

exports.connects = {
setUp : _set_up_redis,
'loads' : function (test) {
test.expect(1);
test.equal(this.plugin.name, 'index');
test.done();
},
'connects' : function (test) {
test.expect(1);
it('connects', function (done) {
const redis = this.plugin.get_redis_client({
host: this.plugin.redisCfg.server.host,
port: this.plugin.redisCfg.server.port,
retry_strategy: retry,
},
function () {
test.ok(redis.connected);
test.done();
assert.ok(redis.connected);
done();
});
},
'populates plugin.cfg.redis when asked' : function (test) {
test.expect(2);
test.equal(this.plugin.cfg, undefined);
})

it('populates plugin.cfg.redis when asked', function (done) {
assert.equal(this.plugin.cfg, undefined);
this.plugin.merge_redis_ini();
test.deepEqual(this.plugin.cfg.redis, { host: '127.0.0.1', port: '6379' });
test.done();
},
'connects to a different redis db' : function (test) {
test.expect(2);
assert.deepEqual(this.plugin.cfg.redis, { host: '127.0.0.1', port: '6379' });
done();
})

it('connects to a different redis db', function (done) {
this.plugin.merge_redis_ini();
this.plugin.cfg.redis.db = 2;
this.plugin.cfg.redis.retry_strategy = retry;
const client = this.plugin.get_redis_client(this.plugin.cfg.redis, function () {
test.expect(2);
// console.log(client);
test.equal(client.connected, true);
test.equal(client.selected_db, 2);
test.done();
});
}
};
assert.equal(client.connected, true)
assert.equal(client.selected_db, 2)
done()
})
})
})

0 comments on commit af1bc26

Please sign in to comment.