github.com/shuguocloud/go-zero@v1.3.0/zrpc/internal/serverinterceptors/breakerinterceptor_test.go (about)

     1  package serverinterceptors
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"google.golang.org/grpc"
     9  	"google.golang.org/grpc/codes"
    10  	"google.golang.org/grpc/status"
    11  )
    12  
    13  func TestStreamBreakerInterceptor(t *testing.T) {
    14  	err := StreamBreakerInterceptor(nil, nil, &grpc.StreamServerInfo{
    15  		FullMethod: "any",
    16  	}, func(
    17  		srv interface{}, stream grpc.ServerStream) error {
    18  		return status.New(codes.DeadlineExceeded, "any").Err()
    19  	})
    20  	assert.NotNil(t, err)
    21  }
    22  
    23  func TestUnaryBreakerInterceptor(t *testing.T) {
    24  	_, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{
    25  		FullMethod: "any",
    26  	}, func(ctx context.Context, req interface{}) (interface{}, error) {
    27  		return nil, status.New(codes.DeadlineExceeded, "any").Err()
    28  	})
    29  	assert.NotNil(t, err)
    30  }