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.
ntool/ntest/writer_test.go

29 lines
584 B
Go

package ntest_test
import (
"git.noahlan.cn/noahlan/ntool/ntest"
"git.noahlan.cn/noahlan/ntool/ntest/assert"
"testing"
)
func TestNewTestWriter(t *testing.T) {
tw := ntest.NewTestWriter()
_, err := tw.Write([]byte("hello"))
assert.NoErr(t, err)
assert.Eq(t, "hello", tw.String())
assert.NoErr(t, tw.Flush())
assert.Eq(t, "", tw.String())
assert.NoErr(t, tw.Close())
tw.SetErrOnWrite()
_, err = tw.Write([]byte("hello"))
assert.Err(t, err)
assert.Eq(t, "", tw.String())
tw.SetErrOnFlush()
assert.Err(t, tw.Flush())
tw.SetErrOnClose()
assert.Err(t, tw.Close())
}