go1.19: core/errgroup minor fix

This commit is contained in:
Gerasimos (Makis) Maropoulos 2022-08-15 01:23:41 +03:00
parent 057fa462f4
commit 0d86a9628d
No known key found for this signature in database
GPG Key ID: 403EEB7885C79503
2 changed files with 12 additions and 3 deletions

View File

@ -147,7 +147,7 @@ func (e *Error) As(target interface{}) bool {
} }
} }
return errors.As(e.Err, &te.Err) return errors.As(te.Err, &e)
} }
return ok return ok

View File

@ -32,13 +32,22 @@ func TestErrorIs(t *testing.T) {
} }
} }
// errorString is a trivial implementation of error.
type errorString struct {
s string
}
func (e *errorString) Error() string {
return e.s
}
func TestErrorAs(t *testing.T) { func TestErrorAs(t *testing.T) {
testErr := errors.New("as") testErr := &errorString{"as"}
err := &Error{Err: testErr} err := &Error{Err: testErr}
if expected, got := true, errors.As(err, &testErr); expected != got { if expected, got := true, errors.As(err, &testErr); expected != got {
t.Fatalf("[testErr as err] expected %v but got %v", expected, got) t.Fatalf("[testErr as err] expected %v but got %v", expected, got)
} }
if expected, got := true, errors.As(testErr, &err); expected != got { if expected, got := false, errors.As(testErr, &err); expected != got /* errorString does not implemeny As, so the std/default functionality will be applied */ {
t.Fatalf("[err as testErr] expected %v but got %v", expected, got) t.Fatalf("[err as testErr] expected %v but got %v", expected, got)
} }
} }