e2e/cli-plugins: use cmd.CombinedOutput() instead of custom buffer

Also remove a debug-log, as the output would already be shown if
the test would fail.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-07-04 17:42:09 +02:00
parent c6b40640cc
commit baf35da401
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 2 additions and 7 deletions

View File

@ -1,7 +1,6 @@
package cliplugins package cliplugins
import ( import (
"bytes"
"io" "io"
"os/exec" "os/exec"
"strings" "strings"
@ -178,9 +177,6 @@ func TestPluginSocketCommunication(t *testing.T) {
t.Run("the plugin does not get signalled", func(t *testing.T) { t.Run("the plugin does not get signalled", func(t *testing.T) {
cmd := run("presocket", "test-socket") cmd := run("presocket", "test-socket")
command := exec.Command(cmd.Command[0], cmd.Command[1:]...) command := exec.Command(cmd.Command[0], cmd.Command[1:]...)
outB := bytes.Buffer{}
command.Stdout = &outB
command.Stderr = &outB
command.SysProcAttr = &syscall.SysProcAttr{ command.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true, Setpgid: true,
} }
@ -191,14 +187,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")
}() }()
err := command.Run() out, err := command.CombinedOutput()
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 its // the plugin does not get signalled, but it does get its
// context canceled by the CLI through the socket // context canceled by the CLI through the socket
const expected = "test-socket: exiting after context was done" const expected = "test-socket: exiting after context was done"
actual := strings.TrimSpace(outB.String()) actual := strings.TrimSpace(string(out))
assert.Check(t, is.Equal(actual, expected)) assert.Check(t, is.Equal(actual, expected))
}) })