diff options
Diffstat (limited to 'cmd/mattermost')
-rw-r--r-- | cmd/mattermost/commands/roles_test.go | 4 | ||||
-rw-r--r-- | cmd/mattermost/commands/sampledata.go | 29 | ||||
-rw-r--r-- | cmd/mattermost/commands/user_test.go | 8 |
3 files changed, 27 insertions, 14 deletions
diff --git a/cmd/mattermost/commands/roles_test.go b/cmd/mattermost/commands/roles_test.go index 4f11ce7ed..da33a73cc 100644 --- a/cmd/mattermost/commands/roles_test.go +++ b/cmd/mattermost/commands/roles_test.go @@ -17,7 +17,7 @@ func TestAssignRole(t *testing.T) { CheckCommand(t, "roles", "system_admin", th.BasicUser.Email) if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) if user.Roles != "system_user system_admin" { @@ -28,7 +28,7 @@ func TestAssignRole(t *testing.T) { CheckCommand(t, "roles", "member", th.BasicUser.Email) if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) if user.Roles != "system_user" { diff --git a/cmd/mattermost/commands/sampledata.go b/cmd/mattermost/commands/sampledata.go index 0983ab0df..ed550bf6b 100644 --- a/cmd/mattermost/commands/sampledata.go +++ b/cmd/mattermost/commands/sampledata.go @@ -59,6 +59,15 @@ func randomPastTime(seconds int) int64 { return (today.Unix() * 1000) - int64(rand.Intn(seconds*1000)) } +func sortedRandomDates(size int) []int64 { + dates := make([]int64, size) + for i := 0; i < size; i++ { + dates[i] = randomPastTime(50000) + } + sort.Slice(dates, func(a, b int) bool { return dates[a] < dates[b] }) + return dates +} + func randomEmoji() string { emojis := []string{"+1", "-1", "heart", "blush"} return emojis[rand.Intn(len(emojis))] @@ -274,8 +283,10 @@ func sampleDataCmdF(command *cobra.Command, args []string) error { for team, channels := range teamsAndChannels { for _, channel := range channels { + dates := sortedRandomDates(postsPerChannel) + for i := 0; i < postsPerChannel; i++ { - postLine := createPost(team, channel, allUsers) + postLine := createPost(team, channel, allUsers, dates[i]) encoder.Encode(postLine) } } @@ -286,8 +297,10 @@ func sampleDataCmdF(command *cobra.Command, args []string) error { user2 := allUsers[rand.Intn(len(allUsers))] channelLine := createDirectChannel([]string{user1, user2}) encoder.Encode(channelLine) + + dates := sortedRandomDates(postsPerDirectChannel) for j := 0; j < postsPerDirectChannel; j++ { - postLine := createDirectPost([]string{user1, user2}) + postLine := createDirectPost([]string{user1, user2}, dates[j]) encoder.Encode(postLine) } } @@ -303,8 +316,10 @@ func sampleDataCmdF(command *cobra.Command, args []string) error { } channelLine := createDirectChannel(users) encoder.Encode(channelLine) + + dates := sortedRandomDates(postsPerGroupChannel) for j := 0; j < postsPerGroupChannel; j++ { - postLine := createDirectPost(users) + postLine := createDirectPost(users, dates[j]) encoder.Encode(postLine) } } @@ -529,9 +544,9 @@ func createChannel(idx int, teamName string) app.LineImportData { } } -func createPost(team string, channel string, allUsers []string) app.LineImportData { +func createPost(team string, channel string, allUsers []string, createAt int64) app.LineImportData { message := randomMessage(allUsers) - create_at := randomPastTime(50000) + create_at := createAt user := allUsers[rand.Intn(len(allUsers))] // Some messages are flagged by an user @@ -589,9 +604,9 @@ func createDirectChannel(members []string) app.LineImportData { } } -func createDirectPost(members []string) app.LineImportData { +func createDirectPost(members []string, createAt int64) app.LineImportData { message := randomMessage(members) - create_at := randomPastTime(50000) + create_at := createAt user := members[rand.Intn(len(members))] // Some messages are flagged by an user diff --git a/cmd/mattermost/commands/user_test.go b/cmd/mattermost/commands/user_test.go index 69ca9ecb8..088893602 100644 --- a/cmd/mattermost/commands/user_test.go +++ b/cmd/mattermost/commands/user_test.go @@ -50,12 +50,10 @@ func TestCreateUserWithoutTeam(t *testing.T) { CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username) if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) - if user.Email != email { - t.Fatal() - } + require.Equal(t, email, user.Email) } } @@ -92,7 +90,7 @@ func TestChangeUserEmail(t *testing.T) { t.Fatal("should've updated to the new email") } if result := <-th.App.Srv.Store.User().GetByEmail(newEmail); result.Err != nil { - t.Fatal() + t.Fatal(result.Err) } else { user := result.Data.(*model.User) if user.Email != newEmail { |