[MM-49989] Pass a context.Context to Client4 methods (#22922)
* Migrate all method in model/client4.go to accept a context.Context * Fix th.*Client * Fix remaining issues * Empty commit to triger CI * Fix test * Add cancellation test * Test that returned error is context.Canceled * Fix bad merge * Update mmctl code --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7116e9267a
Коммит
6c82605df0
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@@ -37,7 +38,7 @@ func CreateTestEnvironmentWithTeams(a *app.App, c request.CTX, client *model.Cli
|
||||
if err != nil {
|
||||
return TestEnvironment{}, err
|
||||
}
|
||||
client.LoginById(randomUser.Id, UserPassword)
|
||||
client.LoginById(context.Background(), randomUser.Id, UserPassword)
|
||||
teamEnvironment, err := CreateTestEnvironmentInTeam(a, c, client, team, rangeChannels, rangeUsers, rangePosts, fuzzy)
|
||||
if err != nil {
|
||||
return TestEnvironment{}, err
|
||||
@@ -77,12 +78,12 @@ func CreateTestEnvironmentInTeam(a *app.App, c request.CTX, client *model.Client
|
||||
// Have every user join every channel
|
||||
for _, user := range users {
|
||||
for _, channel := range channels {
|
||||
_, _, err := client.LoginById(user.Id, UserPassword)
|
||||
_, _, err := client.LoginById(context.Background(), user.Id, UserPassword)
|
||||
if err != nil {
|
||||
return TeamEnvironment{}, err
|
||||
}
|
||||
|
||||
_, _, err = client.AddChannelMember(channel.Id, user.Id)
|
||||
_, _, err = client.AddChannelMember(context.Background(), channel.Id, user.Id)
|
||||
if err != nil {
|
||||
return TeamEnvironment{}, err
|
||||
}
|
||||
@@ -93,7 +94,7 @@ func CreateTestEnvironmentInTeam(a *app.App, c request.CTX, client *model.Client
|
||||
numImages := utils.RandIntFromRange(rangePosts) / 4
|
||||
for j := 0; j < numPosts; j++ {
|
||||
user := users[utils.RandIntFromRange(utils.Range{Begin: 0, End: len(users) - 1})]
|
||||
_, _, err := client.LoginById(user.Id, UserPassword)
|
||||
_, _, err := client.LoginById(context.Background(), user.Id, UserPassword)
|
||||
if err != nil {
|
||||
return TeamEnvironment{}, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
"github.com/mattermost/mattermost-server/server/v8/channels/utils"
|
||||
)
|
||||
@@ -57,7 +59,7 @@ func (cfg *AutoTeamCreator) createRandomTeam() (*model.Team, error) {
|
||||
Type: model.TeamOpen,
|
||||
}
|
||||
|
||||
createdTeam, _, err := cfg.client.CreateTeam(team)
|
||||
createdTeam, _, err := cfg.client.CreateTeam(context.Background(), team)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
@@ -42,18 +43,18 @@ func NewAutoUserCreator(a *app.App, client *model.Client4, team *model.Team) *Au
|
||||
|
||||
// Basic test team and user so you always know one
|
||||
func CreateBasicUser(a *app.App, client *model.Client4) error {
|
||||
found, _, _ := client.TeamExists(BTestTeamName, "")
|
||||
found, _, _ := client.TeamExists(context.Background(), BTestTeamName, "")
|
||||
if found {
|
||||
return nil
|
||||
}
|
||||
|
||||
newteam := &model.Team{DisplayName: BTestTeamDisplayName, Name: BTestTeamName, Email: BTestTeamEmail, Type: BTestTeamType}
|
||||
basicteam, _, err := client.CreateTeam(newteam)
|
||||
basicteam, _, err := client.CreateTeam(context.Background(), newteam)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newuser := &model.User{Email: BTestUserEmail, Nickname: BTestUserName, Password: BTestUserPassword}
|
||||
ruser, _, err := client.CreateUser(newuser)
|
||||
ruser, _, err := client.CreateUser(context.Background(), newuser)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -248,7 +249,7 @@ func (*LoadTestProvider) SetupCommand(a *app.App, c request.CTX, args *model.Com
|
||||
if err := CreateBasicUser(a, client); err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
}
|
||||
_, _, err := client.Login(BTestUserEmail, BTestUserPassword)
|
||||
_, _, err := client.Login(context.Background(), BTestUserEmail, BTestUserPassword)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
}
|
||||
@@ -604,7 +605,7 @@ func (*LoadTestProvider) PostCommand(a *app.App, c request.CTX, args *model.Comm
|
||||
}
|
||||
|
||||
client := model.NewAPIv4Client(args.SiteURL)
|
||||
_, _, nErr := client.LoginById(user.Id, passwd)
|
||||
_, _, nErr := client.LoginById(context.Background(), user.Id, passwd)
|
||||
if nErr != nil {
|
||||
return &model.CommandResponse{Text: "Failed to login a user", ResponseType: model.CommandResponseTypeEphemeral}, nErr
|
||||
}
|
||||
@@ -613,7 +614,7 @@ func (*LoadTestProvider) PostCommand(a *app.App, c request.CTX, args *model.Comm
|
||||
ChannelId: channel.Id,
|
||||
Message: textMessage,
|
||||
}
|
||||
_, _, nErr = client.CreatePost(post)
|
||||
_, _, nErr = client.CreatePost(context.Background(), post)
|
||||
if nErr != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create a post", ResponseType: model.CommandResponseTypeEphemeral}, nErr
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user