From db84b60d6bbe57d5cfec9a4a477022473ce2d197 Mon Sep 17 00:00:00 2001 From: Inhere Date: Sat, 24 Jun 2023 15:55:44 +0800 Subject: [PATCH] :necktie: up: testutil - add more assertions methods and more fakeobj tests --- testutil/assert/assertions_methods.go | 7 +++++++ testutil/fakeobj/io_test.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/testutil/assert/assertions_methods.go b/testutil/assert/assertions_methods.go index 1982169ec..a21ff5a97 100644 --- a/testutil/assert/assertions_methods.go +++ b/testutil/assert/assertions_methods.go @@ -104,6 +104,13 @@ func (as *Assertions) NoErr(err error, fmtAndArgs ...any) *Assertions { return as } +// NoError asserts that the given is a nil error +func (as *Assertions) NoError(err error, fmtAndArgs ...any) *Assertions { + as.t.Helper() + as.ok = NoErr(as.t, err, fmtAndArgs...) + return as +} + // Err asserts that the given is a not nil error func (as *Assertions) Err(err error, fmtAndArgs ...any) *Assertions { as.t.Helper() diff --git a/testutil/fakeobj/io_test.go b/testutil/fakeobj/io_test.go index ee276ebda..d7179a399 100644 --- a/testutil/fakeobj/io_test.go +++ b/testutil/fakeobj/io_test.go @@ -16,6 +16,11 @@ func TestNewWriter(t *testing.T) { assert.Eq(t, "", tw.String()) assert.NoErr(t, tw.Close()) + // write string + _, err = tw.WriteString("hello") + assert.NoErr(t, err) + assert.Eq(t, "hello", tw.ResetGet()) + tw.SetErrOnWrite() _, err = tw.Write([]byte("hello")) assert.Err(t, err)