Skip to content

Commit e4f49da

Browse files
committed
[Add] full tests for plugin api
1 parent 6b2bf29 commit e4f49da

File tree

2 files changed

+253
-30
lines changed

2 files changed

+253
-30
lines changed

plugin.go

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type PluginPrivilege struct {
2020
Value []string `json:"Value,omitempty" yaml:"Value,omitempty" toml:"Value,omitempty"`
2121
}
2222

23-
// InstallPluginOptions This is a TBD Comments.
23+
// InstallPluginOptions .This is a TBD Comments.
2424
//
2525
// See https://goo.gl/kaOHGw for more details.
2626
type InstallPluginOptions struct {
@@ -51,7 +51,7 @@ func (c *Client) InstallPlugins(opts InstallPluginOptions, auth AuthConfiguratio
5151
return nil
5252
}
5353

54-
// PluginSetting This is a TBD Comments.
54+
// PluginSetting .This is a TBD Comments.
5555
//
5656
// See https://goo.gl/kaOHGw for more details.
5757
type PluginSetting struct {
@@ -60,22 +60,22 @@ type PluginSetting struct {
6060
Devices []string `json:"Devices,omitempty" yaml:"Devices,omitempty" toml:"Devices,omitempty"`
6161
}
6262

63-
// PluginInterface This is a TBD Comments.
63+
// PluginInterface .This is a TBD Comments.
6464
//
6565
// See https://goo.gl/kaOHGw for more details.
6666
type PluginInterface struct {
6767
Types []string `json:"Types,omitempty" yaml:"Types,omitempty" toml:"Types,omitempty"`
6868
Socket string `json:"Socket,omitempty" yaml:"Socket,omitempty" toml:"Socket,omitempty"`
6969
}
7070

71-
// PluginNetwork This is a TBD Comments.
71+
// PluginNetwork .This is a TBD Comments.
7272
//
7373
// See https://goo.gl/kaOHGw for more details.
7474
type PluginNetwork struct {
7575
Type string `json:"Type,omitempty" yaml:"Type,omitempty" toml:"Type,omitempty"`
7676
}
7777

78-
// PluginLinux This is a TBD Comments.
78+
// PluginLinux .This is a TBD Comments.
7979
//
8080
// See https://goo.gl/kaOHGw for more details.
8181
type PluginLinux struct {
@@ -84,7 +84,7 @@ type PluginLinux struct {
8484
Devices []PluginLinuxDevices `json:"Devices,omitempty" yaml:"Devices,omitempty" toml:"Devices,omitempty"`
8585
}
8686

87-
// PluginLinuxDevices This is a TBD Comments.
87+
// PluginLinuxDevices .This is a TBD Comments.
8888
//
8989
// See https://goo.gl/kaOHGw for more details.
9090
type PluginLinuxDevices struct {
@@ -94,35 +94,35 @@ type PluginLinuxDevices struct {
9494
Path string `json:"Path,omitempty" yaml:"Path,omitempty" toml:"Path,omitempty"`
9595
}
9696

97-
// PluginEnv This is a TBD Comments.
97+
// PluginEnv .This is a TBD Comments.
9898
//
9999
// See https://goo.gl/kaOHGw for more details.
100100
type PluginEnv struct {
101101
Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
102-
Description string `json:"Documentation,omitempty" yaml:"Documentation,omitempty" toml:"Documentation,omitempty"`
102+
Description string `json:"Description,omitempty" yaml:"Description,omitempty" toml:"Description,omitempty"`
103103
Settable []string `json:"Settable,omitempty" yaml:"Settable,omitempty" toml:"Settable,omitempty"`
104104
Value string `json:"Value,omitempty" yaml:"Value,omitempty" toml:"Value,omitempty"`
105105
}
106106

107-
// PluginArgs This is a TBD Comments.
107+
// PluginArgs .This is a TBD Comments.
108108
//
109109
// See https://goo.gl/kaOHGw for more details.
110110
type PluginArgs struct {
111111
Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
112-
Description string `json:"Documentation,omitempty" yaml:"Documentation,omitempty" toml:"Documentation,omitempty"`
112+
Description string `json:"Description,omitempty" yaml:"Description,omitempty" toml:"Description,omitempty"`
113113
Settable []string `json:"Settable,omitempty" yaml:"Settable,omitempty" toml:"Settable,omitempty"`
114114
Value []string `json:"Value,omitempty" yaml:"Value,omitempty" toml:"Value,omitempty"`
115115
}
116116

117-
// PluginUser This is a TBD Comments.
117+
// PluginUser .This is a TBD Comments.
118118
//
119119
// See https://goo.gl/kaOHGw for more details.
120120
type PluginUser struct {
121121
UID int32 `json:"UID,omitempty" yaml:"UID,omitempty" toml:"UID,omitempty"`
122122
GID int32 `json:"GID,omitempty" yaml:"GID,omitempty" toml:"GID,omitempty"`
123123
}
124124

125-
// PluginConfig This is a TBD Comments.
125+
// PluginConfig .This is a TBD Comments.
126126
//
127127
// See https://goo.gl/kaOHGw for more details.
128128
type PluginConfig struct {
@@ -140,7 +140,7 @@ type PluginConfig struct {
140140
Args PluginArgs `json:"Args,omitempty" yaml:"Args,omitempty" toml:"Args,omitempty"`
141141
}
142142

143-
// PluginDetail This is a TBD Comments.
143+
// PluginDetail .This is a TBD Comments.
144144
//
145145
// See https://goo.gl/kaOHGw for more details.
146146
type PluginDetail struct {
@@ -152,7 +152,7 @@ type PluginDetail struct {
152152
Config PluginConfig `json:"Config,omitempty" yaml:"Config,omitempty" toml:"Config,omitempty"`
153153
}
154154

155-
// ListPlugins This is a TBD Comments.
155+
// ListPlugins .This is a TBD Comments.
156156
//
157157
// See https://goo.gl/kaOHGw for more details.
158158
func (c *Client) ListPlugins() ([]PluginDetail, error) {
@@ -168,7 +168,7 @@ func (c *Client) ListPlugins() ([]PluginDetail, error) {
168168
return pluginDetails, nil
169169
}
170170

171-
// GetPluginPrivileges This is a TBD Comments.
171+
// GetPluginPrivileges .This is a TBD Comments.
172172
//
173173
// See https://goo.gl/kaOHGw for more details.
174174
func (c *Client) GetPluginPrivileges(name string) ([]PluginPrivilege, error) {
@@ -177,14 +177,37 @@ func (c *Client) GetPluginPrivileges(name string) ([]PluginPrivilege, error) {
177177
return nil, err
178178
}
179179
defer resp.Body.Close()
180-
pluginPrivileges := make([]PluginPrivilege, 0)
180+
var pluginPrivileges []PluginPrivilege
181181
if err := json.NewDecoder(resp.Body).Decode(&pluginPrivileges); err != nil {
182182
return nil, err
183183
}
184184
return pluginPrivileges, nil
185185
}
186186

187-
// RemovePluginOptions This is a TBD Comments.
187+
// InspectPlugins .This is a TBD Comments.
188+
//
189+
// See https://goo.gl/kaOHGw for more details.
190+
func (c *Client) InspectPlugins(name string) (*PluginDetail, error) {
191+
resp, err := c.do("GET", "/plugins/"+name+"/json", doOptions{})
192+
if err != nil {
193+
return nil, err
194+
}
195+
defer resp.Body.Close()
196+
if err != nil {
197+
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
198+
return nil, &NoSuchPlugin{ID: name}
199+
}
200+
return nil, err
201+
}
202+
resp.Body.Close()
203+
var pluginDetail PluginDetail
204+
if err := json.NewDecoder(resp.Body).Decode(&pluginDetail); err != nil {
205+
return nil, err
206+
}
207+
return &pluginDetail, nil
208+
}
209+
210+
// RemovePluginOptions .This is a TBD Comments.
188211
//
189212
// See https://goo.gl/kaOHGw for more details.
190213
type RemovePluginOptions struct {
@@ -197,7 +220,7 @@ type RemovePluginOptions struct {
197220
Context context.Context
198221
}
199222

200-
// RemovePlugin This is a TBD Comments.
223+
// RemovePlugin .This is a TBD Comments.
201224
//
202225
// See https://goo.gl/kaOHGw for more details.
203226
func (c *Client) RemovePlugin(opts RemovePluginOptions) (*PluginDetail, error) {
@@ -221,7 +244,7 @@ func (c *Client) RemovePlugin(opts RemovePluginOptions) (*PluginDetail, error) {
221244
return &pluginDetail, nil
222245
}
223246

224-
// EnablePluginOptions This is a TBD Comments.
247+
// EnablePluginOptions .This is a TBD Comments.
225248
//
226249
// See https://goo.gl/kaOHGw for more details.
227250
type EnablePluginOptions struct {
@@ -232,7 +255,7 @@ type EnablePluginOptions struct {
232255
Context context.Context
233256
}
234257

235-
// EnablePlugin This is a TBD Comments.
258+
// EnablePlugin .This is a TBD Comments.
236259
//
237260
// See https://goo.gl/kaOHGw for more details.
238261
func (c *Client) EnablePlugin(opts EnablePluginOptions) error {
@@ -246,7 +269,7 @@ func (c *Client) EnablePlugin(opts EnablePluginOptions) error {
246269
return nil
247270
}
248271

249-
// DisablePluginOptions This is a TBD Comments.
272+
// DisablePluginOptions .This is a TBD Comments.
250273
//
251274
// See https://goo.gl/kaOHGw for more details.
252275
type DisablePluginOptions struct {
@@ -256,7 +279,7 @@ type DisablePluginOptions struct {
256279
Context context.Context
257280
}
258281

259-
// DisablePlugin This is a TBD Comments.
282+
// DisablePlugin .This is a TBD Comments.
260283
//
261284
// See https://goo.gl/kaOHGw for more details.
262285
func (c *Client) DisablePlugin(opts DisablePluginOptions) error {
@@ -270,7 +293,7 @@ func (c *Client) DisablePlugin(opts DisablePluginOptions) error {
270293
return nil
271294
}
272295

273-
// CreatePluginOptions This is a TBD Comments.
296+
// CreatePluginOptions .This is a TBD Comments.
274297
//
275298
// See https://goo.gl/kaOHGw for more details.
276299
type CreatePluginOptions struct {
@@ -282,7 +305,7 @@ type CreatePluginOptions struct {
282305
Context context.Context
283306
}
284307

285-
// CreatePlugin This is a TBD Comments.
308+
// CreatePlugin .This is a TBD Comments.
286309
//
287310
// See https://goo.gl/kaOHGw for more details.
288311
func (c *Client) CreatePlugin(opts CreatePluginOptions) (string, error) {
@@ -301,7 +324,7 @@ func (c *Client) CreatePlugin(opts CreatePluginOptions) (string, error) {
301324
return string(containerNameBytes), nil
302325
}
303326

304-
// PushPluginOptions This is a TBD Comments.
327+
// PushPluginOptions .This is a TBD Comments.
305328
//
306329
// See https://goo.gl/kaOHGw for more details.
307330
type PushPluginOptions struct {
@@ -311,7 +334,7 @@ type PushPluginOptions struct {
311334
Context context.Context
312335
}
313336

314-
// PushPlugin This is a TBD Comments.
337+
// PushPlugin .This is a TBD Comments.
315338
//
316339
// See https://goo.gl/kaOHGw for more details.
317340
func (c *Client) PushPlugin(opts PushPluginOptions) error {
@@ -324,7 +347,7 @@ func (c *Client) PushPlugin(opts PushPluginOptions) error {
324347
return nil
325348
}
326349

327-
// ConfigurePluginOptions This is a TBD Comments.
350+
// ConfigurePluginOptions .This is a TBD Comments.
328351
//
329352
// See https://goo.gl/kaOHGw for more details.
330353
type ConfigurePluginOptions struct {
@@ -335,7 +358,7 @@ type ConfigurePluginOptions struct {
335358
Context context.Context
336359
}
337360

338-
// ConfigurePlugin This is a TBD Comments.
361+
// ConfigurePlugin .This is a TBD Comments.
339362
//
340363
// See https://goo.gl/kaOHGw for more details.
341364
func (c *Client) ConfigurePlugin(opts ConfigurePluginOptions) error {

0 commit comments

Comments
 (0)