github.com/Go-To-Byte/DouSheng/user_center@v0.0.0-20230524130918-ad531c1a3f6a/client/rpc/client_test.go (about) 1 // @Author: Ciusyan 2023/2/9 2 package rpc_test 3 4 import ( 5 "context" 6 "github.com/Go-To-Byte/DouSheng/user_center/apps/user" 7 "github.com/stretchr/testify/assert" 8 "testing" 9 10 "github.com/Go-To-Byte/DouSheng/dou_kit/conf" 11 12 "github.com/Go-To-Byte/DouSheng/user_center/client/rpc" 13 ) 14 15 var ( 16 userCenter *rpc.UserCenterClient 17 ) 18 19 func TestUserCenter(t *testing.T) { 20 should := assert.New(t) 21 22 req := user.NewUserInfoRequest() 23 // 这里主要是为了获取 用户ID 24 validatedToken, err := userCenter.UserService().UserInfo(context.Background(), req) 25 if should.NoError(err) { 26 t.Log(validatedToken) 27 } 28 29 } 30 31 func init() { 32 // 需要先加载配置 33 if err := conf.LoadConfigFromEnv(); err != nil { 34 panic(err) 35 } 36 37 // 获取用户中心的客户端[从环境变量中获取配置] 38 // 获取的配置去执行 kit 库中的 client.NewConfig(consulCfg) 39 center, err := rpc.NewUserCenterClientFromEnv() 40 if err != nil { 41 panic(err) 42 } 43 userCenter = center 44 }