blob: dc28cc37be4d9c8101047c31f91a38d006e39c6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package testhelper
import (
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
// SetCtxGrpcMethod will set the gRPC context value for the proper key
// responsible for an RPC full method name. This directly corresponds to the
// gRPC function responsible for extracting the method:
// https://godoc.org/google.golang.org/grpc#Method
func SetCtxGrpcMethod(ctx context.Context, method string) context.Context {
return grpc.NewContextWithServerTransportStream(ctx, mockServerTransportStream{method})
}
type mockServerTransportStream struct {
method string
}
func (msts mockServerTransportStream) Method() string { return msts.method }
func (mockServerTransportStream) SetHeader(md metadata.MD) error { return nil }
func (mockServerTransportStream) SendHeader(md metadata.MD) error { return nil }
func (mockServerTransportStream) SetTrailer(md metadata.MD) error { return nil }
|