Skip to content

Commit

Permalink
WIP: debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jul 4, 2024
1 parent 4c62b2a commit 4d157d7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions e2e/cli-plugins/socket_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cliplugins

import (
"bytes"
"context"
"errors"
"io"
"os/exec"
"strings"
Expand All @@ -11,6 +12,7 @@ import (

"github.com/creack/pty"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

// TestPluginSocketBackwardsCompatible executes a plugin binary
Expand Down Expand Up @@ -177,9 +179,9 @@ func TestPluginSocketCommunication(t *testing.T) {
t.Run("the plugin does not get signalled", func(t *testing.T) {
cmd := run("presocket", "test-socket")
command := exec.Command(cmd.Command[0], cmd.Command[1:]...)
outB := bytes.Buffer{}
command.Stdout = &outB
command.Stderr = &outB
// outB := bytes.Buffer{}
// command.Stdout = &outB
// command.Stderr = &outB
command.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
Expand All @@ -190,13 +192,19 @@ func TestPluginSocketCommunication(t *testing.T) {
err := syscall.Kill(command.Process.Pid, syscall.SIGINT)
assert.NilError(t, err, "failed to signal CLI process")
}()
err := command.Run()
t.Log(outB.String())
// err := command.Run()
out, err := command.CombinedOutput()
// t.Log(outB.String())
t.Log(string(out))
assert.ErrorContains(t, err, "exit status 2")
var exitError *exec.ExitError
if errors.As(err, &exitError) {
assert.Check(t, is.Equal(exitError.ExitCode(), 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")
assert.Check(t, is.Equal(strings.TrimSpace(string(out)), context.Canceled.Error()))
})

t.Run("the main CLI exits after 3 signals", func(t *testing.T) {
Expand Down

0 comments on commit 4d157d7

Please sign in to comment.