diff options
author | Sebastiaan van Stijn <github@gone.nl> | 2022-03-18 16:33:43 +0100 |
---|---|---|
committer | Sebastiaan van Stijn <github@gone.nl> | 2022-04-21 19:50:59 +0200 |
commit | 176f66df9ca5cdc9466661428f0a3ac33cd1ab1b (patch) | |
tree | 48fc4bbe7e15dffdaf540a1754aea570305eac0f /client | |
parent | 54386f0c8f61796ff64f09b0e45b43c0a367c142 (diff) |
api/types: replace uses of deprecated types.Volume with volume.Volume
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'client')
-rw-r--r-- | client/interface.go | 6 | ||||
-rw-r--r-- | client/volume_create.go | 13 | ||||
-rw-r--r-- | client/volume_create_test.go | 21 | ||||
-rw-r--r-- | client/volume_inspect.go | 22 | ||||
-rw-r--r-- | client/volume_inspect_test.go | 4 | ||||
-rw-r--r-- | client/volume_list_test.go | 7 |
6 files changed, 35 insertions, 38 deletions
diff --git a/client/interface.go b/client/interface.go index cd177475f9..1e177b43d9 100644 --- a/client/interface.go +++ b/client/interface.go @@ -173,9 +173,9 @@ type SystemAPIClient interface { // VolumeAPIClient defines API client methods for the volumes type VolumeAPIClient interface { - VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (types.Volume, error) - VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) - VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) + VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (volume.Volume, error) + VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) + VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) VolumeList(ctx context.Context, filter filters.Args) (volume.VolumeListOKBody, error) VolumeRemove(ctx context.Context, volumeID string, force bool) error VolumesPrune(ctx context.Context, pruneFilter filters.Args) (types.VolumesPruneReport, error) diff --git a/client/volume_create.go b/client/volume_create.go index 92761b3c63..49e9db1441 100644 --- a/client/volume_create.go +++ b/client/volume_create.go @@ -4,18 +4,17 @@ import ( "context" "encoding/json" - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" ) // VolumeCreate creates a volume in the docker host. -func (cli *Client) VolumeCreate(ctx context.Context, options volumetypes.VolumeCreateBody) (types.Volume, error) { - var volume types.Volume +func (cli *Client) VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (volume.Volume, error) { + var vol volume.Volume resp, err := cli.post(ctx, "/volumes/create", nil, options, nil) defer ensureReaderClosed(resp) if err != nil { - return volume, err + return vol, err } - err = json.NewDecoder(resp.body).Decode(&volume) - return volume, err + err = json.NewDecoder(resp.body).Decode(&vol) + return vol, err } diff --git a/client/volume_create_test.go b/client/volume_create_test.go index 9f8624a292..3eb52279cc 100644 --- a/client/volume_create_test.go +++ b/client/volume_create_test.go @@ -10,8 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" ) @@ -20,7 +19,7 @@ func TestVolumeCreateError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{}) + _, err := client.VolumeCreate(context.Background(), volume.VolumeCreateBody{}) if !errdefs.IsSystem(err) { t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err) } @@ -39,7 +38,7 @@ func TestVolumeCreate(t *testing.T) { return nil, fmt.Errorf("expected POST method, got %s", req.Method) } - content, err := json.Marshal(types.Volume{ + content, err := json.Marshal(volume.Volume{ Name: "volume", Driver: "local", Mountpoint: "mountpoint", @@ -54,7 +53,7 @@ func TestVolumeCreate(t *testing.T) { }), } - volume, err := client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{ + vol, err := client.VolumeCreate(context.Background(), volume.VolumeCreateBody{ Name: "myvolume", Driver: "mydriver", DriverOpts: map[string]string{ @@ -64,13 +63,13 @@ func TestVolumeCreate(t *testing.T) { if err != nil { t.Fatal(err) } - if volume.Name != "volume" { - t.Fatalf("expected volume.Name to be 'volume', got %s", volume.Name) + if vol.Name != "volume" { + t.Fatalf("expected volume.Name to be 'volume', got %s", vol.Name) } - if volume.Driver != "local" { - t.Fatalf("expected volume.Driver to be 'local', got %s", volume.Driver) + if vol.Driver != "local" { + t.Fatalf("expected volume.Driver to be 'local', got %s", vol.Driver) } - if volume.Mountpoint != "mountpoint" { - t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", volume.Mountpoint) + if vol.Mountpoint != "mountpoint" { + t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", vol.Mountpoint) } } diff --git a/client/volume_inspect.go b/client/volume_inspect.go index 070209b35e..b3ba4e6046 100644 --- a/client/volume_inspect.go +++ b/client/volume_inspect.go @@ -6,33 +6,33 @@ import ( "encoding/json" "io" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/volume" ) // VolumeInspect returns the information about a specific volume in the docker host. -func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) { - volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID) - return volume, err +func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, 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) (types.Volume, []byte, error) { +func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) { if volumeID == "" { - return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID} + return volume.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID} } - var volume types.Volume + var vol volume.Volume resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil) defer ensureReaderClosed(resp) if err != nil { - return volume, nil, err + return vol, nil, err } body, err := io.ReadAll(resp.body) if err != nil { - return volume, nil, err + return vol, nil, err } rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&volume) - return volume, body, err + err = json.NewDecoder(rdr).Decode(&vol) + return vol, body, err } diff --git a/client/volume_inspect_test.go b/client/volume_inspect_test.go index 1aa2a54448..70b82729b8 100644 --- a/client/volume_inspect_test.go +++ b/client/volume_inspect_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -51,7 +51,7 @@ func TestVolumeInspectWithEmptyID(t *testing.T) { func TestVolumeInspect(t *testing.T) { expectedURL := "/volumes/volume_id" - expected := types.Volume{ + expected := volume.Volume{ Name: "name", Driver: "driver", Mountpoint: "mountpoint", diff --git a/client/volume_list_test.go b/client/volume_list_test.go index d26bb51405..0d54f4a597 100644 --- a/client/volume_list_test.go +++ b/client/volume_list_test.go @@ -10,9 +10,8 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" ) @@ -70,8 +69,8 @@ func TestVolumeList(t *testing.T) { if actualFilters != listCase.expectedFilters { return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) } - content, err := json.Marshal(volumetypes.VolumeListOKBody{ - Volumes: []*types.Volume{ + content, err := json.Marshal(volume.VolumeListOKBody{ + Volumes: []*volume.Volume{ { Name: "volume", Driver: "local", |