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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-07-04 17:08:14 +02:00
parent e9f32edac5
commit c6b40640cc
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 11 additions and 8 deletions

View File

@ -39,7 +39,7 @@ func RootCmd(dockerCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
go func() { go func() {
<-cmd.Context().Done() <-cmd.Context().Done()
_, _ = fmt.Fprintln(dockerCli.Out(), "context cancelled") _, _ = fmt.Fprintln(dockerCli.Out(), "test-no-socket: exiting after context was done")
os.Exit(2) os.Exit(2)
}() }()
signalCh := make(chan os.Signal, 10) 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 { RunE: func(cmd *cobra.Command, args []string) error {
go func() { go func() {
<-cmd.Context().Done() <-cmd.Context().Done()
_, _ = fmt.Fprintln(dockerCli.Out(), "context cancelled") _, _ = fmt.Fprintln(dockerCli.Out(), "test-socket: exiting after context was done")
os.Exit(2) os.Exit(2)
}() }()
signalCh := make(chan os.Signal, 10) signalCh := make(chan os.Signal, 10)

View File

@ -11,6 +11,7 @@ import (
"github.com/creack/pty" "github.com/creack/pty"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
) )
// TestPluginSocketBackwardsCompatible executes a plugin binary // TestPluginSocketBackwardsCompatible executes a plugin binary
@ -194,9 +195,11 @@ func TestPluginSocketCommunication(t *testing.T) {
t.Log(outB.String()) t.Log(outB.String())
assert.ErrorContains(t, err, "exit status 2") assert.ErrorContains(t, err, "exit status 2")
// the plugin does not get signalled, but it does get it's // the plugin does not get signalled, but it does get its
// context cancelled by the CLI through the socket // context canceled by the CLI through the socket
assert.Equal(t, outB.String(), "context cancelled\n") 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) { 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) err = syscall.Kill(command.Process.Pid, syscall.SIGINT)
assert.NilError(t, err, "failed to signal CLI process§") assert.NilError(t, err, "failed to signal CLI process§")
}() }()
bytes, err := command.CombinedOutput() out, err := command.CombinedOutput()
assert.ErrorContains(t, err, "exit status 1") assert.ErrorContains(t, err, "exit status 1")
// the plugin process does not receive a SIGINT and does // 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 // 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")
}) })
}) })
} }