Skip to content

Commit 29fda04

Browse files
committed
Plugin and tests improvements.
1 parent 04c072c commit 29fda04

File tree

4 files changed

+145
-32
lines changed

4 files changed

+145
-32
lines changed

lib/docker.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ Docker.prototype.getVolume = function(name) {
252252
* Fetches a Plugin by name
253253
* @param {String} name Volume's name
254254
*/
255-
Docker.prototype.getPlugin = function(name) {
256-
return new Plugin(this.modem, name);
255+
Docker.prototype.getPlugin = function(name, remote) {
256+
return new Plugin(this.modem, name, remote);
257257
};
258258

259259
/**
@@ -490,30 +490,6 @@ Docker.prototype.createPlugin = function(opts, callback) {
490490
});
491491
};
492492

493-
/**
494-
* Installs a new plugin
495-
* @param {Object} opts Create options
496-
* @param {Function} callback Callback
497-
*/
498-
Docker.prototype.installPlugin = function(opts, callback) {
499-
var args = util.processArgs(opts, callback);
500-
var self = this;
501-
var optsf = {
502-
path: '/plugins/pull?',
503-
method: 'POST',
504-
options: args.opts,
505-
statusCodes: {
506-
200: true, // unofficial, but proxies may return it
507-
204: true,
508-
500: 'server error'
509-
}
510-
};
511-
512-
this.modem.dial(optsf, function(err, data) {
513-
if (err) return args.callback(err, data);
514-
args.callback(err, self.getNetwork(data.Id));
515-
});
516-
};
517493

518494
/**
519495
* Lists plugins

lib/plugin.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ var util = require('./util');
55
* @param {Object} modem docker-modem
66
* @param {String} name Plugin's name
77
*/
8-
var Plugin = function(modem, name) {
8+
var Plugin = function(modem, name, remote) {
99
this.modem = modem;
1010
this.name = name;
11+
this.remote = remote || name;
1112
};
1213

1314
/**
@@ -72,7 +73,7 @@ Plugin.prototype.privileges = function(callback) {
7273
path: '/plugins/privileges?',
7374
method: 'GET',
7475
options: {
75-
'name': this.name
76+
'remote': this.remote
7677
},
7778
statusCodes: {
7879
200: true,
@@ -86,6 +87,40 @@ Plugin.prototype.privileges = function(callback) {
8687
};
8788

8889

90+
/**
91+
* Installs a new plugin
92+
* @param {Object} opts Create options
93+
* @param {Function} callback Callback
94+
*/
95+
Plugin.prototype.install = function(opts, callback) {
96+
var args = util.processArgs(opts, callback);
97+
98+
if(args.opts.query && !args.opts.query.name) {
99+
args.opts.query.name = this.name;
100+
}
101+
if(args.opts.query && !args.opts.query.remote) {
102+
args.opts.query.remote = this.remote;
103+
}
104+
105+
var self = this;
106+
var optsf = {
107+
path: '/plugins/pull?',
108+
method: 'POST',
109+
isStream: true,
110+
options: args.opts,
111+
statusCodes: {
112+
200: true, // unofficial, but proxies may return it
113+
204: true,
114+
500: 'server error'
115+
}
116+
};
117+
118+
this.modem.dial(optsf, function(err, data) {
119+
args.callback(err, data);
120+
});
121+
};
122+
123+
89124
/**
90125
* Enable
91126
* @param {Object} opts Plugin enable options (optional)

test/plugin.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,102 @@ describe("#plugin", function() {
2020
});
2121
});
2222

23+
describe("#install", function() {
24+
25+
it("should get plugin privileges", function(done) {
26+
this.timeout(15000);
27+
var plugin = docker.getPlugin('sshfs', 'vieux/sshfs');
28+
29+
function handler(err, data) {
30+
expect(err).to.be.null;
31+
expect(data).to.be.a('array');
32+
console.log(data);
33+
done();
34+
}
35+
36+
plugin.privileges(handler);
37+
});
38+
39+
it("should pull a plugin", function(done) {
40+
this.timeout(60000);
41+
42+
var plugin = docker.getPlugin('sshfs');
43+
44+
//geezzz url, querystring and body...
45+
plugin.install({
46+
'_query': {
47+
'remote': 'vieux/sshfs'
48+
},
49+
'_body': [{
50+
'Name': 'network',
51+
'Description': '',
52+
'Value': [
53+
'host'
54+
]
55+
}, {
56+
'Name': 'capabilities',
57+
'Description': '',
58+
'Value': [
59+
'CAP_SYS_ADMIN'
60+
]
61+
}, {
62+
'Name': 'mount',
63+
'Description': '',
64+
'Value': [
65+
'/var/lib/docker/plugins/'
66+
]
67+
}, {
68+
'Name': 'device',
69+
'Description': '',
70+
'Value': [
71+
'/dev/fuse'
72+
]
73+
}]
74+
}, function(err, stream) {
75+
if (err) return done(err);
76+
stream.pipe(process.stdout);
77+
stream.once('end', done);
78+
});
79+
80+
});
81+
82+
it("should enable a plugin", function(done) {
83+
this.timeout(15000);
84+
var plugin = docker.getPlugin('sshfs');
85+
86+
function handler(err, data) {
87+
expect(err).to.be.null;
88+
expect(data).to.be.ok;
89+
done();
90+
}
91+
92+
plugin.enable(handler);
93+
});
94+
95+
it("should disable a plugin", function(done) {
96+
this.timeout(15000);
97+
var plugin = docker.getPlugin('sshfs');
98+
99+
function handler(err, data) {
100+
expect(err).to.be.null;
101+
expect(data).to.be.ok;
102+
done();
103+
}
104+
105+
plugin.disable(handler);
106+
});
107+
108+
it("should remove a plugin", function(done) {
109+
this.timeout(15000);
110+
var plugin = docker.getPlugin('sshfs');
111+
112+
function handler(err, data) {
113+
expect(err).to.be.null;
114+
expect(data).to.be.ok;
115+
done();
116+
}
117+
118+
plugin.remove(handler);
119+
});
120+
});
23121
});

test/swarm.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe("#swarm", function() {
5050

5151
describe("#Secrets", function() {
5252
var secret;
53+
var d;
5354

5455
it("should list secrets", function(done) {
5556
this.timeout(5000);
@@ -88,6 +89,7 @@ describe("#swarm", function() {
8889
function handler(err, data) {
8990
expect(err).to.be.null;
9091
expect(data).to.be.ok;
92+
d = data;
9193
done();
9294
}
9395
secret.inspect(handler);
@@ -99,12 +101,12 @@ describe("#swarm", function() {
99101

100102
function handler(err, data) {
101103
expect(err).to.be.null;
102-
expect(data).to.be.ok;
104+
expect(data).to.be.empty;
103105
done();
104106
}
105107
var opts = {
106108
"Name": "app-key.crt",
107-
"version": 2,
109+
"version": parseInt(d.Version.Index),
108110
"Labels": {
109111
"foo": "bar",
110112
"foo2": "bar2"
@@ -129,9 +131,10 @@ describe("#swarm", function() {
129131

130132
describe("#Services", function() {
131133
var service;
134+
var d;
132135

133136
it("should create service", function(done) {
134-
this.timeout(30000);
137+
this.timeout(60000);
135138

136139
function handler(err, data) {
137140
expect(err).to.be.null;
@@ -193,6 +196,7 @@ describe("#swarm", function() {
193196
function handler(err, data) {
194197
expect(err).to.be.null;
195198
expect(data).to.be.ok;
199+
d = data;
196200
done();
197201
}
198202
service.inspect(handler);
@@ -208,7 +212,7 @@ describe("#swarm", function() {
208212
}
209213
var opts = {
210214
"Name": "redis",
211-
"version": 2,
215+
"version": parseInt(d.Version.Index),
212216
"TaskTemplate": {
213217
"ContainerSpec": {
214218
"Image": "redis"

0 commit comments

Comments
 (0)