mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 19:51:50 +00:00
Wholesale migration away from go-multierror into a custom multierror implementation that is fully compatible with cockroachdb/errors, prints all errors, can be introspected with Is, As, and friends, and more. The new MultiError type is only available as an interface. Co-authored-by: Camden Cheek <camden@ccheek.com>
44 lines
869 B
Go
44 lines
869 B
Go
package errors
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGroup(t *testing.T) {
|
|
err1 := New("group_test: 1")
|
|
err2 := New("group_test: 2")
|
|
|
|
cases := []struct {
|
|
errs []error
|
|
nilResult bool
|
|
}{
|
|
{errs: []error{}, nilResult: true},
|
|
{errs: []error{nil}, nilResult: true},
|
|
{errs: []error{err1}},
|
|
{errs: []error{err1, nil}},
|
|
{errs: []error{err1, nil, err2}},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
var g Group
|
|
|
|
for _, err := range tc.errs {
|
|
err := err
|
|
g.Go(func() error { return err })
|
|
|
|
}
|
|
|
|
gErr := g.Wait()
|
|
if gErr != nil {
|
|
for i := range tc.errs {
|
|
if tc.errs[i] != nil && !strings.Contains(gErr.Error(), tc.errs[i].Error()) {
|
|
t.Fatalf("expected error to contain %q, actual: %v", tc.errs[i].Error(), gErr)
|
|
}
|
|
}
|
|
} else if !tc.nilResult {
|
|
t.Fatalf("Group.Wait() should not have returned nil for errs: %v", tc.errs)
|
|
}
|
|
}
|
|
}
|