зеркало из https://github.com/docker/engine-api.git
Merge pull request #376 from vieux/plugin_inspect
add -f to plugin inspect
This commit is contained in:
Коммит
b66d7d91db
|
@ -30,7 +30,7 @@ type PluginAPIClient interface {
|
||||||
PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) error
|
PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) error
|
||||||
PluginPush(ctx context.Context, name string, registryAuth string) error
|
PluginPush(ctx context.Context, name string, registryAuth string) error
|
||||||
PluginSet(ctx context.Context, name string, args []string) error
|
PluginSet(ctx context.Context, name string, args []string) error
|
||||||
PluginInspect(ctx context.Context, name string) (*types.Plugin, error)
|
PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that Client always implements APIClient.
|
// Ensure that Client always implements APIClient.
|
||||||
|
|
|
@ -3,20 +3,28 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PluginInspect inspects an existing plugin
|
// PluginInspect inspects an existing plugin
|
||||||
func (cli *Client) PluginInspect(ctx context.Context, name string) (*types.Plugin, error) {
|
func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) {
|
||||||
var p types.Plugin
|
|
||||||
resp, err := cli.get(ctx, "/plugins/"+name, nil, nil)
|
resp, err := cli.get(ctx, "/plugins/"+name, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
err = json.NewDecoder(resp.body).Decode(&p)
|
|
||||||
ensureReaderClosed(resp)
|
defer ensureReaderClosed(resp)
|
||||||
return &p, err
|
body, err := ioutil.ReadAll(resp.body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
var p types.Plugin
|
||||||
|
rdr := bytes.NewReader(body)
|
||||||
|
err = json.NewDecoder(rdr).Decode(&p)
|
||||||
|
return &p, body, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestPluginInspectError(t *testing.T) {
|
||||||
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
|
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.PluginInspect(context.Background(), "nothing")
|
_, _, err := client.PluginInspectWithRaw(context.Background(), "nothing")
|
||||||
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
||||||
t.Fatalf("expected a Server Error, got %v", err)
|
t.Fatalf("expected a Server Error, got %v", err)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func TestPluginInspect(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginInspect, err := client.PluginInspect(context.Background(), "plugin_name")
|
pluginInspect, _, err := client.PluginInspectWithRaw(context.Background(), "plugin_name")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче