Skip to content

Commit

Permalink
Merge pull request #633 from walmartlabs/user/eran
Browse files Browse the repository at this point in the history
pack interface cleanup
  • Loading branch information
geek committed Mar 4, 2013
2 parents 3dddc4d + 91943cb commit 17fcf8c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
8 changes: 8 additions & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ exports.server = {
server: null // Determines how long to wait for server request processing. Disabled by default
},

// Pack

pack: {
name: 'default', // Default name
labels: [], // Default labels
autoLabel: true // Automatically add 'secure' and 'cached' labels
},

// Optional components
// false -> null, true -> defaults, {} -> override defaults

Expand Down
2 changes: 1 addition & 1 deletion lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internals.Pack.prototype.server = function (name, server, options) {

// Add standard labels

if (options.autoLabel !== false) { // Defaults to true
if (options.autoLabel) {
if (server.settings.tls) {
serverLabels.push('secure');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,5 @@ internals.serverSchema = {
}).allow(false).allow(true).optional()],
app: T.Object().optional().nullOk(),
plugins: T.Object().optional().nullOk(),
plugin: T.Object().optional().nullOk()
pack: T.Object().optional().nullOk()
};
3 changes: 1 addition & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ internals.Server.prototype._plugin = function () {

var Pack = require('./pack'); // Delayed required to avoid circular dependencies
this._pack = new Pack();
var options = this.settings.plugin;
this._pack.server((options && options.name) || 'default', this, options);
this._pack.server(this.settings.pack.name, this, this.settings.pack);
this._pack.list = {};
return this._pack;
};
Expand Down
13 changes: 5 additions & 8 deletions test/integration/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Pack', function () {

it('requires multiple plugins using array', function (done) {

var server = new Hapi.Server({ plugin: { labels: 'test' } });
var server = new Hapi.Server({ pack: { labels: 'test' } });
server.plugin.require(['./pack/--test1', './pack/--test2'], function (err) {

expect(err).to.not.exist;
Expand All @@ -161,7 +161,7 @@ describe('Pack', function () {

it('requires multiple plugins using object', function (done) {

var server = new Hapi.Server({ plugin: { labels: 'test' } });
var server = new Hapi.Server({ pack: { labels: 'test' } });
server.plugin.require({ './pack/--test1': {}, './pack/--test2': {} }, function (err) {

expect(err).to.not.exist;
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('Pack', function () {
it('invalidates missing name', function (done) {

var pack = new Hapi.Pack({ a: 1 });
var err = pack.validate({ version: '0.0.0', hapi: { plugin: '1.x.x' }, register: function (pack, options, next) { next(); } });
var err = pack.validate({ version: '0.0.0', register: function (pack, options, next) { next(); } });

expect(err).to.exist;
expect(err.message).to.equal('Plugin missing name');
Expand All @@ -273,7 +273,7 @@ describe('Pack', function () {
it('invalidates missing version', function (done) {

var pack = new Hapi.Pack({ a: 1 });
var err = pack.validate({ name: 'test', hapi: { plugin: '1.x.x' }, register: function (pack, options, next) { next(); } });
var err = pack.validate({ name: 'test', register: function (pack, options, next) { next(); } });

expect(err).to.exist;
expect(err.message).to.equal('Plugin missing version');
Expand All @@ -283,7 +283,7 @@ describe('Pack', function () {
it('invalidates missing register method', function (done) {

var pack = new Hapi.Pack({ a: 1 });
var err = pack.validate({ name: 'test', version: '0.0.0', hapi: { plugin: '1.x.x' } });
var err = pack.validate({ name: 'test', version: '0.0.0' });

expect(err).to.exist;
expect(err.message).to.equal('Plugin missing register() method');
Expand All @@ -295,9 +295,6 @@ describe('Pack', function () {
var plugin = {
name: 'test',
version: '3.0.0',
hapi: {
plugin: '1.x.x'
},
register: function (pack, options, next) {

pack.route({ method: 'GET', path: '/b', handler: function () { this.reply('b'); } });
Expand Down

0 comments on commit 17fcf8c

Please sign in to comment.