Skip to content

Commit aaea5fb

Browse files
author
Aaron Chambers
committed
Merge pull request #41 from Bockit/feature/activation-suffix
Feature/activation suffix
2 parents f156dcc + f3afa15 commit aaea5fb

File tree

5 files changed

+61
-11
lines changed

5 files changed

+61
-11
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ The prefix to be used for the Redis key under which file will be uploaded to Red
111111

112112
*Default:* `context.project.name() + ':index'`
113113

114+
### activationSuffix
115+
116+
The suffix to be used for the Redis key under which the activated revision will be stored in Redis. By default this option will be `"current"`. This makes the default activated revision key in Redis looks like: `project.name() + ':index:current'`
117+
118+
*Default:* `current`
119+
114120
### revisionKey
115121

116122
The unique revision number for the version of the file being uploaded to Redis. The Redis key will be a combination of the `keyPrefix` and the `revisionKey`. By default this option will use either the `revisionKey` passed in from the command line or the `revisionData.revisionKey` property from the deployment context.

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
keyPrefix: function(context){
2929
return context.project.name() + ':index';
3030
},
31+
activationSuffix: 'current',
3132
didDeployMessage: function(context){
3233
var revisionKey = context.revisionData && context.revisionData.revisionKey;
3334
var activatedRevisionKey = context.revisionData && context.revisionData.activatedRevisionKey;
@@ -53,7 +54,7 @@ module.exports = {
5354
if (!this.pluginConfig.url) {
5455
['host', 'port'].forEach(this.applyDefaultConfigProperty.bind(this));
5556
}
56-
['filePattern', 'distDir', 'keyPrefix', 'revisionKey', 'didDeployMessage', 'redisDeployClient'].forEach(this.applyDefaultConfigProperty.bind(this));
57+
['filePattern', 'distDir', 'keyPrefix', 'activationSuffix', 'revisionKey', 'didDeployMessage', 'redisDeployClient'].forEach(this.applyDefaultConfigProperty.bind(this));
5758

5859
this.log('config ok', { verbose: true });
5960
},
@@ -80,9 +81,10 @@ module.exports = {
8081
var redisDeployClient = this.readConfig('redisDeployClient');
8182
var revisionKey = this.readConfig('revisionKey');
8283
var keyPrefix = this.readConfig('keyPrefix');
84+
var activationSuffix = this.readConfig('activationSuffix');
8385

8486
this.log('Activating revision `' + revisionKey + '`', { verbose: true });
85-
return Promise.resolve(redisDeployClient.activate(keyPrefix, revisionKey))
87+
return Promise.resolve(redisDeployClient.activate(keyPrefix, revisionKey, activationSuffix))
8688
.then(this.log.bind(this, '✔ Activated revision `' + revisionKey + '`', {}))
8789
.then(function(){
8890
return {

lib/redis.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ module.exports = CoreObject.extend({
5252
});
5353
},
5454

55-
activate: function(keyPrefix, revisionKey) {
56-
var currentKey = keyPrefix + ':current';
55+
activate: function(keyPrefix, revisionKey, activationSuffix) {
56+
var currentKey = keyPrefix + ':' + activationSuffix;
5757

5858
return Promise.resolve()
5959
.then(this._listRevisions.bind(this, keyPrefix))

tests/unit/index-nodetest.js

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,14 @@ describe('redis plugin', function() {
199199

200200
return previous;
201201
}, []);
202-
assert.equal(messages.length, 8);
202+
assert.equal(messages.length, 9);
203203
});
204204
it('adds default config to the config object', function() {
205205
plugin.configure(context);
206206
assert.isDefined(config.redis.host);
207207
assert.isDefined(config.redis.port);
208208
assert.isDefined(config.redis.keyPrefix);
209+
assert.isDefined(config.redis.activationSuffix);
209210
assert.isDefined(config.redis.didDeployMessage);
210211
});
211212
});
@@ -228,7 +229,7 @@ describe('redis plugin', function() {
228229
};
229230
plugin.beforeHook(context);
230231
});
231-
it('warns about missing optional filePattern, distDir, revisionKey, didDeployMessage, and connection info', function() {
232+
it('warns about missing optional filePattern, distDir, activationSuffix, revisionKey, didDeployMessage, and connection info', function() {
232233
plugin.configure(context);
233234
var messages = mockUi.messages.reduce(function(previous, current) {
234235
if (/- Missing config:\s.*, using default:\s/.test(current)) {
@@ -237,18 +238,59 @@ describe('redis plugin', function() {
237238

238239
return previous;
239240
}, []);
240-
assert.equal(messages.length, 7);
241+
assert.equal(messages.length, 8);
241242
});
242243
it('does not add default config to the config object', function() {
243244
plugin.configure(context);
244245
assert.isDefined(config.redis.host);
245246
assert.isDefined(config.redis.port);
246247
assert.isDefined(config.redis.filePattern);
248+
assert.isDefined(config.redis.activationSuffix);
247249
assert.isDefined(config.redis.didDeployMessage);
248250
assert.equal(config.redis.keyPrefix, 'proj:home');
249251
});
250252
});
251253

254+
describe('with an activationSuffix provided', function () {
255+
var config, plugin, context;
256+
beforeEach(function() {
257+
config = {
258+
redis: {
259+
activationSuffix: 'special:suffix'
260+
}
261+
};
262+
plugin = subject.createDeployPlugin({
263+
name: 'redis'
264+
});
265+
context = {
266+
ui: mockUi,
267+
project: stubProject,
268+
config: config
269+
};
270+
plugin.beforeHook(context);
271+
});
272+
it('warns about missing optional filePattern, distDir, keyPrefix, revisionKey, didDeployMessage, and connection info', function() {
273+
plugin.configure(context);
274+
var messages = mockUi.messages.reduce(function(previous, current) {
275+
if (/- Missing config:\s.*, using default:\s/.test(current)) {
276+
previous.push(current);
277+
}
278+
279+
return previous;
280+
}, []);
281+
assert.equal(messages.length, 8)
282+
});
283+
it('does not add default config to the config object', function() {
284+
plugin.configure(context);
285+
assert.isDefined(config.redis.host);
286+
assert.isDefined(config.redis.port);
287+
assert.isDefined(config.redis.filePattern);
288+
assert.isDefined(config.redis.keyPrefix);
289+
assert.isDefined(config.redis.didDeployMessage);
290+
assert.equal(config.redis.activationSuffix, 'special:suffix');
291+
});
292+
});
293+
252294
describe('with a url provided', function () {
253295
var config, plugin, context;
254296
beforeEach(function() {
@@ -267,7 +309,7 @@ describe('redis plugin', function() {
267309
};
268310
plugin.beforeHook(context);
269311
});
270-
it('warns about missing optional filePattern, distDir, keyPrefix, revisionKey and didDeployMessage only', function() {
312+
it('warns about missing optional filePattern, distDir, keyPrefix, activationSuffix, revisionKey, and didDeployMessage only', function() {
271313
plugin.configure(context);
272314
var messages = mockUi.messages.reduce(function(previous, current) {
273315
if (/- Missing config:\s.*, using default:\s/.test(current)) {
@@ -276,7 +318,7 @@ describe('redis plugin', function() {
276318

277319
return previous;
278320
}, []);
279-
assert.equal(messages.length, 6);
321+
assert.equal(messages.length, 7);
280322
});
281323

282324
it('does not add default config to the config object', function() {

tests/unit/lib/redis-nodetest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('redis', function() {
172172
});
173173

174174
describe('#activate', function() {
175-
it('rejects if the revisionKey doesn\t exist in list of uploaded revisions', function() {
175+
it('rejects if the revisionKey doesn\'t exist in list of uploaded revisions', function() {
176176
var redis = new Redis({}, new FakeRedis(FakeClient.extend({
177177
zrevrange: function() {
178178
return this.recentRevisions;
@@ -200,7 +200,7 @@ describe('redis', function() {
200200

201201
redis._client.recentRevisions = ['a', 'b', 'c'];
202202

203-
var promise = redis.activate('key-prefix', 'c');
203+
var promise = redis.activate('key-prefix', 'c', 'current');
204204
return assert.isFulfilled(promise)
205205
.then(function() {
206206
assert.equal(redisKey, 'key-prefix:current');

0 commit comments

Comments
 (0)