ErrorContains dont allow empty string (#11314)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terencechain
2022-08-25 12:07:39 -07:00
committed by GitHub
parent 436792fe38
commit 2b3025828f
2 changed files with 13 additions and 0 deletions

View File

@@ -99,6 +99,9 @@ func ErrorIs(loggerFn assertionLoggerFn, err, target error, msg ...interface{})
// ErrorContains asserts that actual error contains wanted message.
func ErrorContains(loggerFn assertionLoggerFn, want string, err error, msg ...interface{}) {
if want == "" {
loggerFn("Want string can't be empty")
}
if err == nil || !strings.Contains(err.Error(), want) {
errMsg := parseMsg("Expected error not returned", msg...)
_, file, line, _ := runtime.Caller(2)

View File

@@ -564,6 +564,16 @@ func TestAssert_ErrorContains(t *testing.T) {
},
expectedErr: "",
},
{
name: "expected error with params",
args: args{
tb: &assertions.TBMock{},
want: "",
err: errors.New("failed"),
msgs: []interface{}{"Something wrong (for slot %d)", 12},
},
expectedErr: "Want string can't be empty",
},
}
for _, tt := range tests {
verify := func() {