mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: PluginInspectWithRaw: refactor and rename to PluginInspect
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -154,7 +154,7 @@ type PluginAPIClient interface {
|
||||
PluginUpgrade(ctx context.Context, name string, options PluginInstallOptions) (io.ReadCloser, error)
|
||||
PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error)
|
||||
PluginSet(ctx context.Context, name string, args []string) error
|
||||
PluginInspectWithRaw(ctx context.Context, name string) (*plugin.Plugin, []byte, error)
|
||||
PluginInspect(ctx context.Context, name string, options PluginInspectOptions) (PluginInspectResult, error)
|
||||
PluginCreate(ctx context.Context, createContext io.Reader, options PluginCreateOptions) error
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,35 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/moby/moby/api/types/plugin"
|
||||
)
|
||||
|
||||
// PluginInspectWithRaw inspects an existing plugin
|
||||
func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*plugin.Plugin, []byte, error) {
|
||||
// PluginInspectOptions holds parameters to inspect a plugin.
|
||||
type PluginInspectOptions struct {
|
||||
// Add future optional parameters here
|
||||
}
|
||||
|
||||
// PluginInspectResult holds the result from the [Client.PluginInspect] method.
|
||||
type PluginInspectResult struct {
|
||||
Raw []byte
|
||||
Plugin plugin.Plugin
|
||||
}
|
||||
|
||||
// PluginInspect inspects an existing plugin
|
||||
func (cli *Client) PluginInspect(ctx context.Context, name string, options PluginInspectOptions) (PluginInspectResult, error) {
|
||||
name, err := trimID("plugin", name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return PluginInspectResult{}, err
|
||||
}
|
||||
resp, err := cli.get(ctx, "/plugins/"+name+"/json", nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return PluginInspectResult{}, err
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
var p plugin.Plugin
|
||||
rdr := bytes.NewReader(body)
|
||||
err = json.NewDecoder(rdr).Decode(&p)
|
||||
return &p, body, err
|
||||
var out PluginInspectResult
|
||||
out.Raw, err = decodeWithRaw(resp, &out.Plugin)
|
||||
return out, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
@@ -19,7 +18,7 @@ func TestPluginInspectError(t *testing.T) {
|
||||
client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusInternalServerError, "Server error")))
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = client.PluginInspectWithRaw(context.Background(), "nothing")
|
||||
_, err = client.PluginInspect(t.Context(), "nothing", PluginInspectOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
}
|
||||
|
||||
@@ -28,11 +27,11 @@ func TestPluginInspectWithEmptyID(t *testing.T) {
|
||||
return nil, errors.New("should not make request")
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
_, _, err = client.PluginInspectWithRaw(context.Background(), "")
|
||||
_, err = client.PluginInspect(t.Context(), "", PluginInspectOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
|
||||
_, _, err = client.PluginInspectWithRaw(context.Background(), " ")
|
||||
_, err = client.PluginInspect(t.Context(), " ", PluginInspectOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
}
|
||||
@@ -56,7 +55,7 @@ func TestPluginInspect(t *testing.T) {
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
|
||||
pluginInspect, _, err := client.PluginInspectWithRaw(context.Background(), "plugin_name")
|
||||
resp, err := client.PluginInspect(t.Context(), "plugin_name", PluginInspectOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(pluginInspect.ID, "plugin_id"))
|
||||
assert.Check(t, is.Equal(resp.Plugin.ID, "plugin_id"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user