Skip to content

Commit

Permalink
Plugin and tests improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Feb 28, 2017
1 parent 04c072c commit 29fda04
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 32 deletions.
28 changes: 2 additions & 26 deletions lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ Docker.prototype.getVolume = function(name) {
* Fetches a Plugin by name
* @param {String} name Volume's name
*/
Docker.prototype.getPlugin = function(name) {
return new Plugin(this.modem, name);
Docker.prototype.getPlugin = function(name, remote) {
return new Plugin(this.modem, name, remote);
};

/**
Expand Down Expand Up @@ -490,30 +490,6 @@ Docker.prototype.createPlugin = function(opts, callback) {
});
};

/**
* Installs a new plugin
* @param {Object} opts Create options
* @param {Function} callback Callback
*/
Docker.prototype.installPlugin = function(opts, callback) {
var args = util.processArgs(opts, callback);
var self = this;
var optsf = {
path: '/plugins/pull?',
method: 'POST',
options: args.opts,
statusCodes: {
200: true, // unofficial, but proxies may return it
204: true,
500: 'server error'
}
};

this.modem.dial(optsf, function(err, data) {
if (err) return args.callback(err, data);
args.callback(err, self.getNetwork(data.Id));
});
};

/**
* Lists plugins
Expand Down
39 changes: 37 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ var util = require('./util');
* @param {Object} modem docker-modem
* @param {String} name Plugin's name
*/
var Plugin = function(modem, name) {
var Plugin = function(modem, name, remote) {
this.modem = modem;
this.name = name;
this.remote = remote || name;
};

/**
Expand Down Expand Up @@ -72,7 +73,7 @@ Plugin.prototype.privileges = function(callback) {
path: '/plugins/privileges?',
method: 'GET',
options: {
'name': this.name
'remote': this.remote
},
statusCodes: {
200: true,
Expand All @@ -86,6 +87,40 @@ Plugin.prototype.privileges = function(callback) {
};


/**
* Installs a new plugin
* @param {Object} opts Create options
* @param {Function} callback Callback
*/
Plugin.prototype.install = function(opts, callback) {
var args = util.processArgs(opts, callback);

if(args.opts.query && !args.opts.query.name) {
args.opts.query.name = this.name;
}
if(args.opts.query && !args.opts.query.remote) {
args.opts.query.remote = this.remote;
}

var self = this;
var optsf = {
path: '/plugins/pull?',
method: 'POST',
isStream: true,
options: args.opts,
statusCodes: {
200: true, // unofficial, but proxies may return it
204: true,
500: 'server error'
}
};

this.modem.dial(optsf, function(err, data) {
args.callback(err, data);
});
};


/**
* Enable
* @param {Object} opts Plugin enable options (optional)
Expand Down
98 changes: 98 additions & 0 deletions test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,102 @@ describe("#plugin", function() {
});
});

describe("#install", function() {

it("should get plugin privileges", function(done) {
this.timeout(15000);
var plugin = docker.getPlugin('sshfs', 'vieux/sshfs');

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.a('array');
console.log(data);
done();
}

plugin.privileges(handler);
});

it("should pull a plugin", function(done) {
this.timeout(60000);

var plugin = docker.getPlugin('sshfs');

//geezzz url, querystring and body...
plugin.install({
'_query': {
'remote': 'vieux/sshfs'
},
'_body': [{
'Name': 'network',
'Description': '',
'Value': [
'host'
]
}, {
'Name': 'capabilities',
'Description': '',
'Value': [
'CAP_SYS_ADMIN'
]
}, {
'Name': 'mount',
'Description': '',
'Value': [
'/var/lib/docker/plugins/'
]
}, {
'Name': 'device',
'Description': '',
'Value': [
'/dev/fuse'
]
}]
}, function(err, stream) {
if (err) return done(err);
stream.pipe(process.stdout);
stream.once('end', done);
});

});

it("should enable a plugin", function(done) {
this.timeout(15000);
var plugin = docker.getPlugin('sshfs');

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}

plugin.enable(handler);
});

it("should disable a plugin", function(done) {
this.timeout(15000);
var plugin = docker.getPlugin('sshfs');

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}

plugin.disable(handler);
});

it("should remove a plugin", function(done) {
this.timeout(15000);
var plugin = docker.getPlugin('sshfs');

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
done();
}

plugin.remove(handler);
});
});
});
12 changes: 8 additions & 4 deletions test/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe("#swarm", function() {

describe("#Secrets", function() {
var secret;
var d;

it("should list secrets", function(done) {
this.timeout(5000);
Expand Down Expand Up @@ -88,6 +89,7 @@ describe("#swarm", function() {
function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
d = data;
done();
}
secret.inspect(handler);
Expand All @@ -99,12 +101,12 @@ describe("#swarm", function() {

function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
expect(data).to.be.empty;
done();
}
var opts = {
"Name": "app-key.crt",
"version": 2,
"version": parseInt(d.Version.Index),
"Labels": {
"foo": "bar",
"foo2": "bar2"
Expand All @@ -129,9 +131,10 @@ describe("#swarm", function() {

describe("#Services", function() {
var service;
var d;

it("should create service", function(done) {
this.timeout(30000);
this.timeout(60000);

function handler(err, data) {
expect(err).to.be.null;
Expand Down Expand Up @@ -193,6 +196,7 @@ describe("#swarm", function() {
function handler(err, data) {
expect(err).to.be.null;
expect(data).to.be.ok;
d = data;
done();
}
service.inspect(handler);
Expand All @@ -208,7 +212,7 @@ describe("#swarm", function() {
}
var opts = {
"Name": "redis",
"version": 2,
"version": parseInt(d.Version.Index),
"TaskTemplate": {
"ContainerSpec": {
"Image": "redis"
Expand Down

0 comments on commit 29fda04

Please sign in to comment.