github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/meta/test/meta_test.go (about) 1 package test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 "google.golang.org/grpc/metadata" 9 10 "github.com/ydb-platform/ydb-go-sdk/v3/internal/credentials" 11 internal "github.com/ydb-platform/ydb-go-sdk/v3/internal/meta" 12 "github.com/ydb-platform/ydb-go-sdk/v3/internal/version" 13 "github.com/ydb-platform/ydb-go-sdk/v3/meta" 14 "github.com/ydb-platform/ydb-go-sdk/v3/trace" 15 ) 16 17 func TestMetaRequiredHeaders(t *testing.T) { 18 m := internal.New( 19 "database", 20 credentials.NewAccessTokenCredentials("token"), 21 &trace.Driver{}, 22 internal.WithRequestTypeOption("requestType"), 23 internal.WithUserAgentOption("user-agent"), 24 ) 25 26 ctx := context.Background() 27 28 ctx = meta.WithUserAgent(ctx, "userAgent") 29 30 ctx = meta.WithTraceID(ctx, "traceID") 31 32 ctx = metadata.AppendToOutgoingContext(ctx, "some-user-header", "some-user-value") 33 34 ctx, err := m.Context(ctx) 35 if err != nil { 36 t.Fatal(err) 37 } 38 md, has := metadata.FromOutgoingContext(ctx) 39 if !has { 40 t.Fatal("no outgoing metadata") 41 } 42 43 require.Equal(t, []string{"database"}, md.Get(internal.HeaderDatabase)) 44 require.Equal(t, []string{"requestType"}, md.Get(internal.HeaderRequestType)) 45 require.Equal(t, []string{"token"}, md.Get(internal.HeaderTicket)) 46 require.Equal(t, []string{"userAgent", "user-agent"}, md.Get(internal.HeaderUserAgent)) 47 require.Equal(t, []string{"traceID"}, md.Get(internal.HeaderTraceID)) 48 require.Equal(t, []string{ 49 "ydb-go-sdk/" + version.Major + "." + version.Minor + "." + version.Patch, 50 }, md.Get(internal.HeaderVersion)) 51 require.Equal(t, []string{"some-user-value"}, md.Get("some-user-header")) 52 }