From 47b6aef5a3d63c4ec41bf8dbf2e9caccf114bebc Mon Sep 17 00:00:00 2001 From: Luke Kysow Date: Wed, 7 Mar 2018 22:14:15 -0800 Subject: [PATCH] Add ErrEquals assert function. --- testing/assertions.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testing/assertions.go b/testing/assertions.go index f00285e3f..db575807e 100644 --- a/testing/assertions.go +++ b/testing/assertions.go @@ -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 {