From c6b40640ccf1bd1b691f32cd1f22dd0a05bb05eb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 4 Jul 2024 17:08:14 +0200 Subject: [PATCH] e2e/cli-plugins: use identifiable output for test This confused me fore a bit, because I thought the test was checking for an actual `context.Canceled` error (which is spelled "context canceled" with a single "l". But then I found that this was a string that's printed as part of a test-utility, just looking very similar but with the British spelling ("cancelled"). Let's change this to a message that's unique for the test, also to make it more grep'able. Signed-off-by: Sebastiaan van Stijn --- e2e/cli-plugins/plugins/presocket/main.go | 4 ++-- e2e/cli-plugins/socket_test.go | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/e2e/cli-plugins/plugins/presocket/main.go b/e2e/cli-plugins/plugins/presocket/main.go index d0ec79dcf4..8c8ad6df66 100644 --- a/e2e/cli-plugins/plugins/presocket/main.go +++ b/e2e/cli-plugins/plugins/presocket/main.go @@ -39,7 +39,7 @@ func RootCmd(dockerCli command.Cli) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { go func() { <-cmd.Context().Done() - _, _ = fmt.Fprintln(dockerCli.Out(), "context cancelled") + _, _ = fmt.Fprintln(dockerCli.Out(), "test-no-socket: exiting after context was done") os.Exit(2) }() signalCh := make(chan os.Signal, 10) @@ -64,7 +64,7 @@ func RootCmd(dockerCli command.Cli) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { go func() { <-cmd.Context().Done() - _, _ = fmt.Fprintln(dockerCli.Out(), "context cancelled") + _, _ = fmt.Fprintln(dockerCli.Out(), "test-socket: exiting after context was done") os.Exit(2) }() signalCh := make(chan os.Signal, 10) diff --git a/e2e/cli-plugins/socket_test.go b/e2e/cli-plugins/socket_test.go index b34982c32b..4c2539b73e 100644 --- a/e2e/cli-plugins/socket_test.go +++ b/e2e/cli-plugins/socket_test.go @@ -11,6 +11,7 @@ import ( "github.com/creack/pty" "gotest.tools/v3/assert" + is "gotest.tools/v3/assert/cmp" ) // TestPluginSocketBackwardsCompatible executes a plugin binary @@ -194,9 +195,11 @@ func TestPluginSocketCommunication(t *testing.T) { t.Log(outB.String()) assert.ErrorContains(t, err, "exit status 2") - // the plugin does not get signalled, but it does get it's - // context cancelled by the CLI through the socket - assert.Equal(t, outB.String(), "context cancelled\n") + // the plugin does not get signalled, but it does get its + // context canceled by the CLI through the socket + const expected = "test-socket: exiting after context was done" + actual := strings.TrimSpace(outB.String()) + assert.Check(t, is.Equal(actual, expected)) }) t.Run("the main CLI exits after 3 signals", func(t *testing.T) { @@ -223,13 +226,13 @@ func TestPluginSocketCommunication(t *testing.T) { err = syscall.Kill(command.Process.Pid, syscall.SIGINT) assert.NilError(t, err, "failed to signal CLI processĀ§") }() - bytes, err := command.CombinedOutput() + out, err := command.CombinedOutput() assert.ErrorContains(t, err, "exit status 1") // the plugin process does not receive a SIGINT and does - // not exit after having it's context cancelled, so the CLI + // not exit after having it's context canceled, so the CLI // kills the plugin process and forcefully exits - assert.Equal(t, string(bytes), "got 3 SIGTERM/SIGINTs, forcefully exiting\n") + assert.Equal(t, string(out), "got 3 SIGTERM/SIGINTs, forcefully exiting\n") }) }) }