forked from cockroachdb/errors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrutil_api_test.go
31 lines (25 loc) · 935 Bytes
/
errutil_api_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package errors_test
import (
"fmt"
"strings"
"testing"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/errors/testutils"
)
func TestUnwrap(t *testing.T) {
tt := testutils.T{t}
e := fmt.Errorf("foo %w %w", fmt.Errorf("bar"), fmt.Errorf("baz"))
// Compatibility with go 1.20: Unwrap() on a multierror returns nil
// (per API documentation)
tt.Check(errors.Unwrap(e) == nil)
}
// More detailed testing of Join is in datadriven_test.go. Here we make
// sure that the public API includes the stacktrace wrapper.
func TestJoin(t *testing.T) {
e := errors.Join(errors.New("abc123"), errors.New("def456"))
printed := fmt.Sprintf("%+v", e)
expected := `Error types: (1) *withstack.withStack (2) *join.joinError (3) *withstack.withStack (4) *errutil.leafError (5) *withstack.withStack (6) *errutil.leafError`
if !strings.Contains(printed, expected) {
t.Errorf("Expected: %s to contain: %s", printed, expected)
}
}