Files
coder/testutil/expecter/stdbuf_internal_test.go
Spike Curtis a16de96611 chore: extract Expecter into its own package (#25806)
Relates to https://github.com/coder/internal/issues/1400  
  
Extracts the code that matches command output from the code that sets up a PTY, so it can be used independently.  
  
Subsequent PRs will actually refactor the tests to use this directly over an inmemory pipe.<!--

If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting.

-->
2026-05-28 17:38:09 -04:00

38 lines
635 B
Go

package expecter
import (
"bytes"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStdbuf(t *testing.T) {
t.Parallel()
var got bytes.Buffer
b := newStdbuf()
done := make(chan struct{})
go func() {
defer close(done)
_, err := io.Copy(&got, b)
assert.NoError(t, err)
}()
_, err := b.Write([]byte("hello "))
require.NoError(t, err)
_, err = b.Write([]byte("world\n"))
require.NoError(t, err)
_, err = b.Write([]byte("bye\n"))
require.NoError(t, err)
err = b.Close()
require.NoError(t, err)
<-done
assert.Equal(t, "hello world\nbye\n", got.String())
}