* MM-12083: unittest using externally managed database * cherry-pick Makefile changes from @cpanato * Jenkins changes (#9915) * add docker compose * udpate * when using minio dont need to set the region * update * add wait for it script * using old minio * add new jenkins file * update makefile * add dockerfile * rename the docker-compose proj to avoid colision (#9917) * rename the docker-compose proj to avoid colision * enable debug * enable debug to double checkt the branchs and fix docker-compose name (#9919) * add ee hash to check (#9920) * fix name (#9921) * update jenkins file to push from branch and prs * if a new push comes in stop the running build * split mysql and postgres variables * add script to run jenkins-like env in local dev env * update docker-compose project name to use uuid to make it more randon * fix DCNAME definition * update elasticsearch docker image * revert test * tidy up stages, and wait for mysql differently * update docker image and add check for postgres * checking if is ready * update docker compose to have a wait for deps * add readme and rename dockerfile * fix -unittest setup * using mm docker image * restore parallel unit tests at the package level Spin up a dedicated database for each package under test to avoid races in accessing the same tables. Simplify the interface for configuring the test database to just a DSN instead of multiple exports for each field. * try to work around root mysql access in CI * update local-test-env.sh too * MYSQL_ROOT_HOST: % * fix missing quotes * setting some memory limits for mysql * revert memory docker compose does not support * fix env name for postgres * expose errors in app/export_test.go * fix test label, better error checking on teardown * increase query timeout for tests * fix export_test * update local dev script * add configurable mysql root passwd
174 строки
5.2 KiB
Go
174 строки
5.2 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestReactionsOfPost(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
|
|
post := th.BasicPost
|
|
post.HasReactions = true
|
|
|
|
reactionObject := model.Reaction{
|
|
UserId: model.NewId(),
|
|
PostId: post.Id,
|
|
EmojiName: "emoji",
|
|
CreateAt: model.GetMillis(),
|
|
}
|
|
|
|
th.App.SaveReactionForPost(&reactionObject)
|
|
reactionsOfPost, err := th.App.BuildPostReactions(post.Id)
|
|
|
|
if err != nil {
|
|
t.Fatal("should have reactions")
|
|
}
|
|
|
|
assert.Equal(t, reactionObject.EmojiName, *(*reactionsOfPost)[0].EmojiName)
|
|
}
|
|
|
|
func TestExportUserNotifyProps(t *testing.T) {
|
|
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
|
|
userNotifyProps := model.StringMap{
|
|
model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL,
|
|
model.DESKTOP_SOUND_NOTIFY_PROP: "true",
|
|
model.EMAIL_NOTIFY_PROP: "true",
|
|
model.MOBILE_NOTIFY_PROP: model.USER_NOTIFY_ALL,
|
|
model.MOBILE_PUSH_STATUS_NOTIFY_PROP: model.STATUS_ONLINE,
|
|
model.CHANNEL_MENTIONS_NOTIFY_PROP: "true",
|
|
model.COMMENTS_NOTIFY_PROP: model.COMMENTS_NOTIFY_ROOT,
|
|
model.MENTION_KEYS_NOTIFY_PROP: "valid,misc",
|
|
}
|
|
|
|
exportNotifyProps := th.App.buildUserNotifyProps(userNotifyProps)
|
|
|
|
require.Equal(t, userNotifyProps[model.DESKTOP_NOTIFY_PROP], *exportNotifyProps.Desktop)
|
|
require.Equal(t, userNotifyProps[model.DESKTOP_SOUND_NOTIFY_PROP], *exportNotifyProps.DesktopSound)
|
|
require.Equal(t, userNotifyProps[model.EMAIL_NOTIFY_PROP], *exportNotifyProps.Email)
|
|
require.Equal(t, userNotifyProps[model.MOBILE_NOTIFY_PROP], *exportNotifyProps.Mobile)
|
|
require.Equal(t, userNotifyProps[model.MOBILE_PUSH_STATUS_NOTIFY_PROP], *exportNotifyProps.MobilePushStatus)
|
|
require.Equal(t, userNotifyProps[model.CHANNEL_MENTIONS_NOTIFY_PROP], *exportNotifyProps.ChannelTrigger)
|
|
require.Equal(t, userNotifyProps[model.COMMENTS_NOTIFY_PROP], *exportNotifyProps.CommentsTrigger)
|
|
require.Equal(t, userNotifyProps[model.MENTION_KEYS_NOTIFY_PROP], *exportNotifyProps.MentionKeys)
|
|
}
|
|
|
|
func TestExportUserChannels(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
channel := th.BasicChannel
|
|
user := th.BasicUser
|
|
team := th.BasicTeam
|
|
channelName := channel.Name
|
|
notifyProps := model.StringMap{
|
|
model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL,
|
|
model.PUSH_NOTIFY_PROP: model.USER_NOTIFY_NONE,
|
|
}
|
|
preference := model.Preference{
|
|
UserId: user.Id,
|
|
Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL,
|
|
Name: channel.Id,
|
|
Value: "true",
|
|
}
|
|
var preferences model.Preferences
|
|
preferences = append(preferences, preference)
|
|
channelMember := model.ChannelMember{
|
|
ChannelId: channel.Id,
|
|
UserId: user.Id,
|
|
}
|
|
th.App.Srv.Store.Channel().SaveMember(&channelMember)
|
|
th.App.Srv.Store.Preference().Save(&preferences)
|
|
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
|
|
exportData, err := th.App.buildUserChannelMemberships(user.Id, team.Id)
|
|
require.Nil(t, err)
|
|
assert.Equal(t, len(*exportData), 3)
|
|
for _, data := range *exportData {
|
|
if *data.Name == channelName {
|
|
assert.Equal(t, *data.NotifyProps.Desktop, "all")
|
|
assert.Equal(t, *data.NotifyProps.Mobile, "none")
|
|
assert.Equal(t, *data.NotifyProps.MarkUnread, "all") // default value
|
|
assert.True(t, *data.Favorite)
|
|
} else { // default values
|
|
assert.Equal(t, *data.NotifyProps.Desktop, "default")
|
|
assert.Equal(t, *data.NotifyProps.Mobile, "default")
|
|
assert.Equal(t, *data.NotifyProps.MarkUnread, "all")
|
|
assert.False(t, *data.Favorite)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDirCreationForEmoji(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
|
|
pathToDir := th.App.createDirForEmoji("test.json", "exported_emoji_test")
|
|
defer os.Remove(pathToDir)
|
|
if _, err := os.Stat(pathToDir); os.IsNotExist(err) {
|
|
t.Fatal("Directory exported_emoji_test should exist")
|
|
}
|
|
}
|
|
|
|
func TestCopyEmojiImages(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
|
|
emoji := &model.Emoji{
|
|
Id: th.BasicUser.Id,
|
|
}
|
|
|
|
// Creating a dir named `exported_emoji_test` in the root of the repo
|
|
pathToDir := "../exported_emoji_test"
|
|
|
|
os.Mkdir(pathToDir, 0777)
|
|
defer os.RemoveAll(pathToDir)
|
|
|
|
filePath := "../data/emoji/" + emoji.Id
|
|
emojiImagePath := filePath + "/image"
|
|
|
|
var _, err = os.Stat(filePath)
|
|
if os.IsNotExist(err) {
|
|
os.MkdirAll(filePath, 0777)
|
|
}
|
|
|
|
// Creating a file with the name `image` to copy it to `exported_emoji_test`
|
|
os.OpenFile(filePath+"/image", os.O_RDONLY|os.O_CREATE, 0777)
|
|
defer os.RemoveAll(filePath)
|
|
|
|
copyError := th.App.copyEmojiImages(emoji.Id, emojiImagePath, pathToDir)
|
|
if copyError != nil {
|
|
t.Fatal(copyError)
|
|
}
|
|
|
|
if _, err := os.Stat(pathToDir + "/" + emoji.Id + "/image"); os.IsNotExist(err) {
|
|
t.Fatal("File should exist ", err)
|
|
}
|
|
}
|
|
|
|
func TestExportCustomEmoji(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
|
|
filePath := "../demo.json"
|
|
|
|
fileWriter, err := os.Create(filePath)
|
|
require.Nil(t, err)
|
|
defer os.Remove(filePath)
|
|
|
|
pathToEmojiDir := "../data/emoji/"
|
|
dirNameToExportEmoji := "exported_emoji_test"
|
|
defer os.RemoveAll("../" + dirNameToExportEmoji)
|
|
|
|
if err := th.App.ExportCustomEmoji(fileWriter, filePath, pathToEmojiDir, dirNameToExportEmoji); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|