diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index e10754f31b..6001cde2c0 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -61,16 +61,14 @@ func parseRun(args []string) (*container.Config, *container.HostConfig, *network return containerConfig.Config, containerConfig.HostConfig, containerConfig.NetworkingConfig, err } -func parsetest(t *testing.T, args string) (*container.Config, *container.HostConfig, error) { - config, hostConfig, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) - return config, hostConfig, err +func parseMustError(t *testing.T, args string) { + _, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) + assert.Error(t, err, args) } func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) { - config, hostConfig, err := parsetest(t, args) - if err != nil { - t.Fatal(err) - } + config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash")) + assert.NoError(t, err) return config, hostConfig } @@ -86,7 +84,6 @@ func TestParseRunLinks(t *testing.T) { } } -// nolint: gocyclo func TestParseRunAttach(t *testing.T) { if config, _ := mustParse(t, "-a stdin"); !config.AttachStdin || config.AttachStdout || config.AttachStderr { t.Fatalf("Error parsing attach flags. Expect only Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) @@ -103,31 +100,17 @@ func TestParseRunAttach(t *testing.T) { if config, _ := mustParse(t, "-i"); !config.AttachStdin || !config.AttachStdout || !config.AttachStderr { t.Fatalf("Error parsing attach flags. Expect Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) } +} - if _, _, err := parsetest(t, "-a"); err == nil { - t.Fatal("Error parsing attach flags, `-a` should be an error but is not") - } - if _, _, err := parsetest(t, "-a invalid"); err == nil { - t.Fatal("Error parsing attach flags, `-a invalid` should be an error but is not") - } - if _, _, err := parsetest(t, "-a invalid -a stdout"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdout -a invalid` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stdout -a stderr -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdout -a stderr -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stdin -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdin -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stdout -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stdout -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-a stderr -d"); err == nil { - t.Fatal("Error parsing attach flags, `-a stderr -d` should be an error but is not") - } - if _, _, err := parsetest(t, "-d --rm"); err == nil { - t.Fatal("Error parsing attach flags, `-d --rm` should be an error but is not") - } +func TestParseRunWithInvalidArgs(t *testing.T) { + parseMustError(t, "-a") + parseMustError(t, "-a invalid") + parseMustError(t, "-a invalid -a stdout") + parseMustError(t, "-a stdout -a stderr -d") + parseMustError(t, "-a stdin -d") + parseMustError(t, "-a stdout -d") + parseMustError(t, "-a stderr -d") + parseMustError(t, "-d --rm") } // nolint: gocyclo diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index da6a6d059b..50495f00c3 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -106,7 +106,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { closeChan <- err } for _, container := range cs { - s := formatter.NewContainerStats(container.ID[:12], daemonOSType) + s := formatter.NewContainerStats(container.ID[:12]) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) @@ -123,7 +123,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { eh := command.InitEventHandler() eh.Handle("create", func(e events.Message) { if opts.all { - s := formatter.NewContainerStats(e.ID[:12], daemonOSType) + s := formatter.NewContainerStats(e.ID[:12]) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) @@ -132,7 +132,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { }) eh.Handle("start", func(e events.Message) { - s := formatter.NewContainerStats(e.ID[:12], daemonOSType) + s := formatter.NewContainerStats(e.ID[:12]) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) @@ -158,7 +158,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { // Artificially send creation events for the containers we were asked to // monitor (same code path than we use when monitoring all containers). for _, name := range opts.containers { - s := formatter.NewContainerStats(name, daemonOSType) + s := formatter.NewContainerStats(name) if cStats.add(s) { waitFirst.Add(1) go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) diff --git a/cli/command/formatter/stats.go b/cli/command/formatter/stats.go index c0151101a0..f53387e90a 100644 --- a/cli/command/formatter/stats.go +++ b/cli/command/formatter/stats.go @@ -109,10 +109,8 @@ func NewStatsFormat(source, osType string) Format { } // NewContainerStats returns a new ContainerStats entity and sets in it the given name -func NewContainerStats(container, osType string) *ContainerStats { - return &ContainerStats{ - StatsEntry: StatsEntry{Container: container}, - } +func NewContainerStats(container string) *ContainerStats { + return &ContainerStats{StatsEntry: StatsEntry{Container: container}} } // ContainerStatsWrite renders the context for a list of containers statistics diff --git a/cli/command/swarm/init.go b/cli/command/swarm/init.go index ea3189a0c7..91b827eb97 100644 --- a/cli/command/swarm/init.go +++ b/cli/command/swarm/init.go @@ -92,7 +92,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro if err != nil { return errors.Wrap(err, "could not fetch unlock key") } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) + printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) } return nil diff --git a/cli/command/swarm/unlock_key.go b/cli/command/swarm/unlock_key.go index 870f8e4435..4618de7dea 100644 --- a/cli/command/swarm/unlock_key.go +++ b/cli/command/swarm/unlock_key.go @@ -2,6 +2,7 @@ package swarm import ( "fmt" + "io" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -74,16 +75,15 @@ func runUnlockKey(dockerCli command.Cli, opts unlockKeyOptions) error { return nil } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) + printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) return nil } -func printUnlockCommand(ctx context.Context, dockerCli command.Cli, unlockKey string) { +func printUnlockCommand(out io.Writer, unlockKey string) { if len(unlockKey) > 0 { - fmt.Fprintf(dockerCli.Out(), "To unlock a swarm manager after it restarts, "+ + fmt.Fprintf(out, "To unlock a swarm manager after it restarts, "+ "run the `docker swarm unlock`\ncommand and provide the following key:\n\n %s\n\n"+ "Please remember to store this key in a password manager, since without it you\n"+ "will not be able to restart the manager.\n", unlockKey) } - return } diff --git a/cli/command/swarm/update.go b/cli/command/swarm/update.go index 561ca0a768..4d751bbd4e 100644 --- a/cli/command/swarm/update.go +++ b/cli/command/swarm/update.go @@ -65,7 +65,7 @@ func runUpdate(dockerCli command.Cli, flags *pflag.FlagSet, opts swarmOptions) e if err != nil { return errors.Wrap(err, "could not fetch unlock key") } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) + printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) } return nil diff --git a/cli/internal/test/network/client.go b/cli/internal/test/network/client.go index b12fdec6f2..d83288d619 100644 --- a/cli/internal/test/network/client.go +++ b/cli/internal/test/network/client.go @@ -18,11 +18,11 @@ func (c *FakeClient) NetworkConnect(ctx context.Context, networkID, container st } // NetworkCreate fakes creating a network -func (c *FakeClient) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) { +func (c *FakeClient) NetworkCreate(_ context.Context, _ string, options types.NetworkCreate) (types.NetworkCreateResponse, error) { return types.NetworkCreateResponse{}, nil } -// NetworkDisconnect fakes disconencting from a network +// NetworkDisconnect fakes disconnecting from a network func (c *FakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error { return nil } @@ -36,12 +36,12 @@ func (c *FakeClient) NetworkInspect(ctx context.Context, networkID string, optio } // NetworkInspectWithRaw fakes inspecting a network with a raw response -func (c *FakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) { +func (c *FakeClient) NetworkInspectWithRaw(_ context.Context, _ string, _ types.NetworkInspectOptions) (types.NetworkResource, []byte, error) { return types.NetworkResource{}, nil, nil } // NetworkList fakes listing networks -func (c *FakeClient) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { +func (c *FakeClient) NetworkList(_ context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { return nil, nil } @@ -51,6 +51,6 @@ func (c *FakeClient) NetworkRemove(ctx context.Context, networkID string) error } // NetworksPrune fakes pruning networks -func (c *FakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) { +func (c *FakeClient) NetworksPrune(_ context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) { return types.NetworksPruneReport{}, nil } diff --git a/docs/yaml/yaml.go b/docs/yaml/yaml.go index 575f9bec5c..edf5e9dd7f 100644 --- a/docs/yaml/yaml.go +++ b/docs/yaml/yaml.go @@ -66,14 +66,14 @@ func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandle if _, err := io.WriteString(f, filePrepender(filename)); err != nil { return err } - if err := GenYamlCustom(cmd, f, linkHandler); err != nil { + if err := GenYamlCustom(cmd, f); err != nil { return err } return nil } // GenYamlCustom creates custom yaml output -func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error { +func GenYamlCustom(cmd *cobra.Command, w io.Writer) error { cliDoc := cmdDoc{} cliDoc.Name = cmd.CommandPath() diff --git a/gometalinter.json b/gometalinter.json index 9ba9ea47a5..873f9a2bd8 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,6 +1,6 @@ { "Vendor": true, - "Deadline": "3m", + "Deadline": "5m", "Sort": ["linter", "severity", "path"], "Exclude": ["cli/compose/schema/bindata.go"], @@ -16,6 +16,7 @@ "lll", "misspell", "unconvert", + "unparam", "unused", "vet" ],