diff --git a/internal/exec/command_linux_test.go b/internal/exec/command_linux_test.go index 754db44e..b2bb5074 100644 --- a/internal/exec/command_linux_test.go +++ b/internal/exec/command_linux_test.go @@ -1,6 +1,7 @@ package exec import ( + "bytes" "context" "fmt" "testing" @@ -71,3 +72,15 @@ func TestExecDoesNotFailIfLongLinesAreStreamed(t *testing.T) { ExpectSuccess().Run(context.Background()) require.NoError(t, err) } + +func TestStderrStream(t *testing.T) { + ctx := context.Background() + buf := bytes.Buffer{} + + _, err := Command("bash", "-c", "echo 'stderrHello' >&2"). + LogPrefix(""). + LogFn(func(f string, a ...any) { fmt.Fprintf(&buf, f, a...) }).ExpectSuccess().Run(ctx) + require.NoError(t, err) + t.Log(buf.String()) + assert.Contains(t, buf.String(), "stderrHello\n") +} diff --git a/internal/exec/command_test.go b/internal/exec/command_test.go index 2e332b1d..2a40fd9a 100644 --- a/internal/exec/command_test.go +++ b/internal/exec/command_test.go @@ -1,6 +1,7 @@ package exec import ( + "bytes" "context" "fmt" "runtime" @@ -58,3 +59,17 @@ func TestExpectSuccess(t *testing.T) { require.Error(t, err) assert.Nil(t, res) } + +func TestOutputStream(t *testing.T) { + ctx := context.Background() + const echoStr = "hello\nline2" + + buf := bytes.Buffer{} + + _, err := Command("bash", "-c", + fmt.Sprintf("echo '%s'", echoStr)).LogPrefix(""). + LogFn(func(f string, a ...any) { fmt.Fprintf(&buf, f, a...) }).ExpectSuccess().Run(ctx) + require.NoError(t, err) + require.Contains(t, buf.String(), echoStr) + +}