From 6e6a44764cafdfbe71baf8eb181dc85ffa12ea67 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Wed, 4 Dec 2019 11:31:52 -0500 Subject: [PATCH] [MM-19892] Fix failing test TestImportBulkImport (#13003) Automatic Merge --- api4/team_test.go | 9 ++++----- api4/websocket_test.go | 2 +- app/import_functions_test.go | 8 ++++---- app/import_test.go | 2 +- model/utils.go | 9 +++++++++ store/sqlstore/integrity_test.go | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/api4/team_test.go b/api4/team_test.go index 1861868c1f..384327dced 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -4,6 +4,7 @@ package api4 import ( + "encoding/base64" "encoding/binary" "fmt" "net/http" @@ -11,8 +12,6 @@ import ( "strings" "testing" - "encoding/base64" - "github.com/mattermost/mattermost-server/v5/app" "github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/services/mailservice" @@ -258,7 +257,7 @@ func TestUpdateTeam(t *testing.T) { defer th.TearDown() Client := th.Client - team := &model.Team{DisplayName: "Name", Description: "Some description", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} + team := &model.Team{DisplayName: "Name", Description: "Some description", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewRandomTeamName() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} team, _ = Client.CreateTeam(team) team.Description = "updated description" @@ -377,7 +376,7 @@ func TestPatchTeam(t *testing.T) { defer th.TearDown() Client := th.Client - team := &model.Team{DisplayName: "Name", Description: "Some description", CompanyName: "Some company name", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} + team := &model.Team{DisplayName: "Name", Description: "Some description", CompanyName: "Some company name", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewRandomTeamName() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} team, _ = Client.CreateTeam(team) patch := &model.TeamPatch{} @@ -465,7 +464,7 @@ func TestRegenerateTeamInviteId(t *testing.T) { defer th.TearDown() Client := th.Client - team := &model.Team{DisplayName: "Name", Description: "Some description", CompanyName: "Some company name", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} + team := &model.Team{DisplayName: "Name", Description: "Some description", CompanyName: "Some company name", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewRandomTeamName() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} team, _ = Client.CreateTeam(team) assert.NotEqual(t, team.InviteId, "") diff --git a/api4/websocket_test.go b/api4/websocket_test.go index f48f256241..5618cc1a69 100644 --- a/api4/websocket_test.go +++ b/api4/websocket_test.go @@ -265,7 +265,7 @@ func TestWebSocketStatuses(t *testing.T) { resp := <-WebSocketClient.ResponseChannel require.Equal(t, resp.Status, model.STATUS_OK, "should have responded OK to authentication challenge") - team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} + team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewRandomTeamName() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} rteam, _ := Client.CreateTeam(&team) user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} diff --git a/app/import_functions_test.go b/app/import_functions_test.go index 00cb429690..8c1ef9a864 100644 --- a/app/import_functions_test.go +++ b/app/import_functions_test.go @@ -595,7 +595,7 @@ func TestImportImportChannel(t *testing.T) { scheme2 := th.SetupChannelScheme() // Import a Team. - teamName := model.NewId() + teamName := model.NewRandomTeamName() th.App.ImportTeam(&TeamImportData{ Name: &teamName, DisplayName: ptrStr("Display Name"), @@ -862,7 +862,7 @@ func TestImportImportUser(t *testing.T) { data.Password = ptrStr("TestPassword") // Test team and channel memberships - teamName := model.NewId() + teamName := model.NewRandomTeamName() th.App.ImportTeam(&TeamImportData{ Name: &teamName, DisplayName: ptrStr("Display Name"), @@ -1570,7 +1570,7 @@ func TestImportImportPost(t *testing.T) { defer th.TearDown() // Create a Team. - teamName := model.NewId() + teamName := model.NewRandomTeamName() th.App.ImportTeam(&TeamImportData{ Name: &teamName, DisplayName: ptrStr("Display Name"), @@ -2510,7 +2510,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { defer th.TearDown() // Create a Team. - teamName := model.NewId() + teamName := model.NewRandomTeamName() th.App.ImportTeam(&TeamImportData{ Name: &teamName, DisplayName: ptrStr("Display Name"), diff --git a/app/import_test.go b/app/import_test.go index d099241bd3..c7d7fd7ea0 100644 --- a/app/import_test.go +++ b/app/import_test.go @@ -143,7 +143,7 @@ func TestImportBulkImport(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true }) - teamName := model.NewId() + teamName := model.NewRandomTeamName() channelName := model.NewId() username := model.NewId() username2 := model.NewId() diff --git a/model/utils.go b/model/utils.go index 2947603b58..ffeb5327d6 100644 --- a/model/utils.go +++ b/model/utils.go @@ -146,6 +146,15 @@ func NewId() string { return b.String() } +// NewRandomTeamName is a NewId that will be a valid team name. +func NewRandomTeamName() string { + teamName := NewId() + for IsReservedTeamName(teamName) { + teamName = NewId() + } + return teamName +} + func NewRandomString(length int) string { var b bytes.Buffer str := make([]byte, length+8) diff --git a/store/sqlstore/integrity_test.go b/store/sqlstore/integrity_test.go index 9709485c33..b6be23eb79 100644 --- a/store/sqlstore/integrity_test.go +++ b/store/sqlstore/integrity_test.go @@ -302,7 +302,7 @@ func createTeam(ss store.Store, userId string) *model.Team { m.DisplayName = "DisplayName" m.Type = model.TEAM_OPEN m.Email = "test@example.com" - m.Name = "z-z-z" + model.NewId() + "b" + m.Name = "z-z-z" + model.NewRandomTeamName() + "b" t, _ := ss.Team().Save(&m) return t }