| Index: common/testing/assertions/error_tests.go
|
| diff --git a/common/testing/assertions/error_tests.go b/common/testing/assertions/error_tests.go
|
| index fa309ba7daae62d2eadc299f35585fe0983d6e9b..5aa2146e81d9ea2bf7af45cee8f67655ecce6cd7 100644
|
| --- a/common/testing/assertions/error_tests.go
|
| +++ b/common/testing/assertions/error_tests.go
|
| @@ -7,6 +7,8 @@ package assertions
|
| import (
|
| "fmt"
|
|
|
| + "github.com/luci/luci-go/common/errors"
|
| +
|
| "github.com/smartystreets/assertions"
|
| )
|
|
|
| @@ -67,3 +69,24 @@ func ShouldPanicLike(function interface{}, expected ...interface{}) (ret string)
|
| f()
|
| return ShouldErrLike(nil, expected...)
|
| }
|
| +
|
| +// ShouldUnwrapTo asserts that an error, when unwrapped, equals another error.
|
| +//
|
| +// The actual field will be unwrapped using errors.Unwrap and then compared to
|
| +// the error in expected.
|
| +func ShouldUnwrapTo(actual interface{}, expected ...interface{}) string {
|
| + act, ok := actual.(error)
|
| + if !ok {
|
| + return fmt.Sprintf("ShouldUnwrapTo requires an error actual type, got %T", act)
|
| + }
|
| +
|
| + if len(expected) != 1 {
|
| + return fmt.Sprintf("ShouldUnwrapTo requires exactly one expected value, got %d", len(expected))
|
| + }
|
| + exp, ok := expected[0].(error)
|
| + if !ok {
|
| + return fmt.Sprintf("ShouldUnwrapTo requires an error expected type, got %T", expected[0])
|
| + }
|
| +
|
| + return assertions.ShouldEqual(errors.Unwrap(act), exp)
|
| +}
|
|
|