github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/ctx_test.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"google.golang.org/grpc/metadata"
     9  )
    10  
    11  func TestOutgoingCtx(t *testing.T) {
    12  	t.Run("debug log level", func(t *testing.T) {
    13  		ctx := WithDebugLogLevel(context.TODO())
    14  		md, ok := metadata.FromOutgoingContext(ctx)
    15  		assert.True(t, ok)
    16  		assert.Equal(t, []string{"debug"}, md.Get(logLevelRPCMetaKey))
    17  	})
    18  
    19  	t.Run("info log level", func(t *testing.T) {
    20  		ctx := WithInfoLogLevel(context.TODO())
    21  		md, ok := metadata.FromOutgoingContext(ctx)
    22  		assert.True(t, ok)
    23  		assert.Equal(t, []string{"info"}, md.Get(logLevelRPCMetaKey))
    24  	})
    25  
    26  	t.Run("warn log level", func(t *testing.T) {
    27  		ctx := WithWarnLogLevel(context.TODO())
    28  		md, ok := metadata.FromOutgoingContext(ctx)
    29  		assert.True(t, ok)
    30  		assert.Equal(t, []string{"warn"}, md.Get(logLevelRPCMetaKey))
    31  	})
    32  
    33  	t.Run("error log level", func(t *testing.T) {
    34  		ctx := WithErrorLogLevel(context.TODO())
    35  		md, ok := metadata.FromOutgoingContext(ctx)
    36  		assert.True(t, ok)
    37  		assert.Equal(t, []string{"error"}, md.Get(logLevelRPCMetaKey))
    38  	})
    39  
    40  	t.Run("client request id", func(t *testing.T) {
    41  		ctx := WithClientRequestID(context.TODO(), "test-trace")
    42  		md, ok := metadata.FromOutgoingContext(ctx)
    43  		assert.True(t, ok)
    44  		assert.Equal(t, []string{"test-trace"}, md.Get(clientRequestIDKey))
    45  	})
    46  }