crashinterceptor_test.go 666 B

12345678910111213141516171819202122232425262728293031
  1. package serverinterceptors
  2. import (
  3. "context"
  4. "testing"
  5. "git.i2edu.net/i2/go-zero/core/logx"
  6. "github.com/stretchr/testify/assert"
  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. srv interface{}, stream grpc.ServerStream) error {
  15. panic("mock panic")
  16. })
  17. assert.NotNil(t, err)
  18. }
  19. func TestUnaryCrashInterceptor(t *testing.T) {
  20. interceptor := UnaryCrashInterceptor()
  21. _, err := interceptor(context.Background(), nil, nil,
  22. func(ctx context.Context, req interface{}) (interface{}, error) {
  23. panic("mock panic")
  24. })
  25. assert.NotNil(t, err)
  26. }