You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
noxy/io_test.go

38 lines
802 B
Go

package noxy
import (
"bytes"
"testing"
"testing/iotest"
)
// ErrorWriter always returns Err on Write calls.
type ErrorWriter struct {
Err error
}
func (ew ErrorWriter) Write([]byte) (int, error) {
return 0, ew.Err
}
func TestSinkTeeReader(t *testing.T) {
const text = "hello"
var w bytes.Buffer
tee := SinkTeeReader(bytes.NewBufferString(text), &w)
if err := iotest.TestReader(tee, []byte(text)); err != nil {
t.Errorf("tee reader: %v", err)
}
if v := string(w.Bytes()); v != text {
t.Errorf("b2 = %q; want %q", v, text)
}
}
func TestSinkTeeReaderErrWriter(t *testing.T) {
const text = "hello"
tee := SinkTeeReader(bytes.NewBufferString(text), ErrorWriter{iotest.ErrTimeout})
if err := iotest.TestReader(tee, []byte(text)); err != nil {
t.Errorf("tee reader: %v", err)
}
}