Skip to content

Commit

Permalink
test: fix get user token
Browse files Browse the repository at this point in the history
  • Loading branch information
icey-yu committed Sep 29, 2024
1 parent aa37216 commit 67e43eb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
14 changes: 12 additions & 2 deletions integration_test/internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,19 @@ func (m *MetaManager) GetSecret() string {
return m.secret
}

func (m *MetaManager) GetToken(userID string, platformID int32) (string, error) {
func (m *MetaManager) GetAdminToken(userID string, platformID int32) (string, error) {
req := authPB.UserTokenReq{PlatformID: platformID, UserID: userID, Secret: m.secret}
resp := authPB.UserTokenResp{}
err := m.PostWithCtx(api.UsersToken.Route(), &req, &resp)
if err != nil {
return "", err
}
return resp.Token, nil
}

func (m *MetaManager) GetUserToken(userID string, platformID int32) (string, error) {
req := authPB.GetUserTokenReq{PlatformID: platformID, UserID: userID}
resp := authPB.GetUserTokenResp{}
err := m.PostWithCtx(api.GetUsersToken.Route(), &req, &resp)
if err != nil {
return "", err
Expand All @@ -67,7 +77,7 @@ func (m *MetaManager) GetToken(userID string, platformID int32) (string, error)
}

func (m *MetaManager) WithAdminToken() (err error) {
token, err := m.GetToken(config.AdminUserID, config.PlatformID)
token, err := m.GetAdminToken(config.AdminUserID, config.PlatformID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion integration_test/internal/manager/user_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (t *TestUserManager) login(ctx context.Context, userIDs ...string) error {
for _, userID := range userIDs {
userID := userID
gr.Go(func() error {
token, err := t.GetToken(userID, config.PlatformID)
token, err := t.GetAdminToken(userID, config.PlatformID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion msgtest/module/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (m *MetaManager) buildCtx() context.Context {
func (m *MetaManager) getToken(userID string, platformID int32) (string, error) {
req := authPB.UserTokenReq{PlatformID: platformID, UserID: userID, Secret: m.secret}
resp := authPB.UserTokenResp{}
err := m.postWithCtx(api.GetUsersToken.Route(), &req, &resp)
err := m.postWithCtx(api.UsersToken.Route(), &req, &resp)
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ var (
)

var (
GetUsersToken = newApi[auth.UserTokenReq, auth.UserTokenResp]("/auth/user_token")
UsersToken = newApi[auth.UserTokenReq, auth.UserTokenResp]("/auth/user_token")
GetUsersToken = newApi[auth.UserTokenReq, auth.UserTokenResp]("/auth/get_user_token")
)

var (
Expand Down
2 changes: 1 addition & 1 deletion test/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ func GetUserToken(ctx context.Context, userID string, platformID int32, secret s
PlatformID: platformID,
Secret: secret,
}
return api.ExtractField(ctx, api.GetUsersToken.Invoke, req, (*auth.UserTokenResp).GetToken)
return api.ExtractField(ctx, api.UsersToken.Invoke, req, (*auth.UserTokenResp).GetToken)
}

0 comments on commit 67e43eb

Please sign in to comment.