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()) }