Skip to content

Commit

Permalink
👔 up: testutil - add more assertions methods and more fakeobj tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 24, 2023
1 parent 99b25f7 commit db84b60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions testutil/assert/assertions_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions testutil/fakeobj/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit db84b60

Please sign in to comment.