You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
361 B
22 lines
361 B
4 years ago
|
package recovery
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestOnce(t *testing.T) {
|
||
|
defer func() {
|
||
|
if recover() != nil {
|
||
|
t.Error("fail")
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
next := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||
|
panic("panic reason")
|
||
|
}
|
||
|
next = Recovery()(next)
|
||
|
_, e := next(context.Background(), "panic")
|
||
|
t.Logf("succ and reason is %v", e)
|
||
|
}
|