mirror of
https://github.com/docker/cli.git
synced 2026-01-13 18:22:35 +03:00
vendor: github.com/docker/docker 2ed904cad7055847796433cc56ef1d1de0da868c
- replace deprecated types
- also fixing some minor nits
full diff: 8941dcfcc5...2ed904cad7
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -142,7 +142,7 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error {
|
||||
return getExitStatus(errC, resultC)
|
||||
}
|
||||
|
||||
func getExitStatus(errC <-chan error, resultC <-chan container.ContainerWaitOKBody) error {
|
||||
func getExitStatus(errC <-chan error, resultC <-chan container.WaitResponse) error {
|
||||
select {
|
||||
case result := <-resultC:
|
||||
if result.Error != nil {
|
||||
|
||||
@@ -81,16 +81,16 @@ func TestGetExitStatus(t *testing.T) {
|
||||
var (
|
||||
expectedErr = fmt.Errorf("unexpected error")
|
||||
errC = make(chan error, 1)
|
||||
resultC = make(chan container.ContainerWaitOKBody, 1)
|
||||
resultC = make(chan container.WaitResponse, 1)
|
||||
)
|
||||
|
||||
testcases := []struct {
|
||||
result *container.ContainerWaitOKBody
|
||||
result *container.WaitResponse
|
||||
err error
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
result: &container.ContainerWaitOKBody{
|
||||
result: &container.WaitResponse{
|
||||
StatusCode: 0,
|
||||
},
|
||||
},
|
||||
@@ -99,13 +99,13 @@ func TestGetExitStatus(t *testing.T) {
|
||||
expectedError: expectedErr,
|
||||
},
|
||||
{
|
||||
result: &container.ContainerWaitOKBody{
|
||||
Error: &container.ContainerWaitOKBodyError{Message: expectedErr.Error()},
|
||||
result: &container.WaitResponse{
|
||||
Error: &container.WaitExitError{Message: expectedErr.Error()},
|
||||
},
|
||||
expectedError: expectedErr,
|
||||
},
|
||||
{
|
||||
result: &container.ContainerWaitOKBody{
|
||||
result: &container.WaitResponse{
|
||||
StatusCode: 15,
|
||||
},
|
||||
expectedError: cli.StatusError{StatusCode: 15},
|
||||
|
||||
@@ -20,14 +20,14 @@ type fakeClient struct {
|
||||
hostConfig *container.HostConfig,
|
||||
networkingConfig *network.NetworkingConfig,
|
||||
platform *specs.Platform,
|
||||
containerName string) (container.ContainerCreateCreatedBody, error)
|
||||
containerName string) (container.CreateResponse, error)
|
||||
containerStartFunc func(container string, options types.ContainerStartOptions) error
|
||||
imageCreateFunc func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
|
||||
infoFunc func() (types.Info, error)
|
||||
containerStatPathFunc func(container, path string) (types.ContainerPathStat, error)
|
||||
containerCopyFromFunc func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
|
||||
logFunc func(string, types.ContainerLogsOptions) (io.ReadCloser, error)
|
||||
waitFunc func(string) (<-chan container.ContainerWaitOKBody, <-chan error)
|
||||
waitFunc func(string) (<-chan container.WaitResponse, <-chan error)
|
||||
containerListFunc func(types.ContainerListOptions) ([]types.Container, error)
|
||||
containerExportFunc func(string) (io.ReadCloser, error)
|
||||
containerExecResizeFunc func(id string, options types.ResizeOptions) error
|
||||
@@ -75,11 +75,11 @@ func (f *fakeClient) ContainerCreate(
|
||||
networkingConfig *network.NetworkingConfig,
|
||||
platform *specs.Platform,
|
||||
containerName string,
|
||||
) (container.ContainerCreateCreatedBody, error) {
|
||||
) (container.CreateResponse, error) {
|
||||
if f.createContainerFunc != nil {
|
||||
return f.createContainerFunc(config, hostConfig, networkingConfig, platform, containerName)
|
||||
}
|
||||
return container.ContainerCreateCreatedBody{}, nil
|
||||
return container.CreateResponse{}, nil
|
||||
}
|
||||
|
||||
func (f *fakeClient) ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error {
|
||||
@@ -128,7 +128,7 @@ func (f *fakeClient) ClientVersion() string {
|
||||
return f.Version
|
||||
}
|
||||
|
||||
func (f *fakeClient) ContainerWait(_ context.Context, container string, _ container.WaitCondition) (<-chan container.ContainerWaitOKBody, <-chan error) {
|
||||
func (f *fakeClient) ContainerWait(_ context.Context, container string, _ container.WaitCondition) (<-chan container.WaitResponse, <-chan error) {
|
||||
if f.waitFunc != nil {
|
||||
return f.waitFunc(container)
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ func newCIDFile(path string) (*cidFile, error) {
|
||||
}
|
||||
|
||||
// nolint: gocyclo
|
||||
func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig *containerConfig, opts *createOptions) (*container.ContainerCreateCreatedBody, error) {
|
||||
func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig *containerConfig, opts *createOptions) (*container.CreateResponse, error) {
|
||||
config := containerConfig.Config
|
||||
hostConfig := containerConfig.HostConfig
|
||||
networkingConfig := containerConfig.NetworkingConfig
|
||||
|
||||
@@ -88,18 +88,18 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
|
||||
cases := []struct {
|
||||
PullPolicy string
|
||||
ExpectedPulls int
|
||||
ExpectedBody container.ContainerCreateCreatedBody
|
||||
ExpectedBody container.CreateResponse
|
||||
ExpectedErrMsg string
|
||||
ResponseCounter int
|
||||
}{
|
||||
{
|
||||
PullPolicy: PullImageMissing,
|
||||
ExpectedPulls: 1,
|
||||
ExpectedBody: container.ContainerCreateCreatedBody{ID: containerID},
|
||||
ExpectedBody: container.CreateResponse{ID: containerID},
|
||||
}, {
|
||||
PullPolicy: PullImageAlways,
|
||||
ExpectedPulls: 1,
|
||||
ExpectedBody: container.ContainerCreateCreatedBody{ID: containerID},
|
||||
ExpectedBody: container.CreateResponse{ID: containerID},
|
||||
ResponseCounter: 1, // This lets us return a container on the first pull
|
||||
}, {
|
||||
PullPolicy: PullImageNever,
|
||||
@@ -118,13 +118,13 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
|
||||
networkingConfig *network.NetworkingConfig,
|
||||
platform *specs.Platform,
|
||||
containerName string,
|
||||
) (container.ContainerCreateCreatedBody, error) {
|
||||
) (container.CreateResponse, error) {
|
||||
defer func() { c.ResponseCounter++ }()
|
||||
switch c.ResponseCounter {
|
||||
case 0:
|
||||
return container.ContainerCreateCreatedBody{}, fakeNotFound{}
|
||||
return container.CreateResponse{}, fakeNotFound{}
|
||||
default:
|
||||
return container.ContainerCreateCreatedBody{ID: containerID}, nil
|
||||
return container.CreateResponse{ID: containerID}, nil
|
||||
}
|
||||
},
|
||||
imageCreateFunc: func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
||||
@@ -187,8 +187,8 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
|
||||
networkingConfig *network.NetworkingConfig,
|
||||
platform *specs.Platform,
|
||||
containerName string,
|
||||
) (container.ContainerCreateCreatedBody, error) {
|
||||
return container.ContainerCreateCreatedBody{}, fmt.Errorf("shouldn't try to pull image")
|
||||
) (container.CreateResponse, error) {
|
||||
return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image")
|
||||
},
|
||||
}, test.EnableContentTrust)
|
||||
cli.SetNotaryClient(tc.notaryFunc)
|
||||
@@ -248,8 +248,8 @@ func TestNewCreateCommandWithWarnings(t *testing.T) {
|
||||
networkingConfig *network.NetworkingConfig,
|
||||
platform *specs.Platform,
|
||||
containerName string,
|
||||
) (container.ContainerCreateCreatedBody, error) {
|
||||
return container.ContainerCreateCreatedBody{}, nil
|
||||
) (container.CreateResponse, error) {
|
||||
return container.CreateResponse{}, nil
|
||||
},
|
||||
})
|
||||
cmd := NewCreateCommand(cli)
|
||||
@@ -287,10 +287,10 @@ func TestCreateContainerWithProxyConfig(t *testing.T) {
|
||||
networkingConfig *network.NetworkingConfig,
|
||||
platform *specs.Platform,
|
||||
containerName string,
|
||||
) (container.ContainerCreateCreatedBody, error) {
|
||||
) (container.CreateResponse, error) {
|
||||
sort.Strings(config.Env)
|
||||
assert.DeepEqual(t, config.Env, expected)
|
||||
return container.ContainerCreateCreatedBody{}, nil
|
||||
return container.CreateResponse{}, nil
|
||||
},
|
||||
})
|
||||
cli.SetConfigFile(&configfile.ConfigFile{
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -42,18 +42,19 @@ func NewRestartCommand(dockerCli command.Cli) *cobra.Command {
|
||||
func runRestart(dockerCli command.Cli, opts *restartOptions) error {
|
||||
ctx := context.Background()
|
||||
var errs []string
|
||||
var timeout *time.Duration
|
||||
var timeout *int
|
||||
if opts.nSecondsChanged {
|
||||
timeoutValue := time.Duration(opts.nSeconds) * time.Second
|
||||
timeout = &timeoutValue
|
||||
timeout = &opts.nSeconds
|
||||
}
|
||||
|
||||
for _, name := range opts.containers {
|
||||
if err := dockerCli.Client().ContainerRestart(ctx, name, timeout); err != nil {
|
||||
err := dockerCli.Client().ContainerRestart(ctx, name, container.StopOptions{
|
||||
Timeout: timeout,
|
||||
})
|
||||
if err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
continue
|
||||
}
|
||||
fmt.Fprintln(dockerCli.Out(), name)
|
||||
_, _ = fmt.Fprintln(dockerCli.Out(), name)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errors.New(strings.Join(errs, "\n"))
|
||||
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
|
||||
func TestRunLabel(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
createContainerFunc: func(_ *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ *specs.Platform, _ string) (container.ContainerCreateCreatedBody, error) {
|
||||
return container.ContainerCreateCreatedBody{
|
||||
createContainerFunc: func(_ *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ *specs.Platform, _ string) (container.CreateResponse, error) {
|
||||
return container.CreateResponse{
|
||||
ID: "id",
|
||||
}, nil
|
||||
},
|
||||
@@ -61,8 +61,8 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) {
|
||||
networkingConfig *network.NetworkingConfig,
|
||||
platform *specs.Platform,
|
||||
containerName string,
|
||||
) (container.ContainerCreateCreatedBody, error) {
|
||||
return container.ContainerCreateCreatedBody{}, fmt.Errorf("shouldn't try to pull image")
|
||||
) (container.CreateResponse, error) {
|
||||
return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image")
|
||||
},
|
||||
}, test.EnableContentTrust)
|
||||
cli.SetNotaryClient(tc.notaryFunc)
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -40,25 +40,23 @@ func NewStopCommand(dockerCli command.Cli) *cobra.Command {
|
||||
}
|
||||
|
||||
func runStop(dockerCli command.Cli, opts *stopOptions) error {
|
||||
ctx := context.Background()
|
||||
|
||||
var timeout *time.Duration
|
||||
var timeout *int
|
||||
if opts.timeChanged {
|
||||
timeoutValue := time.Duration(opts.time) * time.Second
|
||||
timeout = &timeoutValue
|
||||
timeout = &opts.time
|
||||
}
|
||||
|
||||
var errs []string
|
||||
|
||||
errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, id string) error {
|
||||
return dockerCli.Client().ContainerStop(ctx, id, timeout)
|
||||
errChan := parallelOperation(context.Background(), opts.containers, func(ctx context.Context, id string) error {
|
||||
return dockerCli.Client().ContainerStop(ctx, id, container.StopOptions{
|
||||
Timeout: timeout,
|
||||
})
|
||||
})
|
||||
for _, container := range opts.containers {
|
||||
var errs []string
|
||||
for _, ctr := range opts.containers {
|
||||
if err := <-errChan; err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
continue
|
||||
}
|
||||
fmt.Fprintln(dockerCli.Out(), container)
|
||||
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errors.New(strings.Join(errs, "\n"))
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
|
||||
func waitFn(cid string) (<-chan container.ContainerWaitOKBody, <-chan error) {
|
||||
resC := make(chan container.ContainerWaitOKBody)
|
||||
func waitFn(cid string) (<-chan container.WaitResponse, <-chan error) {
|
||||
resC := make(chan container.WaitResponse)
|
||||
errC := make(chan error, 1)
|
||||
var res container.ContainerWaitOKBody
|
||||
var res container.WaitResponse
|
||||
|
||||
go func() {
|
||||
switch {
|
||||
@@ -24,10 +24,10 @@ func waitFn(cid string) (<-chan container.ContainerWaitOKBody, <-chan error) {
|
||||
res.StatusCode = 42
|
||||
resC <- res
|
||||
case strings.Contains(cid, "non-existent"):
|
||||
err := errors.Errorf("No such container: %v", cid)
|
||||
err := errors.Errorf("no such container: %v", cid)
|
||||
errC <- err
|
||||
case strings.Contains(cid, "wait-error"):
|
||||
res.Error = &container.ContainerWaitOKBodyError{Message: "removal failed"}
|
||||
res.Error = &container.WaitExitError{Message: "removal failed"}
|
||||
resC <- res
|
||||
default:
|
||||
// normal exit
|
||||
|
||||
@@ -3,11 +3,13 @@ package formatter
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
units "github.com/docker/go-units"
|
||||
)
|
||||
|
||||
@@ -34,7 +36,7 @@ type DiskUsageContext struct {
|
||||
LayersSize int64
|
||||
Images []*types.ImageSummary
|
||||
Containers []*types.Container
|
||||
Volumes []*types.Volume
|
||||
Volumes []*volume.Volume
|
||||
BuildCache []*types.BuildCache
|
||||
BuilderSize int64
|
||||
}
|
||||
@@ -271,7 +273,7 @@ func (c *diskUsageImagesContext) Type() string {
|
||||
}
|
||||
|
||||
func (c *diskUsageImagesContext) TotalCount() string {
|
||||
return fmt.Sprintf("%d", len(c.images))
|
||||
return strconv.Itoa(len(c.images))
|
||||
}
|
||||
|
||||
func (c *diskUsageImagesContext) Active() string {
|
||||
@@ -282,7 +284,7 @@ func (c *diskUsageImagesContext) Active() string {
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d", used)
|
||||
return strconv.Itoa(used)
|
||||
}
|
||||
|
||||
func (c *diskUsageImagesContext) Size() string {
|
||||
@@ -323,7 +325,7 @@ func (c *diskUsageContainersContext) Type() string {
|
||||
}
|
||||
|
||||
func (c *diskUsageContainersContext) TotalCount() string {
|
||||
return fmt.Sprintf("%d", len(c.containers))
|
||||
return strconv.Itoa(len(c.containers))
|
||||
}
|
||||
|
||||
func (c *diskUsageContainersContext) isActive(container types.Container) bool {
|
||||
@@ -340,7 +342,7 @@ func (c *diskUsageContainersContext) Active() string {
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d", used)
|
||||
return strconv.Itoa(used)
|
||||
}
|
||||
|
||||
func (c *diskUsageContainersContext) Size() string {
|
||||
@@ -373,7 +375,7 @@ func (c *diskUsageContainersContext) Reclaimable() string {
|
||||
|
||||
type diskUsageVolumesContext struct {
|
||||
HeaderContext
|
||||
volumes []*types.Volume
|
||||
volumes []*volume.Volume
|
||||
}
|
||||
|
||||
func (c *diskUsageVolumesContext) MarshalJSON() ([]byte, error) {
|
||||
@@ -385,7 +387,7 @@ func (c *diskUsageVolumesContext) Type() string {
|
||||
}
|
||||
|
||||
func (c *diskUsageVolumesContext) TotalCount() string {
|
||||
return fmt.Sprintf("%d", len(c.volumes))
|
||||
return strconv.Itoa(len(c.volumes))
|
||||
}
|
||||
|
||||
func (c *diskUsageVolumesContext) Active() string {
|
||||
@@ -397,7 +399,7 @@ func (c *diskUsageVolumesContext) Active() string {
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d", used)
|
||||
return strconv.Itoa(used)
|
||||
}
|
||||
|
||||
func (c *diskUsageVolumesContext) Size() string {
|
||||
@@ -447,7 +449,7 @@ func (c *diskUsageBuilderContext) Type() string {
|
||||
}
|
||||
|
||||
func (c *diskUsageBuilderContext) TotalCount() string {
|
||||
return fmt.Sprintf("%d", len(c.buildCache))
|
||||
return strconv.Itoa(len(c.buildCache))
|
||||
}
|
||||
|
||||
func (c *diskUsageBuilderContext) Active() string {
|
||||
@@ -457,7 +459,7 @@ func (c *diskUsageBuilderContext) Active() string {
|
||||
numActive++
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%d", numActive)
|
||||
return strconv.Itoa(numActive)
|
||||
}
|
||||
|
||||
func (c *diskUsageBuilderContext) Size() string {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package formatter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
units "github.com/docker/go-units"
|
||||
)
|
||||
|
||||
@@ -36,10 +36,10 @@ func NewVolumeFormat(source string, quiet bool) Format {
|
||||
}
|
||||
|
||||
// VolumeWrite writes formatted volumes using the Context
|
||||
func VolumeWrite(ctx Context, volumes []*types.Volume) error {
|
||||
func VolumeWrite(ctx Context, volumes []*volume.Volume) error {
|
||||
render := func(format func(subContext SubContext) error) error {
|
||||
for _, volume := range volumes {
|
||||
if err := format(&volumeContext{v: *volume}); err != nil {
|
||||
for _, vol := range volumes {
|
||||
if err := format(&volumeContext{v: *vol}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func VolumeWrite(ctx Context, volumes []*types.Volume) error {
|
||||
|
||||
type volumeContext struct {
|
||||
HeaderContext
|
||||
v types.Volume
|
||||
v volume.Volume
|
||||
}
|
||||
|
||||
func newVolumeContext() *volumeContext {
|
||||
@@ -94,7 +94,7 @@ func (c *volumeContext) Labels() string {
|
||||
|
||||
var joinLabels []string
|
||||
for k, v := range c.v.Labels {
|
||||
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
|
||||
joinLabels = append(joinLabels, k+"="+v)
|
||||
}
|
||||
return strings.Join(joinLabels, ",")
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func (c *volumeContext) Links() string {
|
||||
if c.v.UsageData == nil {
|
||||
return "N/A"
|
||||
}
|
||||
return fmt.Sprintf("%d", c.v.UsageData.RefCount)
|
||||
return strconv.FormatInt(c.v.UsageData.RefCount, 10)
|
||||
}
|
||||
|
||||
func (c *volumeContext) Size() string {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@@ -24,22 +24,22 @@ func TestVolumeContext(t *testing.T) {
|
||||
call func() string
|
||||
}{
|
||||
{volumeContext{
|
||||
v: types.Volume{Name: volumeName},
|
||||
v: volume.Volume{Name: volumeName},
|
||||
}, volumeName, ctx.Name},
|
||||
{volumeContext{
|
||||
v: types.Volume{Driver: "driver_name"},
|
||||
v: volume.Volume{Driver: "driver_name"},
|
||||
}, "driver_name", ctx.Driver},
|
||||
{volumeContext{
|
||||
v: types.Volume{Scope: "local"},
|
||||
v: volume.Volume{Scope: "local"},
|
||||
}, "local", ctx.Scope},
|
||||
{volumeContext{
|
||||
v: types.Volume{Mountpoint: "mountpoint"},
|
||||
v: volume.Volume{Mountpoint: "mountpoint"},
|
||||
}, "mountpoint", ctx.Mountpoint},
|
||||
{volumeContext{
|
||||
v: types.Volume{},
|
||||
v: volume.Volume{},
|
||||
}, "", ctx.Labels},
|
||||
{volumeContext{
|
||||
v: types.Volume{Labels: map[string]string{"label1": "value1", "label2": "value2"}},
|
||||
v: volume.Volume{Labels: map[string]string{"label1": "value1", "label2": "value2"}},
|
||||
}, "label1=value1,label2=value2", ctx.Labels},
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ foobar_bar
|
||||
},
|
||||
}
|
||||
|
||||
volumes := []*types.Volume{
|
||||
volumes := []*volume.Volume{
|
||||
{Name: "foobar_baz", Driver: "foo"},
|
||||
{Name: "foobar_bar", Driver: "bar"},
|
||||
}
|
||||
@@ -143,7 +143,7 @@ foobar_bar
|
||||
}
|
||||
|
||||
func TestVolumeContextWriteJSON(t *testing.T) {
|
||||
volumes := []*types.Volume{
|
||||
volumes := []*volume.Volume{
|
||||
{Driver: "foo", Name: "foobar_baz"},
|
||||
{Driver: "bar", Name: "foobar_bar"},
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func TestVolumeContextWriteJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVolumeContextWriteJSONField(t *testing.T) {
|
||||
volumes := []*types.Volume{
|
||||
volumes := []*volume.Volume{
|
||||
{Driver: "foo", Name: "foobar_baz"},
|
||||
{Driver: "bar", Name: "foobar_bar"},
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ import (
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/builder/remotecontext/urlutil"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
"github.com/docker/docker/pkg/urlutil"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -5,48 +5,48 @@ import (
|
||||
|
||||
"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/client"
|
||||
)
|
||||
|
||||
type fakeClient struct {
|
||||
client.Client
|
||||
volumeCreateFunc func(volumetypes.VolumeCreateBody) (types.Volume, error)
|
||||
volumeInspectFunc func(volumeID string) (types.Volume, error)
|
||||
volumeListFunc func(filter filters.Args) (volumetypes.VolumeListOKBody, error)
|
||||
volumeCreateFunc func(volume.CreateOptions) (volume.Volume, error)
|
||||
volumeInspectFunc func(volumeID string) (volume.Volume, error)
|
||||
volumeListFunc func(filter filters.Args) (volume.ListResponse, error)
|
||||
volumeRemoveFunc func(volumeID string, force bool) error
|
||||
volumePruneFunc func(filter filters.Args) (types.VolumesPruneReport, error)
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumeCreate(ctx context.Context, options volumetypes.VolumeCreateBody) (types.Volume, error) {
|
||||
func (c *fakeClient) VolumeCreate(_ context.Context, options volume.CreateOptions) (volume.Volume, error) {
|
||||
if c.volumeCreateFunc != nil {
|
||||
return c.volumeCreateFunc(options)
|
||||
}
|
||||
return types.Volume{}, nil
|
||||
return volume.Volume{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) {
|
||||
func (c *fakeClient) VolumeInspect(_ context.Context, volumeID string) (volume.Volume, error) {
|
||||
if c.volumeInspectFunc != nil {
|
||||
return c.volumeInspectFunc(volumeID)
|
||||
}
|
||||
return types.Volume{}, nil
|
||||
return volume.Volume{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumeListOKBody, error) {
|
||||
func (c *fakeClient) VolumeList(_ context.Context, filter filters.Args) (volume.ListResponse, error) {
|
||||
if c.volumeListFunc != nil {
|
||||
return c.volumeListFunc(filter)
|
||||
}
|
||||
return volumetypes.VolumeListOKBody{}, nil
|
||||
return volume.ListResponse{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumesPrune(ctx context.Context, filter filters.Args) (types.VolumesPruneReport, error) {
|
||||
func (c *fakeClient) VolumesPrune(_ context.Context, filter filters.Args) (types.VolumesPruneReport, error) {
|
||||
if c.volumePruneFunc != nil {
|
||||
return c.volumePruneFunc(filter)
|
||||
}
|
||||
return types.VolumesPruneReport{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) VolumeRemove(ctx context.Context, volumeID string, force bool) error {
|
||||
func (c *fakeClient) VolumeRemove(_ context.Context, volumeID string, force bool) error {
|
||||
if c.volumeRemoveFunc != nil {
|
||||
return c.volumeRemoveFunc(volumeID, force)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/opts"
|
||||
volumetypes "github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -50,20 +50,16 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
}
|
||||
|
||||
func runCreate(dockerCli command.Cli, options createOptions) error {
|
||||
client := dockerCli.Client()
|
||||
|
||||
volReq := volumetypes.VolumeCreateBody{
|
||||
vol, err := dockerCli.Client().VolumeCreate(context.Background(), volume.CreateOptions{
|
||||
Driver: options.driver,
|
||||
DriverOpts: options.driverOpts.GetAll(),
|
||||
Name: options.name,
|
||||
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
|
||||
}
|
||||
|
||||
vol, err := client.VolumeCreate(context.Background(), volReq)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(dockerCli.Out(), "%s\n", vol.Name)
|
||||
_, _ = fmt.Fprintln(dockerCli.Out(), vol.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types"
|
||||
volumetypes "github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@@ -18,7 +17,7 @@ func TestVolumeCreateErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
args []string
|
||||
flags map[string]string
|
||||
volumeCreateFunc func(volumetypes.VolumeCreateBody) (types.Volume, error)
|
||||
volumeCreateFunc func(volume.CreateOptions) (volume.Volume, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
@@ -33,8 +32,8 @@ func TestVolumeCreateErrors(t *testing.T) {
|
||||
expectedError: "requires at most 1 argument",
|
||||
},
|
||||
{
|
||||
volumeCreateFunc: func(createBody volumetypes.VolumeCreateBody) (types.Volume, error) {
|
||||
return types.Volume{}, errors.Errorf("error creating volume")
|
||||
volumeCreateFunc: func(createBody volume.CreateOptions) (volume.Volume, error) {
|
||||
return volume.Volume{}, errors.Errorf("error creating volume")
|
||||
},
|
||||
expectedError: "error creating volume",
|
||||
},
|
||||
@@ -57,11 +56,11 @@ func TestVolumeCreateErrors(t *testing.T) {
|
||||
func TestVolumeCreateWithName(t *testing.T) {
|
||||
name := "foo"
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumeCreateFunc: func(body volumetypes.VolumeCreateBody) (types.Volume, error) {
|
||||
volumeCreateFunc: func(body volume.CreateOptions) (volume.Volume, error) {
|
||||
if body.Name != name {
|
||||
return types.Volume{}, errors.Errorf("expected name %q, got %q", name, body.Name)
|
||||
return volume.Volume{}, errors.Errorf("expected name %q, got %q", name, body.Name)
|
||||
}
|
||||
return types.Volume{
|
||||
return volume.Volume{
|
||||
Name: body.Name,
|
||||
}, nil
|
||||
},
|
||||
@@ -96,20 +95,20 @@ func TestVolumeCreateWithFlags(t *testing.T) {
|
||||
name := "banana"
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumeCreateFunc: func(body volumetypes.VolumeCreateBody) (types.Volume, error) {
|
||||
volumeCreateFunc: func(body volume.CreateOptions) (volume.Volume, error) {
|
||||
if body.Name != "" {
|
||||
return types.Volume{}, errors.Errorf("expected empty name, got %q", body.Name)
|
||||
return volume.Volume{}, errors.Errorf("expected empty name, got %q", body.Name)
|
||||
}
|
||||
if body.Driver != expectedDriver {
|
||||
return types.Volume{}, errors.Errorf("expected driver %q, got %q", expectedDriver, body.Driver)
|
||||
return volume.Volume{}, errors.Errorf("expected driver %q, got %q", expectedDriver, body.Driver)
|
||||
}
|
||||
if !reflect.DeepEqual(body.DriverOpts, expectedOpts) {
|
||||
return types.Volume{}, errors.Errorf("expected drivers opts %v, got %v", expectedOpts, body.DriverOpts)
|
||||
return volume.Volume{}, errors.Errorf("expected drivers opts %v, got %v", expectedOpts, body.DriverOpts)
|
||||
}
|
||||
if !reflect.DeepEqual(body.Labels, expectedLabels) {
|
||||
return types.Volume{}, errors.Errorf("expected labels %v, got %v", expectedLabels, body.Labels)
|
||||
return volume.Volume{}, errors.Errorf("expected labels %v, got %v", expectedLabels, body.Labels)
|
||||
}
|
||||
return types.Volume{
|
||||
return volume.Volume{
|
||||
Name: name,
|
||||
}, nil
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/golden"
|
||||
@@ -17,7 +17,7 @@ func TestVolumeInspectErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
args []string
|
||||
flags map[string]string
|
||||
volumeInspectFunc func(volumeID string) (types.Volume, error)
|
||||
volumeInspectFunc func(volumeID string) (volume.Volume, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
@@ -25,8 +25,8 @@ func TestVolumeInspectErrors(t *testing.T) {
|
||||
},
|
||||
{
|
||||
args: []string{"foo"},
|
||||
volumeInspectFunc: func(volumeID string) (types.Volume, error) {
|
||||
return types.Volume{}, errors.Errorf("error while inspecting the volume")
|
||||
volumeInspectFunc: func(volumeID string) (volume.Volume, error) {
|
||||
return volume.Volume{}, errors.Errorf("error while inspecting the volume")
|
||||
},
|
||||
expectedError: "error while inspecting the volume",
|
||||
},
|
||||
@@ -39,13 +39,13 @@ func TestVolumeInspectErrors(t *testing.T) {
|
||||
},
|
||||
{
|
||||
args: []string{"foo", "bar"},
|
||||
volumeInspectFunc: func(volumeID string) (types.Volume, error) {
|
||||
volumeInspectFunc: func(volumeID string) (volume.Volume, error) {
|
||||
if volumeID == "foo" {
|
||||
return types.Volume{
|
||||
return volume.Volume{
|
||||
Name: "foo",
|
||||
}, nil
|
||||
}
|
||||
return types.Volume{}, errors.Errorf("error while inspecting the volume")
|
||||
return volume.Volume{}, errors.Errorf("error while inspecting the volume")
|
||||
},
|
||||
expectedError: "error while inspecting the volume",
|
||||
},
|
||||
@@ -69,14 +69,14 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
volumeInspectFunc func(volumeID string) (types.Volume, error)
|
||||
volumeInspectFunc func(volumeID string) (volume.Volume, error)
|
||||
}{
|
||||
{
|
||||
name: "single-volume",
|
||||
args: []string{"foo"},
|
||||
volumeInspectFunc: func(volumeID string) (types.Volume, error) {
|
||||
volumeInspectFunc: func(volumeID string) (volume.Volume, error) {
|
||||
if volumeID != "foo" {
|
||||
return types.Volume{}, errors.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID)
|
||||
return volume.Volume{}, errors.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID)
|
||||
}
|
||||
return *Volume(), nil
|
||||
},
|
||||
@@ -84,7 +84,7 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
|
||||
{
|
||||
name: "multiple-volume-with-labels",
|
||||
args: []string{"foo", "bar"},
|
||||
volumeInspectFunc: func(volumeID string) (types.Volume, error) {
|
||||
volumeInspectFunc: func(volumeID string) (volume.Volume, error) {
|
||||
return *Volume(VolumeName(volumeID), VolumeLabels(map[string]string{
|
||||
"foo": "bar",
|
||||
})), nil
|
||||
@@ -103,7 +103,7 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVolumeInspectWithFormat(t *testing.T) {
|
||||
volumeInspectFunc := func(volumeID string) (types.Volume, error) {
|
||||
volumeInspectFunc := func(volumeID string) (volume.Volume, error) {
|
||||
return *Volume(VolumeLabels(map[string]string{
|
||||
"foo": "bar",
|
||||
})), nil
|
||||
@@ -112,7 +112,7 @@ func TestVolumeInspectWithFormat(t *testing.T) {
|
||||
name string
|
||||
format string
|
||||
args []string
|
||||
volumeInspectFunc func(volumeID string) (types.Volume, error)
|
||||
volumeInspectFunc func(volumeID string) (volume.Volume, error)
|
||||
}{
|
||||
{
|
||||
name: "simple-template",
|
||||
|
||||
@@ -7,9 +7,8 @@ import (
|
||||
"github.com/docker/cli/cli/config/configfile"
|
||||
"github.com/docker/cli/internal/test"
|
||||
. "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function
|
||||
"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/pkg/errors"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/golden"
|
||||
@@ -19,7 +18,7 @@ func TestVolumeListErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
args []string
|
||||
flags map[string]string
|
||||
volumeListFunc func(filter filters.Args) (volumetypes.VolumeListOKBody, error)
|
||||
volumeListFunc func(filter filters.Args) (volume.ListResponse, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
@@ -27,8 +26,8 @@ func TestVolumeListErrors(t *testing.T) {
|
||||
expectedError: "accepts no argument",
|
||||
},
|
||||
{
|
||||
volumeListFunc: func(filter filters.Args) (volumetypes.VolumeListOKBody, error) {
|
||||
return volumetypes.VolumeListOKBody{}, errors.Errorf("error listing volumes")
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{}, errors.Errorf("error listing volumes")
|
||||
},
|
||||
expectedError: "error listing volumes",
|
||||
},
|
||||
@@ -50,9 +49,9 @@ func TestVolumeListErrors(t *testing.T) {
|
||||
|
||||
func TestVolumeListWithoutFormat(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumeListFunc: func(filter filters.Args) (volumetypes.VolumeListOKBody, error) {
|
||||
return volumetypes.VolumeListOKBody{
|
||||
Volumes: []*types.Volume{
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(),
|
||||
Volume(VolumeName("foo"), VolumeDriver("bar")),
|
||||
Volume(VolumeName("baz"), VolumeLabels(map[string]string{
|
||||
@@ -69,9 +68,9 @@ func TestVolumeListWithoutFormat(t *testing.T) {
|
||||
|
||||
func TestVolumeListWithConfigFormat(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumeListFunc: func(filter filters.Args) (volumetypes.VolumeListOKBody, error) {
|
||||
return volumetypes.VolumeListOKBody{
|
||||
Volumes: []*types.Volume{
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(),
|
||||
Volume(VolumeName("foo"), VolumeDriver("bar")),
|
||||
Volume(VolumeName("baz"), VolumeLabels(map[string]string{
|
||||
@@ -91,9 +90,9 @@ func TestVolumeListWithConfigFormat(t *testing.T) {
|
||||
|
||||
func TestVolumeListWithFormat(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumeListFunc: func(filter filters.Args) (volumetypes.VolumeListOKBody, error) {
|
||||
return volumetypes.VolumeListOKBody{
|
||||
Volumes: []*types.Volume{
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(),
|
||||
Volume(VolumeName("foo"), VolumeDriver("bar")),
|
||||
Volume(VolumeName("baz"), VolumeLabels(map[string]string{
|
||||
@@ -111,9 +110,9 @@ func TestVolumeListWithFormat(t *testing.T) {
|
||||
|
||||
func TestVolumeListSortOrder(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
volumeListFunc: func(filter filters.Args) (volumetypes.VolumeListOKBody, error) {
|
||||
return volumetypes.VolumeListOKBody{
|
||||
Volumes: []*types.Volume{
|
||||
volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) {
|
||||
return volume.ListResponse{
|
||||
Volumes: []*volume.Volume{
|
||||
Volume(VolumeName("volume-2-foo")),
|
||||
Volume(VolumeName("volume-10-foo")),
|
||||
Volume(VolumeName("volume-1-foo")),
|
||||
|
||||
Reference in New Issue
Block a user