crashinterceptor_test.go 640 B

123456789101112131415161718192021222324252627282930
  1. package serverinterceptors
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "google.golang.org/grpc"
  8. )
  9. func init() {
  10. logx.Disable()
  11. }
  12. func TestStreamCrashInterceptor(t *testing.T) {
  13. err := StreamCrashInterceptor(nil, nil, nil, func(
  14. svr interface{}, stream grpc.ServerStream) error {
  15. panic("mock panic")
  16. })
  17. assert.NotNil(t, err)
  18. }
  19. func TestUnaryCrashInterceptor(t *testing.T) {
  20. _, err := UnaryCrashInterceptor(context.Background(), nil, nil,
  21. func(ctx context.Context, req interface{}) (interface{}, error) {
  22. panic("mock panic")
  23. })
  24. assert.NotNil(t, err)
  25. }