diff --git a/lib/persistence/mongo.js b/lib/persistence/mongo.js index 1bbc0c25..9ca437ae 100644 --- a/lib/persistence/mongo.js +++ b/lib/persistence/mongo.js @@ -39,7 +39,7 @@ var defaults = { subscriptions: 60 * 60 * 1000, // TTL for packets is 1 hour - packets: 60* 60 * 1000, + packets: 60 * 60 * 1000, }, mongo: {}, @@ -74,7 +74,6 @@ function MongoPersistence(options, done) { this.options = extend(true, {}, defaults, options); - this.options.mongo.safe = true; // This offlineMessageTimeout(in milliseconds) can set the maximum life time for stored offline messages. This is a // Mongo-only feature which relies on TTL index. Since Mongo checks expired entries on a minute-based clock, the @@ -86,7 +85,7 @@ function MongoPersistence(options, done) { var that = this; - var connected = function(err, db) { + var connected = function (err, db) { if (err) { if (done) { return done(err); @@ -97,66 +96,60 @@ function MongoPersistence(options, done) { that.db = db; steed.parallel([ - function(cb) { - db.collection("subscriptions", function(err, coll) { - that._subscriptions = coll; - steed.parallel([ - that._subscriptions.ensureIndex.bind(that._subscriptions, "client"), - that._subscriptions.ensureIndex.bind(that._subscriptions, { "added": 1 }, { expireAfterSeconds: Math.round(that.options.ttl.subscriptions / 1000 )} ) - ], cb); - }); + function (cb) { + that._subscriptions = db.collection('subscriptions'); + + steed.parallel([ + function (parallelCallback) { + that._subscriptions.createIndex({ "added": 1 }, { expireAfterSeconds: Math.round(that.options.ttl.subscriptions / 1000) }, parallelCallback); + }, + that._subscriptions.createIndex.bind(that._subscriptions, "client") + ], cb); }, - function(cb) { - db.collection("packets", function(err, coll) { - if (err) { - return cb(err); - } - - that._packets = coll; - steed.series([ - that._packets.ensureIndex.bind(that._packets, "client"), - function(cb){ - // Check expiration indexes. If not exist, create; If exist but with different TTL, delete and recreate; Otherwise, do nothing. - that._packets.indexes(function(error, colIndexes){ - if (error) { - cb(error); - } else { - var addedIndexKey = {"added": 1}; - var addedIndexKeyString = 'added_1'; // If addedIndex changes, this value should also be changed accordingly. - var addedIndexObj = colIndexes.filter(function(obj){ - return obj.name == addedIndexKeyString; - }); - var packetTTLInSeconds = Math.round(that.options.ttl.packets / 1000); - if (addedIndexObj.length <= 0 || addedIndexObj[0].expireAfterSeconds != packetTTLInSeconds) { - if (addedIndexObj.length > 0) { - // Different index TTL, recreate index to make sure the TTL is set to the new number. - that._packets.dropIndex(addedIndexKeyString, function (error, result){ - if (error) { - cb(error); - } else { - that._packets.createIndex(addedIndexKey, {expireAfterSeconds: packetTTLInSeconds}, cb); - } - }); - } else { - // Create Index for the first time. - that._packets.createIndex(addedIndexKey, {expireAfterSeconds: packetTTLInSeconds}, cb); - } + function (cb) { + that._packets = db.collection('packets'); + steed.series([ + that._packets.createIndex.bind(that._packets, "client"), + function (cb) { + // Check expiration indexes. If not exist, create; If exist but with different TTL, delete and recreate; Otherwise, do nothing. + that._packets.indexes(function (error, colIndexes) { + if (error) { + cb(error); + } else { + var addedIndexKey = { "added": 1 }; + var addedIndexKeyString = 'added_1'; // If addedIndex changes, this value should also be changed accordingly. + var packetTTLInSeconds = Math.round(that.options.ttl.packets / 1000); + var addedIndexObj = colIndexes.filter(function (obj) { + return obj.name == addedIndexKeyString; + }); + + if (addedIndexObj.length <= 0 || addedIndexObj[0].expireAfterSeconds != packetTTLInSeconds) { + if (addedIndexObj.length > 0) { + // Different index TTL, recreate index to make sure the TTL is set to the new number. + that._packets.dropIndex(addedIndexKeyString, function (error, result) { + if (error) { + cb(error); + } else { + that._packets.createIndex(addedIndexKey, { expireAfterSeconds: packetTTLInSeconds }, cb); + } + }); } else { - cb(null); + // Create Index for the first time. + that._packets.createIndex(addedIndexKey, { expireAfterSeconds: packetTTLInSeconds }, cb); } + } else { + cb(null); } - }); - } - ], cb); - }); + } + }); + } + ], cb); }, - function(cb) { - db.collection("retained", function(err, coll) { - that._retained = coll; - that._retained.ensureIndex("topic", { unique: true }, cb); - }); + function (cb) { + that._retained = db.collection('retained'); + that._retained.createIndex('topic', { unique: true }, cb); } - ], function(err) { + ], function (err) { if (done) { done(err, that); } @@ -165,9 +158,15 @@ function MongoPersistence(options, done) { // Connect to the db if (options.connection) { - connected(null, this.options.connection); + connected(null, that.options.connection); } else { - MongoClient.connect(this.options.url, this.options.mongo, connected); + MongoClient.connect(that.options.url, this.options.mongo).then(function (mongoClient) { + var databaseArray = that.options.url.split('/'); + var databaseName = databaseArray[databaseArray.length - 1]; + connected(null, mongoClient.db(databaseName)); + }, function (e) { + throw new Error('Failed to connect with Database'); + }); } } @@ -178,7 +177,7 @@ util.inherits(MongoPersistence, AbstractPersistence); * * @api private */ -MongoPersistence.prototype.storeSubscriptions = function(client, done) { +MongoPersistence.prototype.storeSubscriptions = function (client, done) { var subscriptions; var that = this; @@ -190,62 +189,62 @@ MongoPersistence.prototype.storeSubscriptions = function(client, done) { // }); subscriptions = Object.keys(client.subscriptions); - steed.each(subscriptions, function(key, cb) { + steed.each(subscriptions, function (key, cb) { that._subscriptions.findAndModify({ client: client.id, topic: key }, [['date', -1]], { - $set: { - client: client.id, - topic: key, - qos: client.subscriptions[key].qos, - added: new Date() - } - }, { upsert: true}, cb); + $set: { + client: client.id, + topic: key, + qos: client.subscriptions[key].qos, + added: new Date() + } + }, { upsert: true }, cb); }, done); } else if (done) { return done(); } }; -MongoPersistence.prototype.lookupSubscriptions = function(client, done) { +MongoPersistence.prototype.lookupSubscriptions = function (client, done) { var that = this; this._subscriptions.find({ client: client.id }) - .toArray(function(err, subscriptions) { + .toArray(function (err, subscriptions) { - var now = Date.now(); - - subscriptions = (subscriptions || []).reduce(function(obj, sub) { - // mongodb TTL is not precise - if (sub.added.getTime() + that.options.ttl.subscriptions > now) { - obj[sub.topic] = { - qos: sub.qos - }; - } - return obj; - }, {}); + var now = Date.now(); - if (!client.clean) { - done(err, subscriptions); - return; - } + subscriptions = (subscriptions || []).reduce(function (obj, sub) { + // mongodb TTL is not precise + if (sub.added.getTime() + that.options.ttl.subscriptions > now) { + obj[sub.topic] = { + qos: sub.qos + }; + } + return obj; + }, {}); - var toExecute = [ - function removeSubscriptions(cb) { - that._subscriptions.remove({ client: client.id }, cb); - }, - function removePackets(cb) { - that._packets.remove({ client: client.id }, cb); + if (!client.clean) { + done(err, subscriptions); + return; } - ]; - steed.parallel(toExecute, function(err) { - done(null, {}); + var toExecute = [ + function removeSubscriptions(cb) { + that._subscriptions.remove({ client: client.id }, cb); + }, + function removePackets(cb) { + that._packets.remove({ client: client.id }, cb); + } + ]; + + steed.parallel(toExecute, function (err) { + done(null, {}); + }); }); - }); }; -MongoPersistence.prototype.storeRetained = function(packet, cb) { +MongoPersistence.prototype.storeRetained = function (packet, cb) { if (packet.payload.length > 0) { this._retained.update( { topic: packet.topic }, @@ -254,8 +253,8 @@ MongoPersistence.prototype.storeRetained = function(packet, cb) { upsert: true, w: 1 }, - function(err, n, result){ - if(cb) { + function (err, n, result) { + if (cb) { return cb(err); } }); @@ -267,7 +266,7 @@ MongoPersistence.prototype.storeRetained = function(packet, cb) { } }; -MongoPersistence.prototype.lookupRetained = function(pattern, cb) { +MongoPersistence.prototype.lookupRetained = function (pattern, cb) { var actual = escape(pattern).replace(/(#|\\\+).*$/, ''); var regexp = new RegExp(actual); var stream = this._retained.find({ topic: { $regex: regexp } }).stream(); @@ -277,11 +276,11 @@ MongoPersistence.prototype.lookupRetained = function(pattern, cb) { stream.on("error", cb); - stream.on("end", function() { + stream.on("end", function () { cb(null, matched); }); - stream.on("data", function(data) { + stream.on("data", function (data) { if (matcher.match(data.topic).size > 0) { data.payload = data.payload.buffer; matched.push(data); @@ -289,7 +288,7 @@ MongoPersistence.prototype.lookupRetained = function(pattern, cb) { }); }; -MongoPersistence.prototype.storeOfflinePacket = function(packet, done) { +MongoPersistence.prototype.storeOfflinePacket = function (packet, done) { var patterns = topicPatterns(packet.topic); @@ -303,10 +302,10 @@ MongoPersistence.prototype.storeOfflinePacket = function(packet, done) { stream.on("error", done); } - stream.on("data", function(data) { + stream.on("data", function (data) { started++; - that._storePacket(data.client, packet, function(err) { + that._storePacket(data.client, packet, function (err) { if (err) { return stream.emit("error", err); } @@ -320,7 +319,7 @@ MongoPersistence.prototype.storeOfflinePacket = function(packet, done) { }); }); - stream.on("end", function() { + stream.on("end", function () { ended = true; if (done && started === completed) { done(); @@ -328,34 +327,34 @@ MongoPersistence.prototype.storeOfflinePacket = function(packet, done) { }); }; -MongoPersistence.prototype._storePacket = function(client, packet, cb) { +MongoPersistence.prototype._storePacket = function (client, packet, cb) { var toStore = { client: client, packet: packet, added: new Date() }; - this._packets.insert(toStore, {w:1}, cb); + this._packets.insert(toStore, { w: 1 }, cb); }; -MongoPersistence.prototype.streamOfflinePackets = function(client, cb, done) { - +MongoPersistence.prototype.streamOfflinePackets = function (client, cb, done) { + var stream = this._packets.find({ client: client.id }).stream(); var that = this; var now = Date.now(); // for testing - if(done) + if (done) stream.on("end", done); stream.on("error", cb); - stream.on("data", function(data) { + stream.on("data", function (data) { // mongodb TTL is not precise // mongodb automaticly remove the packet if (data.added.getTime() + that.options.ttl.packets > now) { - data.packet.payload = data.packet.payload.hasOwnProperty('buffer') ? + data.packet.payload = data.packet.payload.hasOwnProperty('buffer') ? data.packet.payload.buffer : data.packet.payload; cb(null, data.packet); } @@ -363,27 +362,27 @@ MongoPersistence.prototype.streamOfflinePackets = function(client, cb, done) { }; -MongoPersistence.prototype.deleteOfflinePacket = function(client, messageId, cb) { +MongoPersistence.prototype.deleteOfflinePacket = function (client, messageId, cb) { var toSearch = { client: client.id, 'packet.messageId': messageId }; - this._packets.remove(toSearch, {w:1}, cb); + this._packets.remove(toSearch, { w: 1 }, cb); }; -MongoPersistence.prototype.updateOfflinePacket = function(client, messageId, packet, cb) { +MongoPersistence.prototype.updateOfflinePacket = function (client, messageId, packet, cb) { this._packets.update({ client: client.id, 'packet.messageId': messageId }, { - $set: { 'packet.messageId': packet.messageId } - }, {w:1}, function(err) { - cb(err, packet); - }); + $set: { 'packet.messageId': packet.messageId } + }, { w: 1 }, function (err) { + cb(err, packet); + }); }; -MongoPersistence.prototype.close = function(cb) { +MongoPersistence.prototype.close = function (cb) { if (this.db && this.options.autoClose !== false) { this.db.close(cb); } else { diff --git a/package.json b/package.json index 96b7a458..496c65a8 100644 --- a/package.json +++ b/package.json @@ -98,9 +98,9 @@ "websocket-stream": "~3.1.0" }, "optionalDependencies": { - "leveldown": "~1.4.3", "amqp": "~0.2.4", "ioredis": "^1.15.1", - "mongodb": "~2.1.4" + "leveldown": "^1.1.0", + "mongodb": "^3.1.13" } } diff --git a/test/cli.js b/test/cli.js index 2ed378d5..e73010c0 100644 --- a/test/cli.js +++ b/test/cli.js @@ -7,31 +7,31 @@ var os = require("os"); var SECURE_KEY = __dirname + '/secure/tls-key.pem'; var SECURE_CERT = __dirname + '/secure/tls-cert.pem'; -describe("mosca.cli", function() { +describe("mosca.cli", function () { var servers = null, oldDebug = null, args = null; - beforeEach(function(done) { + beforeEach(function (done) { args = ["node", "mosca"]; servers = [new mosca.Server({ port: 3833 }, done)]; }); - afterEach(function(done) { + afterEach(function (done) { var count = 0; - steed.each(servers, function(s, cb) { + steed.each(servers, function (s, cb) { count++; s.close(cb); - }, function() { + }, function () { done(); }); }); - var startServer = function(done, callback) { - return mosca.cli(args, function(err, server) { + var startServer = function (done, callback) { + return mosca.cli(args, function (err, server) { if (server) { servers.unshift(server); callback(server); @@ -40,81 +40,81 @@ describe("mosca.cli", function() { }); }; - it("must be a function", function() { + it("must be a function", function () { expect(mosca.cli).to.be.a("function"); }); - it("should start a mosca.Server", function(done) { - startServer(done, function(server) { + it("should start a mosca.Server", function (done) { + startServer(done, function (server) { expect(server).to.be.instanceOf(mosca.Server); }); }); - it("should support a port flag", function(done) { + it("should support a port flag", function (done) { args.push("-p"); args.push("2883"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.port).to.eql(2883); }); }); - it("should support a port flag (bis)", function(done) { + it("should support a port flag (bis)", function (done) { args.push("--port"); args.push("2883"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.port).to.eql(2883); }); }); - it("should support a parent port", function(done) { + it("should support a parent port", function (done) { args.push("--parent-port"); args.push("3833"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.backend.type).to.eql("mqtt"); expect(server.opts.backend.port).to.eql(3833); }); }); - it("should support a parent host", function(done) { + it("should support a parent host", function (done) { args.push("--parent-host"); args.push("localhost"); args.push("--parent-port"); args.push("3833"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.backend.type).to.eql("mqtt"); expect(server.opts.backend.host).to.eql("localhost"); }); }); - it("should support a parent prefix", function(done) { + it("should support a parent prefix", function (done) { args.push("--parent-port"); args.push("3833"); args.push("--parent-prefix"); args.push("/ahaha"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.backend.prefix).to.eql("/ahaha"); }); }); - it("should support a config option", function(done) { + it("should support a config option", function (done) { args.push("--config"); args.push("test/sample_config.js"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts).to.have.property("port", 2883); expect(server.opts).to.have.deep.property("backend.port", 3833); }); }); - it("should support a config option with an absolute path", function(done) { + it("should support a config option with an absolute path", function (done) { args.push("-c"); args.push(process.cwd() + "/test/sample_config.js"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts).to.have.property("port", 2883); expect(server.opts).to.have.deep.property("backend.port", 3833); }); }); - it("should add an user to an authorization file", function(done) { + it("should add an user to an authorization file", function (done) { args.push("adduser"); args.push("myuser"); args.push("mypass"); @@ -135,7 +135,7 @@ describe("mosca.cli", function() { }); }); - it("should add an user specifying the authorizePublish pattern", function(done) { + it("should add an user specifying the authorizePublish pattern", function (done) { args.push("adduser"); args.push("myuser"); args.push("mypass"); @@ -158,7 +158,7 @@ describe("mosca.cli", function() { }); }); - it("should add an user specifying the authorizeSubscribe pattern", function(done) { + it("should add an user specifying the authorizeSubscribe pattern", function (done) { args.push("adduser"); args.push("myuser"); args.push("mypass"); @@ -181,7 +181,7 @@ describe("mosca.cli", function() { }); }); - it("should remove an user from an authorization file", function(done) { + it("should remove an user from an authorization file", function (done) { args.push("adduser"); args.push("myuser"); args.push("mypass"); @@ -207,29 +207,29 @@ describe("mosca.cli", function() { }); }); - it("should support authorizing an authorized client", function(done) { + it("should support authorizing an authorized client", function (done) { args.push("--credentials"); args.push("test/credentials.json"); steed.waterfall([ - function(cb) { + function (cb) { mosca.cli(args, cb); }, - function(server, cb) { + function (server, cb) { servers.unshift(server); var options = { username: "test", password: "test", port: 1883 }; var client = mqtt.connect(options); client.on("error", cb); - client.on("connect", function() { + client.on("connect", function () { cb(null, client); }); }, - function(client, cb) { + function (client, cb) { client.once("close", cb); client.end(); } - ], function(err) { - if(err instanceof Error) { + ], function (err) { + if (err instanceof Error) { done(err); return; } @@ -237,28 +237,28 @@ describe("mosca.cli", function() { }); }); - it("should support negating an unauthorized client", function(done) { + it("should support negating an unauthorized client", function (done) { args.push("--credentials"); args.push("test/credentials.json"); steed.waterfall([ - function(cb) { + function (cb) { mosca.cli(args, cb); }, - function(server, cb) { + function (server, cb) { servers.unshift(server); var options = { port: 1883, username: "bad", password: "bad" }; var client = mqtt.connect(options); client.on("error", cb); - client.on("connect", function() { + client.on("connect", function () { cb(null, client); }); }, - function(client, cb) { + function (client, cb) { client.once("close", cb); client.end(); } - ], function(err) { - if(err) { + ], function (err) { + if (err) { done(); return; } @@ -266,9 +266,9 @@ describe("mosca.cli", function() { }); }); - it("should reload the current config if killed with SIGHUP on a Linux-based OS", function(done) { + it("should reload the current config if killed with SIGHUP on a Linux-based OS", function (done) { - if(os.platform() === "win32") return done(); + if (os.platform() === "win32") return done(); args.push("adduser"); args.push("myuser"); @@ -278,41 +278,41 @@ describe("mosca.cli", function() { var cloned = null; steed.waterfall([ - function(cb) { + function (cb) { tmp.file(cb); }, - function(path, fd, ignore, cb) { + function (path, fd, ignore, cb) { args.push(path); cloned = [].concat(args); cloned[2] = "rmuser"; mosca.cli(args, cb); }, - function(cb) { + function (cb) { mosca.cli(["node", "mosca", "--credentials", cloned[cloned.length - 1]], cb); }, - function(server, cb) { + function (server, cb) { servers.unshift(server); - setTimeout(function() { + setTimeout(function () { mosca.cli(cloned, cb); }, 300); }, - function(cb) { + function (cb) { process.kill(process.pid, 'SIGHUP'); setTimeout(cb, 50); }, - function(cb) { + function (cb) { var options = { port: 1883, username: "myuser", password: "mypass" }; var client = mqtt.connect(options); client.once("error", cb); - client.once("connect", function() { + client.once("connect", function () { client.once("close", cb); client.end(); }); } - ], function(err) { - if(err) { + ], function (err) { + if (err) { done(); return; } @@ -320,7 +320,7 @@ describe("mosca.cli", function() { }); }); - it("should save the credentials.json as a formatted JSON when adding", function(done) { + it("should save the credentials.json as a formatted JSON when adding", function (done) { args.push("adduser"); args.push("myuser"); args.push("mypass"); @@ -341,7 +341,7 @@ describe("mosca.cli", function() { }); }); - it("should save the credentials.json as a formatted JSON when removing", function(done) { + it("should save the credentials.json as a formatted JSON when removing", function (done) { args.push("adduser"); args.push("myuser"); args.push("mypass"); @@ -368,13 +368,13 @@ describe("mosca.cli", function() { }); }); - it("should create a memory persistence object", function(done) { - var s = startServer(done, function(server) { + it("should create a memory persistence object", function (done) { + var s = startServer(done, function (server) { expect(server.persistence).to.be.instanceOf(mosca.persistence.Memory); }); }); - it("should create a leveldb with the --db flag", function(done) { + it("should create a leveldb with the --db flag", function (done) { tmp.dir(function (err, path, fd) { if (err) { @@ -385,142 +385,142 @@ describe("mosca.cli", function() { args.push("--db"); args.push(path); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.persistence).to.be.instanceOf(mosca.persistence.LevelUp); expect(server.persistence.options.path).to.eql(path); }); }); }); - describe("with --key and --cert", function() { + describe("with --key and --cert", function () { - beforeEach(function() { + beforeEach(function () { args.push("--key"); args.push(SECURE_KEY); args.push("--cert"); args.push(SECURE_CERT); }); - it("should pass key and cert to the server", function(done) { - startServer(done, function(server) { + it("should pass key and cert to the server", function (done) { + startServer(done, function (server) { expect(server.opts.secure.keyPath).to.eql(SECURE_KEY); expect(server.opts.secure.certPath).to.eql(SECURE_CERT); }); }); - it("should support the --secure-port flag", function(done) { + it("should support the --secure-port flag", function (done) { var port = nextPort(); args.push("--secure-port"); args.push(port); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.secure.port).to.eql(port); }); }); - it("should set the secure port by default at 8883", function(done) { - startServer(done, function(server) { + it("should set the secure port by default at 8883", function (done) { + startServer(done, function (server) { expect(server.opts.secure.port).to.eql(8883); }); }); - it("should pass the --non-secure flag to the server", function(done) { + it("should pass the --non-secure flag to the server", function (done) { args.push("--non-secure"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.allowNonSecure).to.eql(true); }); }); - it("should allow to set the https port", function(done) { + it("should allow to set the https port", function (done) { args.push("--https-port"); args.push("3000"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.https.port).to.eql(3000); }); }); - it("should serve a HTTPS static directory", function(done) { + it("should serve a HTTPS static directory", function (done) { args.push("--https-port"); args.push("3000"); args.push("--https-static"); args.push("/path/to/nowhere"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.https.static).to.eql("/path/to/nowhere"); }); }); - it("should serve a HTTPS browserify bundle", function(done) { + it("should serve a HTTPS browserify bundle", function (done) { args.push("--https-port"); args.push("3000"); args.push("--https-bundle"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.https.bundle).to.eql(true); }); }); }); - it("should allow to set the http port", function(done) { + it("should allow to set the http port", function (done) { args.push("--http-port"); args.push("3000"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.http.port).to.eql(3000); }); }); - it("should allow to limit the server only to http", function(done) { + it("should allow to limit the server only to http", function (done) { args.push("--http-port"); args.push("3000"); args.push("--only-http"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.http.port).to.eql(3000); }); }); - it("should serve a HTTP static directory", function(done) { + it("should serve a HTTP static directory", function (done) { args.push("--http-port"); args.push("3000"); args.push("--http-static"); args.push("/path/to/nowhere"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.http.static).to.eql("/path/to/nowhere"); }); }); - it("should serve a HTTP browserify bundle", function(done) { + it("should serve a HTTP browserify bundle", function (done) { args.push("--http-port"); args.push("3000"); args.push("--http-bundle"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.http.bundle).to.eql(true); }); }); - it("should have stats enabled by default", function(done) { - var s = startServer(done, function(server) { + it("should have stats enabled by default", function (done) { + var s = startServer(done, function (server) { expect(server.opts.stats).to.equal(true); }); }); - it("should allow to disable stats", function(done) { + it("should allow to disable stats", function (done) { args.push("--disable-stats"); - var s = startServer(done, function(server) { + var s = startServer(done, function (server) { expect(server.opts.stats).to.equal(false); }); }); - it("should allow to specify a broker id", function(done) { + it("should allow to specify a broker id", function (done) { args.push("--broker-id"); args.push("44cats"); - var s = startServer(done, function(server) { + var s = startServer(done, function (server) { expect(server.id).to.equal("44cats"); }); }); - it("should specify an interface to bind to", function(done) { + it("should specify an interface to bind to", function (done) { args.push("--host"); args.push("127.0.0.1"); - startServer(done, function(server) { + startServer(done, function (server) { expect(server.opts.host).to.eql("127.0.0.1"); }); });