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

View File

@ -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