MM-27412 Fixing /test command. (#15155)
* Fixing /test command. * Add error handling to channels command. * Switch to using app instead of client in some places. * Fix lint being confused. * Join channels automatically. Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fb453d578f
Коммит
a22f02c867
@@ -9,7 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AutoChannelCreator struct {
|
type AutoChannelCreator struct {
|
||||||
client *model.Client4
|
a *App
|
||||||
|
userId string
|
||||||
team *model.Team
|
team *model.Team
|
||||||
Fuzzy bool
|
Fuzzy bool
|
||||||
DisplayNameLen utils.Range
|
DisplayNameLen utils.Range
|
||||||
@@ -19,10 +20,11 @@ type AutoChannelCreator struct {
|
|||||||
ChannelType string
|
ChannelType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAutoChannelCreator(client *model.Client4, team *model.Team) *AutoChannelCreator {
|
func NewAutoChannelCreator(a *App, team *model.Team, userId string) *AutoChannelCreator {
|
||||||
return &AutoChannelCreator{
|
return &AutoChannelCreator{
|
||||||
client: client,
|
a: a,
|
||||||
team: team,
|
team: team,
|
||||||
|
userId: userId,
|
||||||
Fuzzy: false,
|
Fuzzy: false,
|
||||||
DisplayNameLen: CHANNEL_DISPLAY_NAME_LEN,
|
DisplayNameLen: CHANNEL_DISPLAY_NAME_LEN,
|
||||||
DisplayNameCharset: utils.ALPHANUMERIC,
|
DisplayNameCharset: utils.ALPHANUMERIC,
|
||||||
@@ -45,12 +47,13 @@ func (cfg *AutoChannelCreator) createRandomChannel() (*model.Channel, error) {
|
|||||||
TeamId: cfg.team.Id,
|
TeamId: cfg.team.Id,
|
||||||
DisplayName: displayName,
|
DisplayName: displayName,
|
||||||
Name: name,
|
Name: name,
|
||||||
Type: cfg.ChannelType}
|
Type: cfg.ChannelType,
|
||||||
|
CreatorId: cfg.userId,
|
||||||
|
}
|
||||||
|
|
||||||
println(cfg.client.GetTeamRoute(cfg.team.Id))
|
channel, err := cfg.a.CreateChannel(channel, true)
|
||||||
channel, resp := cfg.client.CreateChannel(channel)
|
if err != nil {
|
||||||
if resp.Error != nil {
|
return nil, err
|
||||||
return nil, resp.Error
|
|
||||||
}
|
}
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func CreateTestEnvironmentInTeam(a *App, client *model.Client4, team *model.Team
|
|||||||
usernames[i] = user.Username
|
usernames[i] = user.Username
|
||||||
}
|
}
|
||||||
|
|
||||||
channelCreator := NewAutoChannelCreator(client, team)
|
channelCreator := NewAutoChannelCreator(a, team, users[0].Id)
|
||||||
channelCreator.Fuzzy = fuzzy
|
channelCreator.Fuzzy = fuzzy
|
||||||
channels, err := channelCreator.CreateTestChannels(rangeChannels)
|
channels, err := channelCreator.CreateTestChannels(rangeChannels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -97,7 +97,7 @@ func CreateTestEnvironmentInTeam(a *App, client *model.Client4, team *model.Team
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, channel := range channels {
|
for i, channel := range channels {
|
||||||
postCreator := NewAutoPostCreator(client, channel.Id)
|
postCreator := NewAutoPostCreator(a, channel.Id, user.Id)
|
||||||
postCreator.HasImage = i < numImages
|
postCreator.HasImage = i < numImages
|
||||||
postCreator.Users = usernames
|
postCreator.Users = usernames
|
||||||
postCreator.Fuzzy = fuzzy
|
postCreator.Fuzzy = fuzzy
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AutoPostCreator struct {
|
type AutoPostCreator struct {
|
||||||
client *model.Client4
|
a *App
|
||||||
channelid string
|
channelid string
|
||||||
|
userid string
|
||||||
Fuzzy bool
|
Fuzzy bool
|
||||||
TextLength utils.Range
|
TextLength utils.Range
|
||||||
HasImage bool
|
HasImage bool
|
||||||
@@ -27,10 +28,11 @@ type AutoPostCreator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Automatic poster used for testing
|
// Automatic poster used for testing
|
||||||
func NewAutoPostCreator(client *model.Client4, channelid string) *AutoPostCreator {
|
func NewAutoPostCreator(a *App, channelid, userid string) *AutoPostCreator {
|
||||||
return &AutoPostCreator{
|
return &AutoPostCreator{
|
||||||
client: client,
|
a: a,
|
||||||
channelid: channelid,
|
channelid: channelid,
|
||||||
|
userid: userid,
|
||||||
Fuzzy: false,
|
Fuzzy: false,
|
||||||
TextLength: utils.Range{Begin: 100, End: 200},
|
TextLength: utils.Range{Begin: 100, End: 200},
|
||||||
HasImage: false,
|
HasImage: false,
|
||||||
@@ -57,12 +59,12 @@ func (cfg *AutoPostCreator) UploadTestFile() ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fileResp, resp := cfg.client.UploadFile(data.Bytes(), cfg.channelid, filename)
|
fileResp, err2 := cfg.a.UploadFile(data.Bytes(), cfg.channelid, filename)
|
||||||
if resp.Error != nil {
|
if err2 != nil {
|
||||||
return nil, resp.Error
|
return nil, err2
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{fileResp.FileInfos[0].Id}, nil
|
return []string{fileResp.Id}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *AutoPostCreator) CreateRandomPost() (*model.Post, error) {
|
func (cfg *AutoPostCreator) CreateRandomPost() (*model.Post, error) {
|
||||||
@@ -88,13 +90,15 @@ func (cfg *AutoPostCreator) CreateRandomPostNested(parentId, rootId string) (*mo
|
|||||||
|
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
ChannelId: cfg.channelid,
|
ChannelId: cfg.channelid,
|
||||||
|
UserId: cfg.userid,
|
||||||
ParentId: parentId,
|
ParentId: parentId,
|
||||||
RootId: rootId,
|
RootId: rootId,
|
||||||
Message: postText,
|
Message: postText,
|
||||||
FileIds: fileIds}
|
FileIds: fileIds,
|
||||||
rpost, resp := cfg.client.CreatePost(post)
|
}
|
||||||
if resp.Error != nil {
|
rpost, err := cfg.a.CreatePostMissingChannel(post, true)
|
||||||
return nil, resp.Error
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return rpost, nil
|
return rpost, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,11 +207,6 @@ func (me *LoadTestProvider) SetupCommand(a *App, args *model.CommandArgs, messag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
client := model.NewAPIv4Client(args.SiteURL)
|
client := model.NewAPIv4Client(args.SiteURL)
|
||||||
sessions, err := a.GetSessions(args.UserId)
|
|
||||||
if err != nil || len(sessions) == 0 {
|
|
||||||
return &model.CommandResponse{Text: "Failed to get sessions.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
|
||||||
}
|
|
||||||
client.SetToken(sessions[0].Token)
|
|
||||||
|
|
||||||
if doTeams {
|
if doTeams {
|
||||||
if err := a.CreateBasicUser(client); err != nil {
|
if err := a.CreateBasicUser(client); err != nil {
|
||||||
@@ -321,15 +316,11 @@ func (me *LoadTestProvider) ChannelsCommand(a *App, args *model.CommandArgs, mes
|
|||||||
return &model.CommandResponse{Text: "Failed to add channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
return &model.CommandResponse{Text: "Failed to add channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := model.NewAPIv4Client(args.SiteURL)
|
channelCreator := NewAutoChannelCreator(a, team, args.UserId)
|
||||||
sessions, err := a.GetSessions(args.UserId)
|
|
||||||
if err != nil || len(sessions) == 0 {
|
|
||||||
return &model.CommandResponse{Text: "Failed to get sessions.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
|
||||||
}
|
|
||||||
client.SetToken(sessions[0].Token)
|
|
||||||
channelCreator := NewAutoChannelCreator(client, team)
|
|
||||||
channelCreator.Fuzzy = doFuzz
|
channelCreator.Fuzzy = doFuzz
|
||||||
channelCreator.CreateTestChannels(channelsr)
|
if _, err := channelCreator.CreateTestChannels(channelsr); err != nil {
|
||||||
|
return &model.CommandResponse{Text: "Failed to create test channels: " + err.Error(), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
||||||
|
}
|
||||||
|
|
||||||
return &model.CommandResponse{Text: "Added channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
|
return &model.CommandResponse{Text: "Added channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
|
||||||
}
|
}
|
||||||
@@ -346,18 +337,12 @@ func (me *LoadTestProvider) ThreadedPostCommand(a *App, args *model.CommandArgs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client := model.NewAPIv4Client(args.SiteURL)
|
testPoster := NewAutoPostCreator(a, args.ChannelId, args.UserId)
|
||||||
sessions, err := a.GetSessions(args.UserId)
|
|
||||||
if err != nil || len(sessions) == 0 {
|
|
||||||
return &model.CommandResponse{Text: "Failed to get sessions.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
|
||||||
}
|
|
||||||
client.MockSession(sessions[0].Token)
|
|
||||||
testPoster := NewAutoPostCreator(client, args.ChannelId)
|
|
||||||
testPoster.Fuzzy = true
|
testPoster.Fuzzy = true
|
||||||
testPoster.Users = usernames
|
testPoster.Users = usernames
|
||||||
rpost, err2 := testPoster.CreateRandomPost()
|
rpost, err2 := testPoster.CreateRandomPost()
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return &model.CommandResponse{Text: "Failed to create a post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
return &model.CommandResponse{Text: "Failed to create a post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err2
|
||||||
}
|
}
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
testPoster.CreateRandomPostNested(rpost.Id, rpost.Id)
|
testPoster.CreateRandomPostNested(rpost.Id, rpost.Id)
|
||||||
@@ -399,13 +384,7 @@ func (me *LoadTestProvider) PostsCommand(a *App, args *model.CommandArgs, messag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client := model.NewAPIv4Client(args.SiteURL)
|
testPoster := NewAutoPostCreator(a, args.ChannelId, args.UserId)
|
||||||
sessions, err := a.GetSessions(args.UserId)
|
|
||||||
if err != nil || len(sessions) == 0 {
|
|
||||||
return &model.CommandResponse{Text: "Failed to get sessions.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
|
|
||||||
}
|
|
||||||
client.SetToken(sessions[0].Token)
|
|
||||||
testPoster := NewAutoPostCreator(client, args.ChannelId)
|
|
||||||
testPoster.Fuzzy = doFuzz
|
testPoster.Fuzzy = doFuzz
|
||||||
testPoster.Users = usernames
|
testPoster.Users = usernames
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user