From 4d157d7c81dd42995fdeddc31ebdbec76a81a12f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 4 Jul 2024 16:00:57 +0200 Subject: [PATCH] WIP: debugging Signed-off-by: Sebastiaan van Stijn --- e2e/cli-plugins/socket_test.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/e2e/cli-plugins/socket_test.go b/e2e/cli-plugins/socket_test.go index 5e0b1cbb7c8f..40af2c30338e 100644 --- a/e2e/cli-plugins/socket_test.go +++ b/e2e/cli-plugins/socket_test.go @@ -1,7 +1,8 @@ package cliplugins import ( - "bytes" + "context" + "errors" "io" "os/exec" "strings" @@ -11,6 +12,7 @@ import ( "github.com/creack/pty" "gotest.tools/v3/assert" + is "gotest.tools/v3/assert/cmp" ) // TestPluginSocketBackwardsCompatible executes a plugin binary @@ -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, } @@ -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) {