mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: remove VolumeInspectWithRaw, merge with VolumeInspect
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -195,7 +195,6 @@ type SystemAPIClient interface {
|
||||
type VolumeAPIClient interface {
|
||||
VolumeCreate(ctx context.Context, options VolumeCreateOptions) (VolumeCreateResult, error)
|
||||
VolumeInspect(ctx context.Context, volumeID string) (VolumeInspectResult, error)
|
||||
VolumeInspectWithRaw(ctx context.Context, volumeID string) (VolumeInspectResult, []byte, error)
|
||||
VolumeList(ctx context.Context, options VolumeListOptions) (VolumeListResult, error)
|
||||
VolumeRemove(ctx context.Context, volumeID string, options VolumeRemoveOptions) error
|
||||
VolumesPrune(ctx context.Context, opts VolumePruneOptions) (VolumePruneResult, error)
|
||||
|
||||
@@ -1,45 +1,31 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/moby/moby/api/types/volume"
|
||||
)
|
||||
|
||||
// VolumeInspectResult holds the result from the [Client.VolumeInspect] method.
|
||||
type VolumeInspectResult struct {
|
||||
Raw []byte
|
||||
Volume volume.Volume
|
||||
}
|
||||
|
||||
// VolumeInspect returns the information about a specific volume in the docker host.
|
||||
func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (VolumeInspectResult, error) {
|
||||
vol, _, err := cli.VolumeInspectWithRaw(ctx, volumeID)
|
||||
return vol, err
|
||||
}
|
||||
|
||||
// VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation
|
||||
func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (VolumeInspectResult, []byte, error) {
|
||||
volumeID, err := trimID("volume", volumeID)
|
||||
if err != nil {
|
||||
return VolumeInspectResult{}, nil, err
|
||||
return VolumeInspectResult{}, err
|
||||
}
|
||||
|
||||
resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return VolumeInspectResult{}, nil, err
|
||||
return VolumeInspectResult{}, err
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return VolumeInspectResult{}, nil, err
|
||||
}
|
||||
|
||||
var vol volume.Volume
|
||||
rdr := bytes.NewReader(body)
|
||||
err = json.NewDecoder(rdr).Decode(&vol)
|
||||
return VolumeInspectResult{Volume: vol}, body, err
|
||||
var out VolumeInspectResult
|
||||
out.Raw, err = decodeWithRaw(resp, &out.Volume)
|
||||
return out, err
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ func TestVolumeInspectWithEmptyID(t *testing.T) {
|
||||
return nil, errors.New("should not make request")
|
||||
}))
|
||||
assert.NilError(t, err)
|
||||
_, _, err = client.VolumeInspectWithRaw(context.Background(), "")
|
||||
_, err = client.VolumeInspect(context.Background(), "")
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
|
||||
_, _, err = client.VolumeInspectWithRaw(context.Background(), " ")
|
||||
_, err = client.VolumeInspect(context.Background(), " ")
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user