github.com/lingyao2333/mo-zero@v1.4.1/zrpc/internal/serverinterceptors/crashinterceptor_test.go (about)

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