feat: converge grpc interceptor processing (#2830)
* feat: converge grpc interceptor processing * x * x
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@@ -58,3 +59,115 @@ func TestRpcServer_WithBadAddress(t *testing.T) {
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestRpcServer_buildUnaryInterceptor(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
r *rpcServer
|
||||
len int
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{},
|
||||
},
|
||||
len: 0,
|
||||
},
|
||||
{
|
||||
name: "custom",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
unaryInterceptors: []grpc.UnaryServerInterceptor{
|
||||
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
len: 1,
|
||||
},
|
||||
{
|
||||
name: "middleware",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
unaryInterceptors: []grpc.UnaryServerInterceptor{
|
||||
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler) (interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Stat: true,
|
||||
Prometheus: true,
|
||||
Breaker: true,
|
||||
},
|
||||
},
|
||||
len: 6,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(t, test.len, len(test.r.buildUnaryInterceptors()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRpcServer_buildStreamInterceptor(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
r *rpcServer
|
||||
len int
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{},
|
||||
},
|
||||
len: 0,
|
||||
},
|
||||
{
|
||||
name: "custom",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
streamInterceptors: []grpc.StreamServerInterceptor{
|
||||
func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
len: 1,
|
||||
},
|
||||
{
|
||||
name: "middleware",
|
||||
r: &rpcServer{
|
||||
baseRpcServer: &baseRpcServer{
|
||||
streamInterceptors: []grpc.StreamServerInterceptor{
|
||||
func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
|
||||
handler grpc.StreamHandler) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
middlewares: ServerMiddlewaresConf{
|
||||
Trace: true,
|
||||
Recover: true,
|
||||
Breaker: true,
|
||||
},
|
||||
},
|
||||
len: 4,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(t, test.len, len(test.r.buildStreamInterceptors()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user