mirror of
https://github.com/coder/coder.git
synced 2025-07-21 01:28:49 +00:00
committed by
GitHub
parent
d7dee2c069
commit
92a95fbd5f
37
pty/ptytest/ptytest_internal_test.go
Normal file
37
pty/ptytest/ptytest_internal_test.go
Normal file
@ -0,0 +1,37 @@
|
||||
package ptytest
|
||||
|
||||
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())
|
||||
}
|
Reference in New Issue
Block a user