fe938b9849
Using the interface opens up the use of all methods to benchmarks as well as tests.
20 lines
484 B
Go
20 lines
484 B
Go
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.
|
|
func RequireErrorContains(t testing.TB, err error, expectedErrorMessage string) {
|
|
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)
|
|
}
|
|
}
|