Implementation of expectation tests (#14191)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f79b7567b1
Коммит
9853056b7a
@@ -4,14 +4,10 @@
|
||||
package searchtest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -28,9 +24,11 @@ type SearchTestEngine struct {
|
||||
}
|
||||
|
||||
type searchTest struct {
|
||||
Name string
|
||||
Fn func(*testing.T, store.Store)
|
||||
Tags []string
|
||||
Name string
|
||||
Fn func(*testing.T, *SearchTestHelper)
|
||||
Tags []string
|
||||
Skip bool
|
||||
SkipMessage string
|
||||
}
|
||||
|
||||
func filterTestsByTag(tests []searchTest, tags ...string) []searchTest {
|
||||
@@ -51,130 +49,29 @@ func filterTestsByTag(tests []searchTest, tags ...string) []searchTest {
|
||||
return filteredTests
|
||||
}
|
||||
|
||||
func runTestSearch(t *testing.T, s store.Store, testEngine *SearchTestEngine, tests []searchTest) {
|
||||
func runTestSearch(t *testing.T, testEngine *SearchTestEngine, tests []searchTest, th *SearchTestHelper) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping advanced search test")
|
||||
return
|
||||
}
|
||||
|
||||
filteredTests := filterTestsByTag(tests, testEngine.Driver)
|
||||
|
||||
for _, test := range filteredTests {
|
||||
test := test
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping advanced search test")
|
||||
|
||||
if test.Skip {
|
||||
t.Log("SKIPPED: " + test.Name + ". Reason: " + test.SkipMessage)
|
||||
continue
|
||||
}
|
||||
|
||||
if testEngine.BeforeTest != nil {
|
||||
testEngine.BeforeTest(t, s)
|
||||
testEngine.BeforeTest(t, th.Store)
|
||||
}
|
||||
t.Run(test.Name, func(t *testing.T) { test.Fn(t, s) })
|
||||
testName := test.Name
|
||||
testFn := test.Fn
|
||||
t.Run(testName, func(t *testing.T) { testFn(t, th) })
|
||||
if testEngine.AfterTest != nil {
|
||||
testEngine.AfterTest(t, s)
|
||||
testEngine.AfterTest(t, th.Store)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func makeEmail() string {
|
||||
return "success_" + model.NewId() + "@simulator.amazonses.com"
|
||||
}
|
||||
|
||||
func assertUsersMatchInAnyOrder(t *testing.T, expected, actual []*model.User) {
|
||||
expectedUsernames := make([]string, 0, len(expected))
|
||||
for _, user := range expected {
|
||||
expectedUsernames = append(expectedUsernames, user.Username)
|
||||
}
|
||||
|
||||
actualUsernames := make([]string, 0, len(actual))
|
||||
for _, user := range actual {
|
||||
actualUsernames = append(actualUsernames, user.Username)
|
||||
}
|
||||
|
||||
if assert.ElementsMatch(t, expectedUsernames, actualUsernames) {
|
||||
assert.ElementsMatch(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func createUser(username, nickname, firstName, lastName string) *model.User {
|
||||
user := &model.User{
|
||||
Username: username,
|
||||
Password: username,
|
||||
Nickname: nickname,
|
||||
FirstName: firstName,
|
||||
LastName: lastName,
|
||||
Email: makeEmail(),
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
func createPost(userId string, channelId string, message string) *model.Post {
|
||||
post := &model.Post{
|
||||
Message: message,
|
||||
ChannelId: channelId,
|
||||
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
||||
UserId: userId,
|
||||
CreateAt: 1000000,
|
||||
}
|
||||
|
||||
return post
|
||||
}
|
||||
|
||||
func addUserToTeamsAndChannels(s store.Store, user *model.User, teamIds []string, channelIds []string) error {
|
||||
for _, teamId := range teamIds {
|
||||
_, err := s.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: user.Id}, -1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, channelId := range channelIds {
|
||||
_, err := s.Channel().SaveMember(&model.ChannelMember{ChannelId: channelId, UserId: user.Id, NotifyProps: model.GetDefaultChannelNotifyProps()})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkPostInSearchResults(t *testing.T, postId string, searchResults []string) {
|
||||
t.Helper()
|
||||
assert.Contains(t, searchResults, postId, "Did not find expected post in search results.")
|
||||
}
|
||||
|
||||
func checkPostNotInSearchResults(t *testing.T, postId string, searchResults []string) {
|
||||
t.Helper()
|
||||
assert.NotContains(t, searchResults, postId, "Found post in search results that should not be there.")
|
||||
}
|
||||
|
||||
func checkMatchesEqual(t *testing.T, expected model.PostSearchMatches, actual map[string][]string) {
|
||||
a := assert.New(t)
|
||||
|
||||
a.Len(actual, len(expected), "Received matches for a different number of posts")
|
||||
|
||||
for postId, expectedMatches := range expected {
|
||||
a.ElementsMatch(expectedMatches, actual[postId], fmt.Sprintf("%v: expected %v, got %v", postId, expectedMatches, actual[postId]))
|
||||
}
|
||||
}
|
||||
|
||||
func createPostWithHashtags(userId string, channelId string, message string, hashtags string) *model.Post {
|
||||
post := &model.Post{
|
||||
Message: message,
|
||||
ChannelId: channelId,
|
||||
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
||||
UserId: userId,
|
||||
CreateAt: 1000000,
|
||||
Hashtags: hashtags,
|
||||
}
|
||||
|
||||
return post
|
||||
}
|
||||
|
||||
func createPostAtTime(userId string, channelId string, message string, createAt int64) *model.Post {
|
||||
post := &model.Post{
|
||||
Message: message,
|
||||
ChannelId: channelId,
|
||||
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
||||
UserId: userId,
|
||||
CreateAt: createAt,
|
||||
}
|
||||
|
||||
return post
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user