From fe6659e85394fddef4933cedccc82c8b6121579b Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Thu, 29 Aug 2024 12:15:26 +0200 Subject: [PATCH] grpc: Add test for external dependencies --- grpc/server_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/grpc/server_test.go b/grpc/server_test.go index ce918a86e..a2bda5f50 100644 --- a/grpc/server_test.go +++ b/grpc/server_test.go @@ -7,9 +7,11 @@ import ( "context" "testing" + "github.com/pace/bricks/http/middleware" "github.com/pace/bricks/locale" "github.com/pace/bricks/maintenance/log" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "google.golang.org/grpc/metadata" ) @@ -68,4 +70,23 @@ func TestPrepareContext(t *testing.T) { _, ok = locale.FromCtx(ctx2) assert.False(t, ok) + ctx = metadata.NewIncomingContext(ctx, metadata.MD{ + MetadataKeyExternalDependencies: []string{"foo:60000,bar:1000"}, + }) + + ctx3, md := prepareContext(ctx) + assert.Len(t, md.Get(MetadataKeyExternalDependencies), 0) + + externalDependencyContext := middleware.ExternalDependencyContextFromContext(ctx3) + require.NotNil(t, externalDependencyContext) + assert.Equal(t, "foo:60000,bar:1000", externalDependencyContext.String()) + + ctx = metadata.NewIncomingContext(context.Background(), metadata.MD{}) + + ctx4, md := prepareContext(ctx) + assert.Len(t, md.Get(MetadataKeyExternalDependencies), 0) + + externalDependencyContext = middleware.ExternalDependencyContextFromContext(ctx4) + require.NotNil(t, externalDependencyContext) + assert.Empty(t, externalDependencyContext.String()) }