Skip to content

Commit d152b54

Browse files
committed
update(assert): add new assert func: ErrHasMsg
1 parent 8932d06 commit d152b54

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

testutil/assert/asserts.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ func ErrMsgContains(t TestingT, err error, subMsg string, fmtAndArgs ...any) boo
486486

487487
// ErrSubMsg asserts that the given is a not nil error and the error message contains subMsg
488488
func ErrSubMsg(t TestingT, err error, subMsg string, fmtAndArgs ...any) bool {
489+
t.Helper()
490+
return ErrMsgContains(t, err, subMsg, fmtAndArgs...)
491+
}
492+
493+
// ErrHasMsg asserts that the given is a not nil error and the error message contains subMsg
494+
func ErrHasMsg(t TestingT, err error, subMsg string, fmtAndArgs ...any) bool {
495+
t.Helper()
489496
return ErrMsgContains(t, err, subMsg, fmtAndArgs...)
490497
}
491498

testutil/assert/asserts_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ func TestErr(t *testing.T) {
317317
assert.Err(t, err, "user custom message")
318318
assert.Error(t, err)
319319
assert.ErrMsg(t, err, "this is a error")
320+
assert.ErrHasMsg(t, err, "a error")
320321
}
321322

322323
func TestContains(t *testing.T) {

0 commit comments

Comments
 (0)