2020-05-01 16:56:34 +00:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RequireErrorContains is a test helper for asserting that an error occurred
|
|
|
|
// and the error message returned contains the expected error message as a
|
|
|
|
// substring.
|
2021-03-16 22:05:39 +00:00
|
|
|
func RequireErrorContains(t testing.TB, err error, expectedErrorMessage string) {
|
2020-05-01 16:56:34 +00:00
|
|
|
t.Helper()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("An error is expected but got nil.")
|
|
|
|
}
|
|
|
|
if !strings.Contains(err.Error(), expectedErrorMessage) {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
}
|