Bring mwc to 100% coverage.
This commit is contained in:
@@ -4,7 +4,8 @@ import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/kisom/testio"
|
||||
"github.com/kisom/goutils/testio"
|
||||
"github.com/kisom/goutils/assert"
|
||||
)
|
||||
|
||||
func TestMWC(t *testing.T) {
|
||||
@@ -13,15 +14,43 @@ func TestMWC(t *testing.T) {
|
||||
|
||||
mwc := MultiWriteCloser(buf1, buf2)
|
||||
|
||||
if _, err := mwc.Write([]byte("hello, world")); err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
_, err := mwc.Write([]byte("hello, world"))
|
||||
assert.NoErrorT(t, err)
|
||||
|
||||
if !bytes.Equal(buf1.Bytes(), buf2.Bytes()) {
|
||||
t.Fatal("write failed")
|
||||
}
|
||||
assert.BoolT(t, bytes.Equal(buf1.Bytes(), buf2.Bytes()), "write failed")
|
||||
assert.BoolT(t, bytes.Equal(buf1.Bytes(), []byte("hello, world")), "write failed")
|
||||
|
||||
if !bytes.Equal(buf1.Bytes(), []byte("hello, world")) {
|
||||
t.Fatal("writing failed")
|
||||
}
|
||||
err = mwc.Close()
|
||||
assert.NoErrorT(t, err)
|
||||
}
|
||||
|
||||
func TestMWCShort(t *testing.T) {
|
||||
buf1 := testio.NewBufCloser(nil)
|
||||
buf2 := testio.NewBufCloser(nil)
|
||||
buf3 := testio.NewBrokenWriter(5)
|
||||
buf4 := testio.NewSilentBrokenWriter(5)
|
||||
|
||||
mwc := MultiWriteCloser(buf1, buf2, buf3)
|
||||
defer mwc.Close()
|
||||
|
||||
_, err := mwc.Write([]byte("hello, world"))
|
||||
assert.ErrorT(t, err, "expected a short write error", "but no error occurred")
|
||||
mwc.Close()
|
||||
|
||||
mwc = MultiWriteCloser(buf1, buf2, buf4)
|
||||
_, err = mwc.Write([]byte("hello, world"))
|
||||
assert.ErrorT(t, err, "expected a short write error", "but no error occurred")
|
||||
}
|
||||
|
||||
func TestMWCClose(t *testing.T) {
|
||||
buf1 := testio.NewBufCloser(nil)
|
||||
buf2 := testio.NewBufCloser(nil)
|
||||
buf3 := testio.NewBrokenCloser(nil)
|
||||
|
||||
mwc := MultiWriteCloser(buf1, buf2, buf3)
|
||||
_, err := mwc.Write([]byte("hello, world"))
|
||||
assert.NoErrorT(t, err)
|
||||
|
||||
err = mwc.Close()
|
||||
assert.ErrorT(t, err, "expected broken closer to fail")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user