MCPcopy
hub / github.com/minio/minio-go / TestPanicErrorUnwrap

Function TestPanicErrorUnwrap

pkg/singleflight/singleflight_test.go:28–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestPanicErrorUnwrap(t *testing.T) {
29 t.Parallel()
30
31 testCases := []struct {
32 name string
33 panicValue any
34 wrappedErrorType bool
35 }{
36 {
37 name: "panicError wraps non-error type",
38 panicValue: &panicError{value: "string value"},
39 wrappedErrorType: false,
40 },
41 {
42 name: "panicError wraps error type",
43 panicValue: &panicError{value: new(errValue)},
44 wrappedErrorType: false,
45 },
46 }
47
48 for _, tc := range testCases {
49 tc := tc
50
51 t.Run(tc.name, func(t *testing.T) {
52 t.Parallel()
53
54 var recovered any
55
56 group := &Group[string, any]{}
57
58 func() {
59 defer func() {
60 recovered = recover()
61 t.Logf("after panic(%#v) in group.Do, recovered %#v", tc.panicValue, recovered)
62 }()
63
64 _, _, _ = group.Do(tc.name, func() (any, error) {
65 panic(tc.panicValue)
66 })
67 }()
68
69 if recovered == nil {
70 t.Fatal("expected a non-nil panic value")
71 }
72
73 err, ok := recovered.(error)
74 if !ok {
75 t.Fatalf("recovered non-error type: %T", recovered)
76 }
77
78 if !errors.Is(err, new(errValue)) && tc.wrappedErrorType {
79 t.Errorf("unexpected wrapped error type %T; want %T", err, new(errValue))
80 }
81 })
82 }
83}
84
85func TestDo(t *testing.T) {

Callers

nothing calls this directly

Calls 2

DoMethod · 0.80
IsMethod · 0.45

Tested by

no test coverage detected