diff --git a/cli-plugins/examples/helloworld/main.go b/cli-plugins/examples/helloworld/main.go index 0461e01c8c..d91e1185fa 100644 --- a/cli-plugins/examples/helloworld/main.go +++ b/cli-plugins/examples/helloworld/main.go @@ -12,24 +12,24 @@ import ( ) func main() { - plugin.Run(func(dockerCli command.Cli) *cobra.Command { + plugin.Run(func(dockerCLI command.Cli) *cobra.Command { goodbye := &cobra.Command{ Use: "goodbye", Short: "Say Goodbye instead of Hello", Run: func(cmd *cobra.Command, _ []string) { - fmt.Fprintln(dockerCli.Out(), "Goodbye World!") + _, _ = fmt.Fprintln(dockerCLI.Out(), "Goodbye World!") }, } apiversion := &cobra.Command{ Use: "apiversion", Short: "Print the API version of the server", RunE: func(_ *cobra.Command, _ []string) error { - cli := dockerCli.Client() - ping, err := cli.Ping(context.Background()) + apiClient := dockerCLI.Client() + ping, err := apiClient.Ping(context.Background()) if err != nil { return err } - fmt.Println(ping.APIVersion) + _, _ = fmt.Println(ping.APIVersion) return nil }, } @@ -38,7 +38,7 @@ func main() { Use: "exitstatus2", Short: "Exit with status 2", RunE: func(_ *cobra.Command, _ []string) error { - fmt.Fprintln(dockerCli.Err(), "Exiting with error status 2") + _, _ = fmt.Fprintln(dockerCLI.Err(), "Exiting with error status 2") os.Exit(2) return nil }, @@ -56,33 +56,33 @@ func main() { return err } if preRun { - fmt.Fprintf(dockerCli.Err(), "Plugin PersistentPreRunE called") + _, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin PersistentPreRunE called") } return nil }, RunE: func(cmd *cobra.Command, args []string) error { if debug { - fmt.Fprintf(dockerCli.Err(), "Plugin debug mode enabled") + _, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin debug mode enabled") } switch optContext { case "Christmas": - fmt.Fprintf(dockerCli.Out(), "Merry Christmas!\n") + _, _ = fmt.Fprintln(dockerCLI.Out(), "Merry Christmas!") return nil case "": // nothing } if who == "" { - who, _ = dockerCli.ConfigFile().PluginConfig("helloworld", "who") + who, _ = dockerCLI.ConfigFile().PluginConfig("helloworld", "who") } if who == "" { who = "World" } - fmt.Fprintf(dockerCli.Out(), "Hello %s!\n", who) - dockerCli.ConfigFile().SetPluginConfig("helloworld", "lastwho", who) - return dockerCli.ConfigFile().Save() + _, _ = fmt.Fprintln(dockerCLI.Out(), "Hello", who) + dockerCLI.ConfigFile().SetPluginConfig("helloworld", "lastwho", who) + return dockerCLI.ConfigFile().Save() }, } diff --git a/cli-plugins/hooks/printer.go b/cli-plugins/hooks/printer.go index bedc87f929..f6d4b28ef4 100644 --- a/cli-plugins/hooks/printer.go +++ b/cli-plugins/hooks/printer.go @@ -11,8 +11,8 @@ func PrintNextSteps(out io.Writer, messages []string) { if len(messages) == 0 { return } - fmt.Fprintln(out, aec.Bold.Apply("\nWhat's next:")) + _, _ = fmt.Fprintln(out, aec.Bold.Apply("\nWhat's next:")) for _, n := range messages { - _, _ = fmt.Fprintf(out, " %s\n", n) + _, _ = fmt.Fprintln(out, " ", n) } } diff --git a/e2e/cli-plugins/config_test.go b/e2e/cli-plugins/config_test.go index a9d55e3d87..1cac1dd7b1 100644 --- a/e2e/cli-plugins/config_test.go +++ b/e2e/cli-plugins/config_test.go @@ -20,7 +20,7 @@ func TestConfig(t *testing.T) { res := icmd.RunCmd(run("helloworld")) res.Assert(t, icmd.Expected{ ExitCode: 0, - Out: "Hello Cambridge!", + Out: "Hello Cambridge", }) cfg2, err := config.Load(filepath.Dir(cfg.GetFilename())) diff --git a/e2e/cli-plugins/dial_test.go b/e2e/cli-plugins/dial_test.go index 0be5ec3d4c..87ae6eb488 100644 --- a/e2e/cli-plugins/dial_test.go +++ b/e2e/cli-plugins/dial_test.go @@ -6,8 +6,6 @@ import ( "testing" "github.com/docker/cli/cli-plugins/manager" - "gotest.tools/v3/assert" - is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/icmd" ) @@ -24,7 +22,9 @@ func TestCLIPluginDialStdio(t *testing.T) { helloworld := filepath.Join(os.Getenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"), "docker-helloworld") cmd := icmd.Command(helloworld, "--config=blah", "--log-level", "debug", "helloworld", "--who=foo") res := icmd.RunCmd(cmd, icmd.WithEnv(manager.ReexecEnvvar+"=/bin/true")) - res.Assert(t, icmd.Success) - assert.Assert(t, is.Contains(res.Stderr(), `msg="commandconn: starting /bin/true with [--config=blah --log-level debug system dial-stdio]"`)) - assert.Assert(t, is.Equal(res.Stdout(), "Hello foo!\n")) + res.Assert(t, icmd.Expected{ + ExitCode: 0, + Err: `msg="commandconn: starting /bin/true with [--config=blah --log-level debug system dial-stdio]"`, + Out: `Hello foo`, + }) } diff --git a/e2e/cli-plugins/flags_test.go b/e2e/cli-plugins/flags_test.go index 7631bab0de..69fe6d6ad3 100644 --- a/e2e/cli-plugins/flags_test.go +++ b/e2e/cli-plugins/flags_test.go @@ -15,7 +15,7 @@ func TestRunGoodArgument(t *testing.T) { res := icmd.RunCmd(run("helloworld", "--who", "Cleveland")) res.Assert(t, icmd.Expected{ ExitCode: 0, - Out: "Hello Cleveland!", + Out: "Hello Cleveland", }) } @@ -33,25 +33,25 @@ func TestClashWithGlobalArgs(t *testing.T) { { name: "short-without-val", args: []string{"-D"}, - expectedOut: "Hello World!", + expectedOut: "Hello World", expectedErr: "Plugin debug mode enabled", }, { name: "long-without-val", args: []string{"--debug"}, - expectedOut: "Hello World!", + expectedOut: "Hello World", expectedErr: "Plugin debug mode enabled", }, { name: "short-with-val", args: []string{"-c", "Christmas"}, - expectedOut: "Merry Christmas!", + expectedOut: "Merry Christmas", expectedErr: icmd.None, }, { name: "short-with-val", args: []string{"--context", "Christmas"}, - expectedOut: "Merry Christmas!", + expectedOut: "Merry Christmas", expectedErr: icmd.None, }, } { @@ -220,7 +220,7 @@ func TestCliPluginsVersion(t *testing.T) { name: "plugin-with-version", args: []string{"helloworld", "version"}, expCode: 0, - expOut: "Hello World!", + expOut: "Hello World", expErr: icmd.None, }, { diff --git a/e2e/cli-plugins/plugins/presocket/main.go b/e2e/cli-plugins/plugins/presocket/main.go index 8c8ad6df66..9a695f1883 100644 --- a/e2e/cli-plugins/plugins/presocket/main.go +++ b/e2e/cli-plugins/plugins/presocket/main.go @@ -113,7 +113,7 @@ func RootCmd(dockerCli command.Cli) *cobra.Command { select { case <-done: case <-time.After(2 * time.Second): - _, _ = fmt.Fprint(dockerCli.Err(), "timeout after 2 seconds") + _, _ = fmt.Fprintln(dockerCli.Err(), "timeout after 2 seconds") } return nil }, diff --git a/e2e/cli-plugins/run_test.go b/e2e/cli-plugins/run_test.go index c3bd279c99..db3628802f 100644 --- a/e2e/cli-plugins/run_test.go +++ b/e2e/cli-plugins/run_test.go @@ -4,7 +4,6 @@ import ( "testing" "gotest.tools/v3/assert" - is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" "gotest.tools/v3/icmd" ) @@ -123,7 +122,7 @@ func TestRunGood(t *testing.T) { res := icmd.RunCmd(run("helloworld")) res.Assert(t, icmd.Expected{ ExitCode: 0, - Out: "Hello World!", + Out: "Hello World", Err: icmd.None, }) } @@ -218,18 +217,23 @@ func TestCliInitialized(t *testing.T) { run, _, cleanup := prepare(t) defer cleanup() - var apiversion string + var apiVersion string t.Run("withhook", func(t *testing.T) { res := icmd.RunCmd(run("helloworld", "--pre-run", "apiversion")) - res.Assert(t, icmd.Success) - assert.Assert(t, res.Stdout() != "") - apiversion = res.Stdout() - assert.Assert(t, is.Equal(res.Stderr(), "Plugin PersistentPreRunE called")) + res.Assert(t, icmd.Expected{ + ExitCode: 0, + Err: "Plugin PersistentPreRunE called", + }) + apiVersion = res.Stdout() + assert.Assert(t, apiVersion != "") }) t.Run("withouthook", func(t *testing.T) { res := icmd.RunCmd(run("nopersistentprerun")) - res.Assert(t, icmd.Success) - assert.Assert(t, is.Equal(res.Stdout(), apiversion)) + res.Assert(t, icmd.Expected{ + ExitCode: 0, + Err: icmd.None, + Out: apiVersion, + }) }) }