diff --git a/lib/container.js b/lib/container.js index 61e8690..d4292d1 100644 --- a/lib/container.js +++ b/lib/container.js @@ -42,18 +42,19 @@ var Container = function(modem, id) { */ Container.prototype.inspect = function(opts, callback) { var args = util.processArgs(opts, callback); - var optsf = { - path: '/containers/' + this.id + '/json?', - method: 'GET', - options: args.opts, - statusCodes: { - 200: true, - 404: 'no such container', - 500: 'server error' - } - }; if (typeof args.callback === 'function') { + var optsf = { + path: '/containers/' + this.id + '/json?', + method: 'GET', + options: args.opts, + statusCodes: { + 200: true, + 404: 'no such container', + 500: 'server error' + } + }; + this.modem.dial(optsf, function(err, data) { args.callback(err, data); }); @@ -65,10 +66,10 @@ Container.prototype.inspect = function(opts, callback) { }; /** -* Rename -* @param {Object} opts Rename options -* @param {Function} callback Callback -*/ + * Rename + * @param {Object} opts Rename options + * @param {Function} callback Callback + */ Container.prototype.rename = function(opts, callback) { var args = util.processArgs(opts, callback, this.defaultOptions.rename); @@ -252,7 +253,7 @@ Container.prototype.exec = function(opts, callback) { var self = this; this.modem.dial(optsf, function(err, data) { - if(err) return args.callback(err, data); + if (err) return args.callback(err, data); args.callback(err, new Exec(self.modem, data.Id)); }); }; @@ -565,7 +566,6 @@ Container.prototype.putArchive = function(file, opts, callback) { }); }; - /** * Container logs * @param {Object} opts Logs options. (optional) @@ -592,10 +592,10 @@ Container.prototype.logs = function(opts, callback) { }; /** -* Container stats -* @param {Object} opts Stats options. (optional) -* @param {Function} callback Callback with data -*/ + * Container stats + * @param {Object} opts Stats options. (optional) + * @param {Function} callback Callback with data + */ Container.prototype.stats = function(opts, callback) { var args = util.processArgs(opts, callback, this.defaultOptions.stats); diff --git a/package.json b/package.json index 9f19636..70ac437 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "docker.io" ], "dependencies": { - "docker-modem": "0.2.x" + "docker-modem": "0.3.x" }, "devDependencies": { "chai": "~1.7.0", diff --git a/test/docker.js b/test/docker.js index 2ce8cfe..9c87767 100644 --- a/test/docker.js +++ b/test/docker.js @@ -351,8 +351,6 @@ describe("#docker", function() { }); }); - - describe("#createContainer", function() { it("should create and remove a container", function(done) { this.timeout(5000); @@ -463,7 +461,6 @@ describe("#docker", function() { }); }); - describe("#version", function() { it("should return version", function(done) { this.timeout(5000); @@ -512,18 +509,17 @@ describe("#docker", function() { var created_containers = []; // after fn to cleanup created containers after testsuite execution - after(function(done){ + after(function(done) { if (!created_containers.length) return done(); - created_containers.forEach(function(container, index){ + created_containers.forEach(function(container, index) { container.remove(function(err, data) { - created_containers.splice(index); - if (!created_containers.length) return done(err); + if (index === created_containers.length - 1) return done(err); }); }); }); // helper fn to create labeled containers and verify through inspection - var createLabledContainer = function(label_map, callback){ + var createLabledContainer = function(label_map, callback) { function handler(err, container) { expect(err).to.be.null; expect(container).to.be.ok; @@ -534,7 +530,7 @@ describe("#docker", function() { expect(info.Config.Labels).to.deep.equal(label_map); callback(); }); - }; + } docker.createContainer({ "Image": testImage, @@ -543,31 +539,36 @@ describe("#docker", function() { }, handler); }; - it("should create a container with an empty value label", function(done){ + it("should create a container with an empty value label", function(done) { this.timeout(5000); - createLabledContainer({"dockerode-test-label": ""}, done); + createLabledContainer({ + "dockerode-test-label": "" + }, done); }); - it("should create a container with an assigned value label", function(done){ + it("should create a container with an assigned value label", function(done) { this.timeout(5000); - createLabledContainer({"dockerode-test-label": "", "dockerode-test-value-label": "assigned"}, done); + createLabledContainer({ + "dockerode-test-label": "", + "dockerode-test-value-label": "assigned" + }, done); }); - it("should query containers filtering by valueless labels", function(done){ + it("should query containers filtering by valueless labels", function(done) { docker.listContainers({ "limit": 3, "filters": '{"label": ["dockerode-test-label"]}' - }, function(err, data){ + }, function(err, data) { expect(data.length).to.equal(2); done(); }); }); - it("should query containers filtering by valued labels", function(done){ + it("should query containers filtering by valued labels", function(done) { docker.listContainers({ "limit": 3, "filters": '{"label": ["dockerode-test-label", "dockerode-test-value-label=assigned"]}' - }, function(err, data){ + }, function(err, data) { expect(data.length).to.equal(1); done(); }); diff --git a/test/networks.js b/test/networks.js index 6f830d5..7f01389 100644 --- a/test/networks.js +++ b/test/networks.js @@ -7,6 +7,8 @@ var MemoryStream = require('memorystream'); describe("#networks", function() { var testContainer; + var testNetwork; + before(function(done) { docker.createContainer({ Image: 'ubuntu', @@ -22,10 +24,26 @@ describe("#networks", function() { testContainer = container.id; container.start(function(err, result) { if (err) done(err); - done(); + + docker.createNetwork({ + "Name": "isolated_nw", + "Driver": "bridge", + "IPAM": { + "Config": [{ + "Subnet": "172.20.0.0/16", + "IPRange": "172.20.10.0/24", + "Gateway": "172.20.10.11" + }] + } + }, function(err, network) { + if (err) done(err); + testNetwork = network; + done(); + }); }); }); }); + after(function(done) { this.timeout(15000); var container = docker.getContainer(testContainer); @@ -33,33 +51,12 @@ describe("#networks", function() { if (err) done(err); container.remove(function(err, result) { if (err) done(err); - done(); - }); - }); - }); - var testNetwork; - before(function(done) { - docker.createNetwork({ - "Name": "isolated_nw", - "Driver": "bridge", - "IPAM": { - "Config": [{ - "Subnet": "172.20.0.0/16", - "IPRange": "172.20.10.0/24", - "Gateway": "172.20.10.11" - }] - } - }, function(err, network) { - if (err) done(err); - testNetwork = network; - done(); - }); - }); - after(function(done) { - testNetwork.remove(function(err, result) { - if (err) done(err); - done(); + testNetwork.remove(function(err, result) { + if (err) done(err); + done(); + }); + }); }); }); @@ -110,4 +107,4 @@ describe("#networks", function() { }); }); -}); \ No newline at end of file +});