pkg: add grpcutil package (#1032)

This commit is contained in:
Caleb Doxsey 2020-07-01 15:21:19 -06:00 committed by GitHub
parent fae02791f5
commit 09621ee263
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,29 @@
package grpcutil
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"
)
func TestWithOutgoingSessionID(t *testing.T) {
ctx := context.Background()
ctx = WithOutgoingSessionID(ctx, "EXAMPLE")
md, ok := metadata.FromOutgoingContext(ctx)
if !assert.True(t, ok) {
return
}
assert.Equal(t, []string{"EXAMPLE"}, md.Get("sessionid"))
}
func TestSessionIDFromGRPCRequest(t *testing.T) {
ctx := context.Background()
ctx = metadata.NewIncomingContext(ctx, metadata.MD{
"sessionid": {"EXAMPLE"},
})
sessionID, ok := SessionIDFromGRPCRequest(ctx)
assert.True(t, ok)
assert.Equal(t, "EXAMPLE", sessionID)
}