go-zero/zrpc/internal/serverinterceptors/crashinterceptor_test.go

31 lines
640 B
Go
Raw Normal View History

2020-08-20 22:53:18 +08:00
package serverinterceptors
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/logx"
2020-08-20 22:53:18 +08:00
"google.golang.org/grpc"
)
func init() {
logx.Disable()
}
func TestStreamCrashInterceptor(t *testing.T) {
err := StreamCrashInterceptor(nil, nil, nil, func(
svr interface{}, stream grpc.ServerStream) error {
2020-08-20 22:53:18 +08:00
panic("mock panic")
})
assert.NotNil(t, err)
}
func TestUnaryCrashInterceptor(t *testing.T) {
_, err := UnaryCrashInterceptor(context.Background(), nil, nil,
2020-08-22 23:08:33 +08:00
func(ctx context.Context, req interface{}) (interface{}, error) {
panic("mock panic")
})
2020-08-20 22:53:18 +08:00
assert.NotNil(t, err)
}