Add ErrEquals assert function.

This commit is contained in:
Luke Kysow
2018-03-07 22:14:15 -08:00
parent b45ee9c86c
commit 47b6aef5a3

View File

@@ -37,6 +37,17 @@ func Equals(tb testing.TB, exp, act interface{}) {
}
}
// ErrEquals fails the test if act is nil or act.Error() != exp
func ErrEquals(tb testing.TB, exp string, act error) {
tb.Helper()
if act == nil {
tb.Errorf("exp err %q but err was nil", exp)
}
if act.Error() != exp {
tb.Errorf("exp err: %q but got: %q", exp, act.Error())
}
}
// Contains fails the test if the slice doesn't contain the expected element
func Contains(tb testing.TB, exp interface{}, slice []string) {
for _, v := range slice {