diff --git a/byteutil/buffer.go b/byteutil/buffer.go index c0a6917fe..04eb111cc 100644 --- a/byteutil/buffer.go +++ b/byteutil/buffer.go @@ -57,9 +57,24 @@ func (b *Buffer) MustWriteString(ss ...string) { } } +// ResetGet buffer string. alias of ResetAndGet() +func (b *Buffer) ResetGet() string { + return b.ResetAndGet() +} + // ResetAndGet buffer string. func (b *Buffer) ResetAndGet() string { s := b.String() b.Reset() return s } + +// Close buffer +func (b *Buffer) Close() error { + return nil +} + +// Flush buffer +func (b *Buffer) Flush() error { + return nil +} diff --git a/byteutil/buffer_test.go b/byteutil/buffer_test.go index 843c364c5..76c31694a 100644 --- a/byteutil/buffer_test.go +++ b/byteutil/buffer_test.go @@ -19,8 +19,11 @@ func TestBuffer_WriteAny(t *testing.T) { assert.Eq(t, "ab-cd-ef", buf.ResetAndGet()) buf.WriteAny(23, "abc") - assert.Eq(t, "23abc", buf.ResetAndGet()) + assert.Eq(t, "23abc", buf.ResetGet()) buf.Writeln("abc") assert.Eq(t, "abc\n", buf.ResetAndGet()) + + assert.NoErr(t, buf.Close()) + assert.NoErr(t, buf.Flush()) } diff --git a/testutil/fakeobj/io.go b/testutil/fakeobj/io.go index bca0584b1..8fd341a8f 100644 --- a/testutil/fakeobj/io.go +++ b/testutil/fakeobj/io.go @@ -16,6 +16,11 @@ type Writer struct { ErrOnClose bool } +// NewBuffer instance. alias of NewWriter() +func NewBuffer() *Writer { + return NewWriter() +} + // NewWriter instance func NewWriter() *Writer { return &Writer{} @@ -39,28 +44,35 @@ func (w *Writer) SetErrOnClose() *Writer { return w } -// Flush implements -func (w *Writer) Flush() error { - if w.ErrOnFlush { - return errors.New("flush error") - } - +// ResetGet buffer string. +func (w *Writer) ResetGet() string { + s := w.String() w.Reset() - return nil + return s +} + +// Write implements +func (w *Writer) Write(p []byte) (n int, err error) { + if w.ErrOnWrite { + return 0, errors.New("fake write error") + } + return w.Buffer.Write(p) } // Close implements func (w *Writer) Close() error { if w.ErrOnClose { - return errors.New("close error") + return errors.New("fake close error") } return nil } -// Write implements -func (w *Writer) Write(p []byte) (n int, err error) { - if w.ErrOnWrite { - return 0, errors.New("write error") +// Flush implements +func (w *Writer) Flush() error { + if w.ErrOnFlush { + return errors.New("fake flush error") } - return w.Buffer.Write(p) + + w.Reset() + return nil }