Skip to content

Commit f4839df

Browse files
committed
Read config from configured name path instead of static 'redis' key
1 parent 7b0231e commit f4839df

File tree

6 files changed

+71
-42
lines changed

6 files changed

+71
-42
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ module.exports = {
3939
return context.commandOptions.revision || context.revisionKey;
4040
},
4141
redisDeployClient: function(context) {
42-
var options = context.config.redis;
42+
var redisOptions = this.pluginConfig;
4343
var redisLib = context._redisLib;
4444

45-
return new Redis(options, redisLib);
45+
return new Redis(redisOptions, redisLib);
4646
}
4747
},
4848
configure: function(/* context */) {
@@ -114,6 +114,7 @@ module.exports = {
114114
return Promise.reject(error);
115115
}
116116
});
117+
117118
return new DeployPlugin();
118119
}
119120
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"dependencies": {
4545
"chalk": "^1.0.0",
4646
"core-object": "^1.1.0",
47-
"ember-cli-deploy-plugin": "0.1.2",
47+
"ember-cli-deploy-plugin": "0.1.3",
4848
"ember-cli-babel": "^5.0.0",
4949
"redis": "^0.12.1",
5050
"rsvp": "^3.0.18",

tests/helpers/fake-redis-client.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var CoreObject = require('core-object');
2+
3+
module.exports = CoreObject.extend({
4+
init: function (options) {
5+
this.options = options;
6+
},
7+
get: function(key) {
8+
return Promise.resolve('some-other-value');
9+
},
10+
set: function() { },
11+
lpush: function() { },
12+
ltrim: function() { }
13+
});

tests/helpers/fake-redis-lib.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var FakeClient = require('./fake-redis-client');
2+
3+
var CoreObject = require('core-object');
4+
5+
module.exports = CoreObject.extend({
6+
init: function(clientClass) {
7+
this.clientClass = clientClass || FakeClient;
8+
},
9+
10+
createClient: function(options) {
11+
this.options = options;
12+
this.createdClient = new this.clientClass(options);
13+
return this.createdClient;
14+
}
15+
});

tests/unit/index-nodetest.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,14 @@
22

33
var Promise = require('ember-cli/lib/ext/promise');
44
var assert = require('ember-cli/tests/helpers/assert');
5-
var CoreObject = require('core-object');
5+
var FakeRedis = require('../helpers/fake-redis-lib');
66

77
var stubProject = {
88
name: function(){
99
return 'my-project';
1010
}
1111
};
1212

13-
var fakeClient = {
14-
createClient: function(options) {
15-
this.options = options;
16-
return {
17-
get: function(key) {
18-
return Promise.resolve('some-other-value');
19-
},
20-
set: function() { },
21-
lpush: function() { },
22-
ltrim: function() { }
23-
}
24-
}
25-
};
26-
2713
describe('redis plugin', function() {
2814
var subject, mockUi;
2915

@@ -83,6 +69,8 @@ describe('redis plugin', function() {
8369
name: 'redis'
8470
});
8571

72+
var redisLib = new FakeRedis();
73+
8674
var context = {
8775
ui: mockUi,
8876
project: stubProject,
@@ -93,15 +81,15 @@ describe('redis plugin', function() {
9381
database: 4
9482
}
9583
},
96-
_redisLib: fakeClient
84+
_redisLib: redisLib
9785
};
9886
plugin.beforeHook(context);
9987
plugin.configure(context);
10088
plugin.readConfig('redisDeployClient');
10189

102-
assert.equal(fakeClient.options.host, 'somehost');
103-
assert.equal(fakeClient.options.port, 1234);
104-
assert.equal(fakeClient.options.database, 4);
90+
assert.equal(redisLib.createdClient.options.host, 'somehost');
91+
assert.equal(redisLib.createdClient.options.port, 1234);
92+
assert.equal(redisLib.createdClient.options.database, 4);
10593
});
10694

10795
describe('resolving revisionKey from the pipeline', function() {
@@ -292,6 +280,34 @@ describe('redis plugin', function() {
292280
assert.isDefined(config.redis.didDeployMessage);
293281
});
294282
});
283+
284+
describe('with aliases', function () {
285+
it('passes config for specified alias to redis', function () {
286+
var plugin = subject.createDeployPlugin({
287+
name: 'foobar'
288+
});
289+
290+
var redisLib = new FakeRedis();
291+
292+
var config = {
293+
database: 7
294+
};
295+
var context = {
296+
ui: mockUi,
297+
project: stubProject,
298+
config: {
299+
foobar: config
300+
},
301+
_redisLib: redisLib
302+
};
303+
304+
plugin.beforeHook(context);
305+
plugin.configure(context);
306+
plugin.readConfig('redisDeployClient');
307+
308+
assert.equal(redisLib.createdClient.options.database, 7);
309+
});
310+
});
295311
});
296312

297313
describe('upload hook', function() {

tests/unit/lib/redis-nodetest.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22

3+
var FakeRedis = require('../../helpers/fake-redis-lib');
4+
var FakeClient = require('../../helpers/fake-redis-client');
5+
6+
37
var Promise = require('ember-cli/lib/ext/promise');
48
var assert = require('ember-cli/tests/helpers/assert');
59
var CoreObject = require('core-object');
@@ -11,26 +15,6 @@ describe('redis', function() {
1115
Redis = require('../../../lib/redis');
1216
});
1317

14-
var FakeClient = CoreObject.extend({
15-
get: function(key) {
16-
return Promise.resolve('some-other-value');
17-
},
18-
set: function() { },
19-
lpush: function() { },
20-
ltrim: function() { }
21-
});
22-
23-
var FakeRedis = CoreObject.extend({
24-
init: function(clientClass) {
25-
this.clientClass = clientClass || FakeClient;
26-
},
27-
28-
createClient: function(options) {
29-
this.options = options;
30-
return new this.clientClass()
31-
}
32-
});
33-
3418
describe('#upload', function() {
3519
it('rejects if the key already exists in redis', function() {
3620
var redis = new Redis({}, new FakeRedis());

0 commit comments

Comments
 (0)