github.com/lingyao2333/mo-zero@v1.4.1/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(_ interface{}, _ grpc.ServerStream) error { 17 return status.New(codes.DeadlineExceeded, "any").Err() 18 }) 19 assert.NotNil(t, err) 20 } 21 22 func TestUnaryBreakerInterceptor(t *testing.T) { 23 _, err := UnaryBreakerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{ 24 FullMethod: "any", 25 }, func(_ context.Context, _ interface{}) (interface{}, error) { 26 return nil, status.New(codes.DeadlineExceeded, "any").Err() 27 }) 28 assert.NotNil(t, err) 29 }