trpc.group/trpc-go/trpc-go@v1.0.3/naming/servicerouter/options_test.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package servicerouter 15 16 import ( 17 "context" 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestOptions(t *testing.T) { 24 opts := &Options{} 25 26 ctx := context.Background() 27 WithContext(ctx)(opts) 28 WithNamespace("ns")(opts) 29 WithSourceNamespace("sns")(opts) 30 WithSourceServiceName("sname")(opts) 31 WithSourceEnvName("envname")(opts) 32 WithEnvTransfer("envtransfer")(opts) 33 WithEnvKey("env")(opts) 34 WithDisableServiceRouter()(opts) 35 WithDestinationEnvName("dst_env")(opts) 36 WithSourceSetName("setname")(opts) 37 WithDestinationSetName("dstSetName")(opts) 38 WithSourceMetadata("srcMeta", "value")(opts) 39 WithDestinationMetadata("dstMeta", "value")(opts) 40 41 assert.Equal(t, opts.Ctx, ctx) 42 assert.Equal(t, opts.Namespace, "ns") 43 assert.Equal(t, opts.SourceNamespace, "sns") 44 assert.Equal(t, opts.SourceServiceName, "sname") 45 assert.Equal(t, opts.SourceEnvName, "envname") 46 assert.Equal(t, opts.SourceSetName, "setname") 47 assert.Equal(t, opts.EnvTransfer, "envtransfer") 48 assert.Equal(t, opts.EnvKey, "env") 49 assert.True(t, opts.DisableServiceRouter) 50 assert.Equal(t, opts.DestinationEnvName, "dst_env") 51 assert.Equal(t, opts.DestinationSetName, "dstSetName") 52 assert.Equal(t, opts.SourceMetadata["srcMeta"], "value") 53 assert.Equal(t, opts.DestinationMetadata["dstMeta"], "value") 54 }