Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Jan 4, 2016
1 parent b056c95 commit 51d55c0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 66 deletions.
40 changes: 20 additions & 20 deletions lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);

Expand Down Expand Up @@ -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));
});
};
Expand Down Expand Up @@ -565,7 +566,6 @@ Container.prototype.putArchive = function(file, opts, callback) {
});
};


/**
* Container logs
* @param {Object} opts Logs options. (optional)
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"docker.io"
],
"dependencies": {
"docker-modem": "0.2.x"
"docker-modem": "0.3.x"
},
"devDependencies": {
"chai": "~1.7.0",
Expand Down
35 changes: 18 additions & 17 deletions test/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ describe("#docker", function() {
});
});



describe("#createContainer", function() {
it("should create and remove a container", function(done) {
this.timeout(5000);
Expand Down Expand Up @@ -463,7 +461,6 @@ describe("#docker", function() {
});
});


describe("#version", function() {
it("should return version", function(done) {
this.timeout(5000);
Expand Down Expand Up @@ -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;
Expand All @@ -534,7 +530,7 @@ describe("#docker", function() {
expect(info.Config.Labels).to.deep.equal(label_map);
callback();
});
};
}

docker.createContainer({
"Image": testImage,
Expand All @@ -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();
});
Expand Down
53 changes: 25 additions & 28 deletions test/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var MemoryStream = require('memorystream');
describe("#networks", function() {

var testContainer;
var testNetwork;

before(function(done) {
docker.createContainer({
Image: 'ubuntu',
Expand All @@ -22,44 +24,39 @@ 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);
container.kill(function(err, result) {
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();
});
});
});
});

Expand Down Expand Up @@ -110,4 +107,4 @@ describe("#networks", function() {
});
});

});
});

0 comments on commit 51d55c0

Please sign in to comment.