mirror of https://github.com/docker/cli.git
linting: fmt.Errorf can be replaced with errors.New (perfsprint)
internal/test/cli.go:175:14: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("no notary client available unless defined") ^ cli/command/cli.go:318:29: fmt.Errorf can be replaced with errors.New (perfsprint) return docker.Endpoint{}, fmt.Errorf("no context store initialized") ^ cli/command/container/attach.go:161:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf(result.Error.Message) ^ cli/command/container/opts.go:577:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("--health-start-period cannot be negative") ^ cli/command/container/opts.go:580:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("--health-start-interval cannot be negative") ^ cli/command/container/stats.go:221:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("filtering is not supported when specifying a list of containers") ^ cli/command/container/attach_test.go:82:17: fmt.Errorf can be replaced with errors.New (perfsprint) expectedErr = fmt.Errorf("unexpected error") ^ cli/command/container/create_test.go:234:40: fmt.Errorf can be replaced with errors.New (perfsprint) return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") ^ cli/command/container/list_test.go:150:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("error listing containers") ^ cli/command/container/rm_test.go:40:31: fmt.Errorf can be replaced with errors.New (perfsprint) return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container)) ^ cli/command/container/run_test.go:138:40: fmt.Errorf can be replaced with errors.New (perfsprint) return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") ^ cli/command/image/pull_test.go:115:49: fmt.Errorf can be replaced with errors.New (perfsprint) return io.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image") ^ cli/command/network/connect.go:88:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("invalid key/value pair format in driver options") ^ cli/command/plugin/create_test.go:96:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error creating plugin") ^ cli/command/plugin/disable_test.go:32:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error disabling plugin") ^ cli/command/plugin/enable_test.go:32:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("failed to enable plugin") ^ cli/command/plugin/inspect_test.go:55:22: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, nil, fmt.Errorf("error inspecting plugin") ^ cli/command/plugin/install_test.go:43:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("Error installing plugin") ^ cli/command/plugin/install_test.go:51:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("(image) when fetching") ^ cli/command/plugin/install_test.go:95:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("should not try to install plugin") ^ cli/command/plugin/list_test.go:35:41: fmt.Errorf can be replaced with errors.New (perfsprint) return types.PluginsListResponse{}, fmt.Errorf("error listing plugins") ^ cli/command/plugin/remove_test.go:27:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error removing plugin") ^ cli/command/registry/login_test.go:36:46: fmt.Errorf can be replaced with errors.New (perfsprint) return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password") ^ cli/command/registry/login_test.go:44:46: fmt.Errorf can be replaced with errors.New (perfsprint) return registrytypes.AuthenticateOKBody{}, fmt.Errorf(errUnknownUser) ^ cli/command/system/info.go:190:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("errors pretty printing info") ^ cli/command/system/prune.go:77:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`) ^ cli/command/system/version_test.go:19:28: fmt.Errorf can be replaced with errors.New (perfsprint) return types.Version{}, fmt.Errorf("no server") ^ cli/command/trust/key_load.go:112:22: fmt.Errorf can be replaced with errors.New (perfsprint) return []byte{}, fmt.Errorf("could not decrypt key") ^ cli/command/trust/revoke.go:44:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("cannot use a digest reference for IMAGE:TAG") ^ cli/command/trust/revoke.go:105:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("no signed tags to remove") ^ cli/command/trust/signer_add.go:56:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("releases is a reserved keyword, please use a different signer name") ^ cli/command/trust/signer_add.go:60:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("path to a public key must be provided using the `--key` flag") ^ opts/config.go:71:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("source is required") ^ opts/mount.go:168:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("type is required") ^ opts/mount.go:172:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("target is required") ^ opts/network.go:90:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("network name/id is not specified") ^ opts/network.go:129:18: fmt.Errorf can be replaced with errors.New (perfsprint) return "", "", fmt.Errorf("invalid key value pair format in driver options") ^ opts/opts.go:404:13: fmt.Errorf can be replaced with errors.New (perfsprint) return 0, fmt.Errorf("value is too precise") ^ opts/opts.go:412:18: fmt.Errorf can be replaced with errors.New (perfsprint) return "", "", fmt.Errorf("empty string specified for links") ^ opts/parse.go:84:37: fmt.Errorf can be replaced with errors.New (perfsprint) return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: no policy provided before colon") ^ opts/parse.go:89:38: fmt.Errorf can be replaced with errors.New (perfsprint) return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: maximum retry count must be an integer") ^ opts/port.go:105:13: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("hostip is not supported") ^ opts/secret.go:70:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("source is required") ^ opts/env_test.go:57:11: fmt.Errorf can be replaced with errors.New (perfsprint) err: fmt.Errorf("invalid environment variable: =a"), ^ opts/env_test.go:93:11: fmt.Errorf can be replaced with errors.New (perfsprint) err: fmt.Errorf("invalid environment variable: ="), ^ cli-plugins/manager/error_test.go:16:11: fmt.Errorf can be replaced with errors.New (perfsprint) inner := fmt.Errorf("testing") ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e93abde7a0
commit
dfec976e84
|
@ -2,7 +2,7 @@ package manager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
|
@ -13,7 +13,7 @@ func TestPluginError(t *testing.T) {
|
||||||
err := NewPluginError("new error")
|
err := NewPluginError("new error")
|
||||||
assert.Check(t, is.Error(err, "new error"))
|
assert.Check(t, is.Error(err, "new error"))
|
||||||
|
|
||||||
inner := fmt.Errorf("testing")
|
inner := errors.New("testing")
|
||||||
err = wrapAsPluginError(inner, "wrapping")
|
err = wrapAsPluginError(inner, "wrapping")
|
||||||
assert.Check(t, is.Error(err, "wrapping: testing"))
|
assert.Check(t, is.Error(err, "wrapping: testing"))
|
||||||
assert.Check(t, is.ErrorIs(err, inner))
|
assert.Check(t, is.ErrorIs(err, inner))
|
||||||
|
|
|
@ -315,7 +315,7 @@ func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigF
|
||||||
|
|
||||||
func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) {
|
func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return docker.Endpoint{}, fmt.Errorf("no context store initialized")
|
return docker.Endpoint{}, errors.New("no context store initialized")
|
||||||
}
|
}
|
||||||
ctxMeta, err := s.GetMetadata(contextName)
|
ctxMeta, err := s.GetMetadata(contextName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
|
@ -158,7 +157,7 @@ func getExitStatus(errC <-chan error, resultC <-chan container.WaitResponse) err
|
||||||
select {
|
select {
|
||||||
case result := <-resultC:
|
case result := <-resultC:
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return fmt.Errorf(result.Error.Message)
|
return errors.New(result.Error.Message)
|
||||||
}
|
}
|
||||||
if result.StatusCode != 0 {
|
if result.StatusCode != 0 {
|
||||||
return cli.StatusError{StatusCode: int(result.StatusCode)}
|
return cli.StatusError{StatusCode: int(result.StatusCode)}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
|
||||||
|
|
||||||
func TestGetExitStatus(t *testing.T) {
|
func TestGetExitStatus(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
expectedErr = fmt.Errorf("unexpected error")
|
expectedErr = errors.New("unexpected error")
|
||||||
errC = make(chan error, 1)
|
errC = make(chan error, 1)
|
||||||
resultC = make(chan container.WaitResponse, 1)
|
resultC = make(chan container.WaitResponse, 1)
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,6 @@ package container
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -231,7 +230,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
|
||||||
platform *specs.Platform,
|
platform *specs.Platform,
|
||||||
containerName string,
|
containerName string,
|
||||||
) (container.CreateResponse, error) {
|
) (container.CreateResponse, error) {
|
||||||
return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image")
|
return container.CreateResponse{}, errors.New("shouldn't try to pull image")
|
||||||
},
|
},
|
||||||
}, test.EnableContentTrust)
|
}, test.EnableContentTrust)
|
||||||
fakeCLI.SetNotaryClient(tc.notaryFunc)
|
fakeCLI.SetNotaryClient(tc.notaryFunc)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ func TestContainerListErrors(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) {
|
containerListFunc: func(_ container.ListOptions) ([]types.Container, error) {
|
||||||
return nil, fmt.Errorf("error listing containers")
|
return nil, errors.New("error listing containers")
|
||||||
},
|
},
|
||||||
expectedError: "error listing containers",
|
expectedError: "error listing containers",
|
||||||
},
|
},
|
||||||
|
|
|
@ -574,10 +574,10 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
||||||
return nil, errors.Errorf("--health-retries cannot be negative")
|
return nil, errors.Errorf("--health-retries cannot be negative")
|
||||||
}
|
}
|
||||||
if copts.healthStartPeriod < 0 {
|
if copts.healthStartPeriod < 0 {
|
||||||
return nil, fmt.Errorf("--health-start-period cannot be negative")
|
return nil, errors.New("--health-start-period cannot be negative")
|
||||||
}
|
}
|
||||||
if copts.healthStartInterval < 0 {
|
if copts.healthStartInterval < 0 {
|
||||||
return nil, fmt.Errorf("--health-start-interval cannot be negative")
|
return nil, errors.New("--health-start-interval cannot be negative")
|
||||||
}
|
}
|
||||||
|
|
||||||
healthConfig = &container.HealthConfig{
|
healthConfig = &container.HealthConfig{
|
||||||
|
|
|
@ -2,7 +2,7 @@ package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -37,7 +37,7 @@ func TestRemoveForce(t *testing.T) {
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
|
|
||||||
if container == "nosuchcontainer" {
|
if container == "nosuchcontainer" {
|
||||||
return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container))
|
return errdefs.NotFound(errors.New("Error: no such container: " + container))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,6 @@ package container
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -135,7 +134,7 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) {
|
||||||
platform *specs.Platform,
|
platform *specs.Platform,
|
||||||
containerName string,
|
containerName string,
|
||||||
) (container.CreateResponse, error) {
|
) (container.CreateResponse, error) {
|
||||||
return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image")
|
return container.CreateResponse{}, errors.New("shouldn't try to pull image")
|
||||||
},
|
},
|
||||||
}, test.EnableContentTrust)
|
}, test.EnableContentTrust)
|
||||||
fakeCLI.SetNotaryClient(tc.notaryFunc)
|
fakeCLI.SetNotaryClient(tc.notaryFunc)
|
||||||
|
|
|
@ -218,7 +218,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
|
||||||
// with a list of container names/IDs.
|
// with a list of container names/IDs.
|
||||||
|
|
||||||
if options.Filters != nil && options.Filters.Len() > 0 {
|
if options.Filters != nil && options.Filters.Len() > 0 {
|
||||||
return fmt.Errorf("filtering is not supported when specifying a list of containers")
|
return errors.New("filtering is not supported when specifying a list of containers")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the list of containers, and start collecting stats for all
|
// Create the list of containers, and start collecting stats for all
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -112,7 +113,7 @@ func TestNewPullCommandWithContentTrustErrors(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
imagePullFunc: func(ref string, options image.PullOptions) (io.ReadCloser, error) {
|
imagePullFunc: func(ref string, options image.PullOptions) (io.ReadCloser, error) {
|
||||||
return io.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image")
|
return io.NopCloser(strings.NewReader("")), errors.New("shouldn't try to pull image")
|
||||||
},
|
},
|
||||||
}, test.EnableContentTrust)
|
}, test.EnableContentTrust)
|
||||||
cli.SetNotaryClient(tc.notaryFunc)
|
cli.SetNotaryClient(tc.notaryFunc)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
|
@ -83,7 +83,7 @@ func convertDriverOpt(options []string) (map[string]string, error) {
|
||||||
// TODO(thaJeztah): we should probably not accept whitespace here (both for key and value).
|
// TODO(thaJeztah): we should probably not accept whitespace here (both for key and value).
|
||||||
k = strings.TrimSpace(k)
|
k = strings.TrimSpace(k)
|
||||||
if !ok || k == "" {
|
if !ok || k == "" {
|
||||||
return nil, fmt.Errorf("invalid key/value pair format in driver options")
|
return nil, errors.New("invalid key/value pair format in driver options")
|
||||||
}
|
}
|
||||||
driverOpt[k] = strings.TrimSpace(v)
|
driverOpt[k] = strings.TrimSpace(v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -91,16 +91,14 @@ func TestCreateErrorFromDaemon(t *testing.T) {
|
||||||
fs.WithFile("config.json", `{ "Name": "plugin-foo" }`))
|
fs.WithFile("config.json", `{ "Name": "plugin-foo" }`))
|
||||||
defer tmpDir.Remove()
|
defer tmpDir.Remove()
|
||||||
|
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cmd := newCreateCommand(test.NewFakeCli(&fakeClient{
|
||||||
pluginCreateFunc: func(createContext io.Reader, createOptions types.PluginCreateOptions) error {
|
pluginCreateFunc: func(createContext io.Reader, createOptions types.PluginCreateOptions) error {
|
||||||
return fmt.Errorf("Error creating plugin")
|
return errors.New("error creating plugin")
|
||||||
},
|
},
|
||||||
})
|
}))
|
||||||
|
|
||||||
cmd := newCreateCommand(cli)
|
|
||||||
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
|
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
|
||||||
cmd.SetOut(io.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
assert.ErrorContains(t, cmd.Execute(), "Error creating plugin")
|
assert.ErrorContains(t, cmd.Execute(), "error creating plugin")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreatePlugin(t *testing.T) {
|
func TestCreatePlugin(t *testing.T) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ func TestPluginDisableErrors(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
args: []string{"plugin-foo"},
|
args: []string{"plugin-foo"},
|
||||||
expectedError: "Error disabling plugin",
|
expectedError: "error disabling plugin",
|
||||||
pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error {
|
pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error {
|
||||||
return fmt.Errorf("Error disabling plugin")
|
return errors.New("error disabling plugin")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func TestPluginEnableErrors(t *testing.T) {
|
||||||
{
|
{
|
||||||
args: []string{"plugin-foo"},
|
args: []string{"plugin-foo"},
|
||||||
pluginEnableFunc: func(name string, options types.PluginEnableOptions) error {
|
pluginEnableFunc: func(name string, options types.PluginEnableOptions) error {
|
||||||
return fmt.Errorf("failed to enable plugin")
|
return errors.New("failed to enable plugin")
|
||||||
},
|
},
|
||||||
expectedError: "failed to enable plugin",
|
expectedError: "failed to enable plugin",
|
||||||
},
|
},
|
||||||
|
@ -43,8 +43,7 @@ func TestPluginEnableErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cmd := newEnableCommand(
|
cmd := newEnableCommand(test.NewFakeCli(&fakeClient{
|
||||||
test.NewFakeCli(&fakeClient{
|
|
||||||
pluginEnableFunc: tc.pluginEnableFunc,
|
pluginEnableFunc: tc.pluginEnableFunc,
|
||||||
}))
|
}))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/cli/internal/test"
|
"github.com/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/golden"
|
"gotest.tools/v3/golden"
|
||||||
)
|
)
|
||||||
|
@ -52,7 +52,7 @@ func TestInspectErrors(t *testing.T) {
|
||||||
args: []string{"foo"},
|
args: []string{"foo"},
|
||||||
expectedError: "error inspecting plugin",
|
expectedError: "error inspecting plugin",
|
||||||
inspectFunc: func(name string) (*types.Plugin, []byte, error) {
|
inspectFunc: func(name string) (*types.Plugin, []byte, error) {
|
||||||
return nil, nil, fmt.Errorf("error inspecting plugin")
|
return nil, nil, errors.New("error inspecting plugin")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -38,9 +38,9 @@ func TestInstallErrors(t *testing.T) {
|
||||||
{
|
{
|
||||||
description: "installation error",
|
description: "installation error",
|
||||||
args: []string{"foo"},
|
args: []string{"foo"},
|
||||||
expectedError: "Error installing plugin",
|
expectedError: "error installing plugin",
|
||||||
installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
|
installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
|
||||||
return nil, fmt.Errorf("Error installing plugin")
|
return nil, errors.New("error installing plugin")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ func TestInstallErrors(t *testing.T) {
|
||||||
args: []string{"foo"},
|
args: []string{"foo"},
|
||||||
expectedError: "docker image pull",
|
expectedError: "docker image pull",
|
||||||
installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
|
installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
|
||||||
return nil, fmt.Errorf("(image) when fetching")
|
return nil, errors.New("(image) when fetching")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func TestInstallContentTrustErrors(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
pluginInstallFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
|
pluginInstallFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) {
|
||||||
return nil, fmt.Errorf("should not try to install plugin")
|
return nil, errors.New("should not try to install plugin")
|
||||||
},
|
},
|
||||||
}, test.EnableContentTrust)
|
}, test.EnableContentTrust)
|
||||||
cli.SetNotaryClient(tc.notaryFunc)
|
cli.SetNotaryClient(tc.notaryFunc)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func TestListErrors(t *testing.T) {
|
||||||
args: []string{},
|
args: []string{},
|
||||||
expectedError: "error listing plugins",
|
expectedError: "error listing plugins",
|
||||||
listFunc: func(filter filters.Args) (types.PluginsListResponse, error) {
|
listFunc: func(filter filters.Args) (types.PluginsListResponse, error) {
|
||||||
return types.PluginsListResponse{}, fmt.Errorf("error listing plugins")
|
return types.PluginsListResponse{}, errors.New("error listing plugins")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ func TestRemoveErrors(t *testing.T) {
|
||||||
{
|
{
|
||||||
args: []string{"plugin-foo"},
|
args: []string{"plugin-foo"},
|
||||||
pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error {
|
pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error {
|
||||||
return fmt.Errorf("Error removing plugin")
|
return errors.New("error removing plugin")
|
||||||
},
|
},
|
||||||
expectedError: "Error removing plugin",
|
expectedError: "error removing plugin",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package registry
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ func (c fakeClient) Info(context.Context) (system.Info, error) {
|
||||||
|
|
||||||
func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
|
func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
|
||||||
if auth.Password == expiredPassword {
|
if auth.Password == expiredPassword {
|
||||||
return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password")
|
return registrytypes.AuthenticateOKBody{}, errors.New("Invalid Username or Password")
|
||||||
}
|
}
|
||||||
if auth.Password == useToken {
|
if auth.Password == useToken {
|
||||||
return registrytypes.AuthenticateOKBody{
|
return registrytypes.AuthenticateOKBody{
|
||||||
|
@ -41,7 +42,7 @@ func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConf
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
if auth.Username == unknownUser {
|
if auth.Username == unknownUser {
|
||||||
return registrytypes.AuthenticateOKBody{}, fmt.Errorf(errUnknownUser)
|
return registrytypes.AuthenticateOKBody{}, errors.New(errUnknownUser)
|
||||||
}
|
}
|
||||||
return registrytypes.AuthenticateOKBody{}, nil
|
return registrytypes.AuthenticateOKBody{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -187,7 +188,7 @@ func prettyPrintInfo(streams command.Streams, info dockerInfo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 {
|
if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 {
|
||||||
return fmt.Errorf("errors pretty printing info")
|
return errors.New("errors pretty printing info")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ Are you sure you want to continue?`
|
||||||
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) error {
|
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) error {
|
||||||
// TODO version this once "until" filter is supported for volumes
|
// TODO version this once "until" filter is supported for volumes
|
||||||
if options.pruneVolumes && options.filter.Value().Contains("until") {
|
if options.pruneVolumes && options.filter.Value().Contains("until") {
|
||||||
return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`)
|
return errors.New(`ERROR: The "until" filter is not supported with "--volumes"`)
|
||||||
}
|
}
|
||||||
if !options.force {
|
if !options.force {
|
||||||
r, err := command.PromptForConfirmation(ctx, dockerCli.In(), dockerCli.Out(), confirmationMessage(dockerCli, options))
|
r, err := command.PromptForConfirmation(ctx, dockerCli.In(), dockerCli.Out(), confirmationMessage(dockerCli, options))
|
||||||
|
@ -105,11 +105,11 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
|
||||||
}
|
}
|
||||||
spaceReclaimed += spc
|
spaceReclaimed += spc
|
||||||
if output != "" {
|
if output != "" {
|
||||||
fmt.Fprintln(dockerCli.Out(), output)
|
_, _ = fmt.Fprintln(dockerCli.Out(), output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
_, _ = fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
func TestVersionWithoutServer(t *testing.T) {
|
func TestVersionWithoutServer(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
serverVersion: func(ctx context.Context) (types.Version, error) {
|
serverVersion: func(ctx context.Context) (types.Version, error) {
|
||||||
return types.Version{}, fmt.Errorf("no server")
|
return types.Version{}, errors.New("no server")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := NewVersionCommand(cli)
|
cmd := NewVersionCommand(cli)
|
||||||
|
|
|
@ -109,7 +109,7 @@ func decodePrivKeyIfNecessary(privPemBytes []byte, passRet notary.PassRetriever)
|
||||||
if _, ok := pemBlock.Headers["path"]; !ok {
|
if _, ok := pemBlock.Headers["path"]; !ok {
|
||||||
privKey, _, err := trustmanager.GetPasswdDecryptBytes(passRet, privPemBytes, "", "encrypted")
|
privKey, _, err := trustmanager.GetPasswdDecryptBytes(passRet, privPemBytes, "", "encrypted")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, fmt.Errorf("could not decrypt key")
|
return []byte{}, errors.New("could not decrypt key")
|
||||||
}
|
}
|
||||||
privPemBytes = privKey.Private()
|
privPemBytes = privKey.Private()
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func revokeTrust(ctx context.Context, dockerCLI command.Cli, remote string, opti
|
||||||
}
|
}
|
||||||
tag := imgRefAndAuth.Tag()
|
tag := imgRefAndAuth.Tag()
|
||||||
if imgRefAndAuth.Tag() == "" && imgRefAndAuth.Digest() != "" {
|
if imgRefAndAuth.Tag() == "" && imgRefAndAuth.Digest() != "" {
|
||||||
return fmt.Errorf("cannot use a digest reference for IMAGE:TAG")
|
return errors.New("cannot use a digest reference for IMAGE:TAG")
|
||||||
}
|
}
|
||||||
if imgRefAndAuth.Tag() == "" && !options.forceYes {
|
if imgRefAndAuth.Tag() == "" && !options.forceYes {
|
||||||
deleteRemote, err := command.PromptForConfirmation(ctx, dockerCLI.In(), dockerCLI.Out(), fmt.Sprintf("Please confirm you would like to delete all signature data for %s?", remote))
|
deleteRemote, err := command.PromptForConfirmation(ctx, dockerCLI.In(), dockerCLI.Out(), fmt.Sprintf("Please confirm you would like to delete all signature data for %s?", remote))
|
||||||
|
@ -65,7 +65,7 @@ func revokeTrust(ctx context.Context, dockerCLI command.Cli, remote string, opti
|
||||||
if err := revokeSignature(notaryRepo, tag); err != nil {
|
if err := revokeSignature(notaryRepo, tag); err != nil {
|
||||||
return errors.Wrapf(err, "could not remove signature for %s", remote)
|
return errors.Wrapf(err, "could not remove signature for %s", remote)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(dockerCLI.Out(), "Successfully deleted signature for %s\n", remote)
|
_, _ = fmt.Fprintf(dockerCLI.Out(), "Successfully deleted signature for %s\n", remote)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func revokeAllSigs(notaryRepo client.Repository) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(releasedTargetWithRoleList) == 0 {
|
if len(releasedTargetWithRoleList) == 0 {
|
||||||
return fmt.Errorf("no signed tags to remove")
|
return errors.New("no signed tags to remove")
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need all the roles that signed each released target so we can remove from all roles.
|
// we need all the roles that signed each released target so we can remove from all roles.
|
||||||
|
|
|
@ -53,11 +53,11 @@ func addSigner(ctx context.Context, dockerCLI command.Cli, options signerAddOpti
|
||||||
return fmt.Errorf("signer name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", signerName)
|
return fmt.Errorf("signer name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", signerName)
|
||||||
}
|
}
|
||||||
if signerName == "releases" {
|
if signerName == "releases" {
|
||||||
return fmt.Errorf("releases is a reserved keyword, please use a different signer name")
|
return errors.New("releases is a reserved keyword, please use a different signer name")
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.keys.Len() == 0 {
|
if options.keys.Len() == 0 {
|
||||||
return fmt.Errorf("path to a public key must be provided using the `--key` flag")
|
return errors.New("path to a public key must be provided using the `--key` flag")
|
||||||
}
|
}
|
||||||
signerPubKeys, err := ingestPublicKeys(options.keys.GetAll())
|
signerPubKeys, err := ingestPublicKeys(options.keys.GetAll())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ func (c *FakeCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []st
|
||||||
if c.notaryClientFunc != nil {
|
if c.notaryClientFunc != nil {
|
||||||
return c.notaryClientFunc(imgRefAndAuth, actions)
|
return c.notaryClientFunc(imgRefAndAuth, actions)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("no notary client available unless defined")
|
return nil, errors.New("no notary client available unless defined")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManifestStore returns a fake store used for testing
|
// ManifestStore returns a fake store used for testing
|
||||||
|
|
|
@ -2,6 +2,7 @@ package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -68,7 +69,7 @@ func (o *ConfigOpt) Set(value string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.ConfigName == "" {
|
if options.ConfigName == "" {
|
||||||
return fmt.Errorf("source is required")
|
return errors.New("source is required")
|
||||||
}
|
}
|
||||||
if options.File.Name == "" {
|
if options.File.Name == "" {
|
||||||
options.File.Name = options.ConfigName
|
options.File.Name = options.ConfigName
|
||||||
|
|
|
@ -13,7 +13,7 @@ func TestValidateEnv(t *testing.T) {
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
value string
|
value string
|
||||||
expected string
|
expected string
|
||||||
err error
|
expectedErr string
|
||||||
}
|
}
|
||||||
tests := []testCase{
|
tests := []testCase{
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ func TestValidateEnv(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "=a",
|
value: "=a",
|
||||||
err: fmt.Errorf("invalid environment variable: =a"),
|
expectedErr: "invalid environment variable: =a",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "PATH=",
|
value: "PATH=",
|
||||||
|
@ -90,7 +90,7 @@ func TestValidateEnv(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "=",
|
value: "=",
|
||||||
err: fmt.Errorf("invalid environment variable: ="),
|
expectedErr: "invalid environment variable: =",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func TestValidateEnv(t *testing.T) {
|
||||||
tests = append(tests, testCase{
|
tests = append(tests, testCase{
|
||||||
value: "PaTh",
|
value: "PaTh",
|
||||||
expected: fmt.Sprintf("PaTh=%v", os.Getenv("PATH")),
|
expected: fmt.Sprintf("PaTh=%v", os.Getenv("PATH")),
|
||||||
err: nil,
|
expectedErr: "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,10 +108,10 @@ func TestValidateEnv(t *testing.T) {
|
||||||
t.Run(tc.value, func(t *testing.T) {
|
t.Run(tc.value, func(t *testing.T) {
|
||||||
actual, err := ValidateEnv(tc.value)
|
actual, err := ValidateEnv(tc.value)
|
||||||
|
|
||||||
if tc.err == nil {
|
if tc.expectedErr == "" {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
} else {
|
} else {
|
||||||
assert.Error(t, err, tc.err.Error())
|
assert.Error(t, err, tc.expectedErr)
|
||||||
}
|
}
|
||||||
assert.Equal(t, actual, tc.expected)
|
assert.Equal(t, actual, tc.expected)
|
||||||
})
|
})
|
||||||
|
|
|
@ -165,11 +165,11 @@ func (m *MountOpt) Set(value string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if mount.Type == "" {
|
if mount.Type == "" {
|
||||||
return fmt.Errorf("type is required")
|
return errors.New("type is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if mount.Target == "" {
|
if mount.Target == "" {
|
||||||
return fmt.Errorf("target is required")
|
return errors.New("target is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume {
|
if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -83,11 +84,11 @@ func (n *NetworkOpt) Set(value string) error { //nolint:gocyclo
|
||||||
}
|
}
|
||||||
netOpt.DriverOpts[key] = val
|
netOpt.DriverOpts[key] = val
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid field key %s", key)
|
return errors.New("invalid field key " + key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(netOpt.Target) == 0 {
|
if len(netOpt.Target) == 0 {
|
||||||
return fmt.Errorf("network name/id is not specified")
|
return errors.New("network name/id is not specified")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
netOpt.Target = value
|
netOpt.Target = value
|
||||||
|
@ -126,7 +127,7 @@ func parseDriverOpt(driverOpt string) (string, string, error) {
|
||||||
// TODO(thaJeztah): should value be converted to lowercase as well, or only the key?
|
// TODO(thaJeztah): should value be converted to lowercase as well, or only the key?
|
||||||
key, value, ok := strings.Cut(strings.ToLower(driverOpt), "=")
|
key, value, ok := strings.Cut(strings.ToLower(driverOpt), "=")
|
||||||
if !ok || key == "" {
|
if !ok || key == "" {
|
||||||
return "", "", fmt.Errorf("invalid key value pair format in driver options")
|
return "", "", errors.New("invalid key value pair format in driver options")
|
||||||
}
|
}
|
||||||
key = strings.TrimSpace(key)
|
key = strings.TrimSpace(key)
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
|
|
|
@ -401,7 +401,7 @@ func ParseCPUs(value string) (int64, error) {
|
||||||
}
|
}
|
||||||
nano := cpu.Mul(cpu, big.NewRat(1e9, 1))
|
nano := cpu.Mul(cpu, big.NewRat(1e9, 1))
|
||||||
if !nano.IsInt() {
|
if !nano.IsInt() {
|
||||||
return 0, fmt.Errorf("value is too precise")
|
return 0, errors.New("value is too precise")
|
||||||
}
|
}
|
||||||
return nano.Num().Int64(), nil
|
return nano.Num().Int64(), nil
|
||||||
}
|
}
|
||||||
|
@ -409,14 +409,14 @@ func ParseCPUs(value string) (int64, error) {
|
||||||
// ParseLink parses and validates the specified string as a link format (name:alias)
|
// ParseLink parses and validates the specified string as a link format (name:alias)
|
||||||
func ParseLink(val string) (string, string, error) {
|
func ParseLink(val string) (string, string, error) {
|
||||||
if val == "" {
|
if val == "" {
|
||||||
return "", "", fmt.Errorf("empty string specified for links")
|
return "", "", errors.New("empty string specified for links")
|
||||||
}
|
}
|
||||||
// We expect two parts, but restrict to three to allow detecting invalid formats.
|
// We expect two parts, but restrict to three to allow detecting invalid formats.
|
||||||
arr := strings.SplitN(val, ":", 3)
|
arr := strings.SplitN(val, ":", 3)
|
||||||
|
|
||||||
// TODO(thaJeztah): clean up this logic!!
|
// TODO(thaJeztah): clean up this logic!!
|
||||||
if len(arr) > 2 {
|
if len(arr) > 2 {
|
||||||
return "", "", fmt.Errorf("bad format for links: %s", val)
|
return "", "", errors.New("bad format for links: " + val)
|
||||||
}
|
}
|
||||||
// TODO(thaJeztah): this should trim the "/" prefix as well??
|
// TODO(thaJeztah): this should trim the "/" prefix as well??
|
||||||
if len(arr) == 1 {
|
if len(arr) == 1 {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package opts
|
package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -81,12 +81,12 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) {
|
||||||
p := container.RestartPolicy{}
|
p := container.RestartPolicy{}
|
||||||
k, v, ok := strings.Cut(policy, ":")
|
k, v, ok := strings.Cut(policy, ":")
|
||||||
if ok && k == "" {
|
if ok && k == "" {
|
||||||
return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: no policy provided before colon")
|
return container.RestartPolicy{}, errors.New("invalid restart policy format: no policy provided before colon")
|
||||||
}
|
}
|
||||||
if v != "" {
|
if v != "" {
|
||||||
count, err := strconv.Atoi(v)
|
count, err := strconv.Atoi(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: maximum retry count must be an integer")
|
return container.RestartPolicy{}, errors.New("invalid restart policy format: maximum retry count must be an integer")
|
||||||
}
|
}
|
||||||
p.MaximumRetryCount = count
|
p.MaximumRetryCount = count
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -102,7 +103,7 @@ func (p *PortOpt) Set(value string) error {
|
||||||
for _, portBindings := range portBindingMap {
|
for _, portBindings := range portBindingMap {
|
||||||
for _, portBinding := range portBindings {
|
for _, portBinding := range portBindings {
|
||||||
if portBinding.HostIP != "" {
|
if portBinding.HostIP != "" {
|
||||||
return fmt.Errorf("hostip is not supported")
|
return errors.New("hostip is not supported")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -62,12 +63,12 @@ func (o *SecretOpt) Set(value string) error {
|
||||||
|
|
||||||
options.File.Mode = os.FileMode(m)
|
options.File.Mode = os.FileMode(m)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid field in secret request: %s", key)
|
return errors.New("invalid field in secret request: " + key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.SecretName == "" {
|
if options.SecretName == "" {
|
||||||
return fmt.Errorf("source is required")
|
return errors.New("source is required")
|
||||||
}
|
}
|
||||||
if options.File.Name == "" {
|
if options.File.Name == "" {
|
||||||
options.File.Name = options.SecretName
|
options.File.Name = options.SecretName
|
||||||
|
|
Loading…
Reference in New Issue