From 2f83064ec49fb5e7181c42d969d1bcb9b09a2463 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 4 Jul 2024 17:50:02 +0200 Subject: [PATCH] e2e/cli-plugins: check for exit-errors in tests Verify that we get the expected exit-code, not just the message. Signed-off-by: Sebastiaan van Stijn --- e2e/cli-plugins/socket_test.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/e2e/cli-plugins/socket_test.go b/e2e/cli-plugins/socket_test.go index 8d80824d5c..be9b2c67f6 100644 --- a/e2e/cli-plugins/socket_test.go +++ b/e2e/cli-plugins/socket_test.go @@ -1,6 +1,7 @@ package cliplugins import ( + "errors" "io" "os/exec" "strings" @@ -131,7 +132,12 @@ func TestPluginSocketBackwardsCompatible(t *testing.T) { assert.NilError(t, err, "failed to signal process group") }() out, err := command.CombinedOutput() - assert.ErrorContains(t, err, "exit status 1") + + var exitError *exec.ExitError + assert.Assert(t, errors.As(err, &exitError)) + assert.Check(t, exitError.Exited()) + assert.Check(t, is.Equal(exitError.ExitCode(), 1)) + assert.Check(t, is.ErrorContains(err, "exit status 1")) // the plugin process does not receive a SIGINT and does // the CLI cannot cancel it over the socket, so it kills @@ -188,7 +194,12 @@ func TestPluginSocketCommunication(t *testing.T) { assert.NilError(t, err, "failed to signal CLI process") }() out, err := command.CombinedOutput() - assert.ErrorContains(t, err, "exit status 2") + + var exitError *exec.ExitError + assert.Assert(t, errors.As(err, &exitError)) + assert.Check(t, exitError.Exited()) + assert.Check(t, is.Equal(exitError.ExitCode(), 2)) + assert.Check(t, is.ErrorContains(err, "exit status 2")) // the plugin does not get signalled, but it does get its // context canceled by the CLI through the socket @@ -222,7 +233,12 @@ func TestPluginSocketCommunication(t *testing.T) { assert.NilError(t, err, "failed to signal CLI processĀ§") }() out, err := command.CombinedOutput() - assert.ErrorContains(t, err, "exit status 1") + + var exitError *exec.ExitError + assert.Assert(t, errors.As(err, &exitError)) + assert.Check(t, exitError.Exited()) + assert.Check(t, is.Equal(exitError.ExitCode(), 1)) + assert.Check(t, is.ErrorContains(err, "exit status 1")) // the plugin process does not receive a SIGINT and does // not exit after having it's context canceled, so the CLI