[MM-13833] Configured unit tests to log through t.Log (#10272)

* Rerouted the unit test logs through t.Log

* resolving merge confilvts

* Update testing.go

* Update helper_test.go

* Added godocs for NewTestingLogger

* Added go docs for NewTestingLogger

* Resolving conflicts
Этот коммит содержится в:
Shreyansh Chouhan
2019-02-14 23:22:11 +05:30
коммит произвёл Jesse Hallam
родитель a6d0b73c0d
Коммит 39ceaa3e86
56 изменённых файлов: 316 добавлений и 264 удалений

Просмотреть файл

@@ -26,7 +26,7 @@ func TestAppRace(t *testing.T) {
*/
func TestUpdateConfig(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
prev := *th.App.Config().ServiceSettings.SiteURL
@@ -42,7 +42,7 @@ func TestUpdateConfig(t *testing.T) {
}
func TestDoAdvancedPermissionsMigration(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
if mainHelper.SqlSupplier == nil {
@@ -421,7 +421,7 @@ func TestDoAdvancedPermissionsMigration(t *testing.T) {
}
func TestDoEmojisPermissionsMigration(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
if mainHelper.SqlSupplier == nil {

Просмотреть файл

@@ -10,7 +10,7 @@ import (
)
func TestCheckIfRolesGrantPermission(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
cases := []struct {

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestSetAutoResponderStatus(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.CreateUser()
@@ -51,7 +51,7 @@ func TestSetAutoResponderStatus(t *testing.T) {
}
func TestDisableAutoResponder(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.CreateUser()
@@ -80,7 +80,7 @@ func TestDisableAutoResponder(t *testing.T) {
}
func TestSendAutoResponseSuccess(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.CreateUser()
@@ -117,7 +117,7 @@ func TestSendAutoResponseSuccess(t *testing.T) {
}
func TestSendAutoResponseFailure(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.CreateUser()

Просмотреть файл

@@ -17,7 +17,7 @@ import (
)
func TestPermanentDeleteChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -71,7 +71,7 @@ func TestPermanentDeleteChannel(t *testing.T) {
}
func TestMoveChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
sourceTeam := th.CreateTeam()
@@ -158,7 +158,7 @@ func TestMoveChannel(t *testing.T) {
}
func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// figure out the initial number of users in town square
@@ -184,7 +184,7 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testi
}
func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// figure out the initial number of users in off-topic
@@ -210,7 +210,7 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing
}
func TestJoinDefaultChannelsExperimentalDefaultChannels(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
basicChannel2 := th.CreateChannel(th.BasicTeam)
@@ -240,7 +240,7 @@ func TestJoinDefaultChannelsExperimentalDefaultChannels(t *testing.T) {
}
func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// creates a public channel and adds basic user to it
@@ -254,7 +254,7 @@ func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) {
}
func TestCreateChannelPrivateCreatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// creates a private channel and adds basic user to it
@@ -268,7 +268,7 @@ func TestCreateChannelPrivateCreatesChannelMemberHistoryRecord(t *testing.T) {
}
func TestUpdateChannelPrivacy(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
privateChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
@@ -283,7 +283,7 @@ func TestUpdateChannelPrivacy(t *testing.T) {
}
func TestCreateGroupChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user1 := th.CreateUser()
@@ -314,7 +314,7 @@ func TestCreateGroupChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
}
func TestCreateDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user1 := th.CreateUser()
@@ -341,7 +341,7 @@ func TestCreateDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
}
func TestGetDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user1 := th.CreateUser()
@@ -369,7 +369,7 @@ func TestGetDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
}
func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// create a user and add it to a channel
@@ -399,7 +399,7 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
}
/*func TestRemoveUserFromChannelUpdatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// a user creates a channel
@@ -422,7 +422,7 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
}*/
func TestAddChannelMemberNoUserRequestor(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// create a user and add it to a channel
@@ -463,7 +463,7 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
}
func TestAppUpdateChannelScheme(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channel := th.BasicChannel
@@ -481,7 +481,7 @@ func TestAppUpdateChannelScheme(t *testing.T) {
}
func TestFillInChannelProps(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channelPublic1, err := th.App.CreateChannel(&model.Channel{DisplayName: "Public 1", Name: "public1", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
@@ -686,7 +686,7 @@ func TestFillInChannelProps(t *testing.T) {
}
func TestRenameChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
testCases := []struct {
@@ -733,7 +733,7 @@ func TestRenameChannel(t *testing.T) {
}
func TestGetChannelMembersTimezones(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
userRequestorId := ""
@@ -770,7 +770,7 @@ func TestGetChannelMembersTimezones(t *testing.T) {
}
func TestGetPublicChannelsForTeam(t *testing.T) {
th := Setup()
th := Setup(t)
team := th.CreateTeam()
defer th.TearDown()

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestClusterDiscoveryService(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
ds := th.App.NewClusterDiscoveryService()

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestHeaderProviderDoCommand(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
hp := HeaderProvider{}

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestPurposeProviderDoCommand(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
pp := PurposeProvider{}

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestRenameProviderDoCommand(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
rp := RenameProvider{}

Просмотреть файл

@@ -42,7 +42,7 @@ func TestGroupMsgUsernames(t *testing.T) {
}
func TestGroupMsgProvider(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user3 := th.CreateUser()

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestInvitePeopleProvider(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestInviteProvider(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestJoinCommandNoChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {
@@ -33,7 +33,7 @@ func TestJoinCommandNoChannel(t *testing.T) {
}
func TestJoinCommandForExistingChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {
@@ -62,7 +62,7 @@ func TestJoinCommandForExistingChannel(t *testing.T) {
}
func TestJoinCommandWithTilde(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {
@@ -91,7 +91,7 @@ func TestJoinCommandWithTilde(t *testing.T) {
}
func TestJoinCommandPermissions(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channel2, _ := th.App.CreateChannel(&model.Channel{

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestLeaveProviderDoCommand(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
lp := LeaveProvider{}

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestMsgProvider(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
team := th.CreateTeam()

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestMuteCommandNoChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {
@@ -40,7 +40,7 @@ func TestMuteCommandNoChannel(t *testing.T) {
}
func TestMuteCommandNoArgs(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channel1 := th.BasicChannel
@@ -70,7 +70,7 @@ func TestMuteCommandNoArgs(t *testing.T) {
}
func TestMuteCommandSpecificChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {
@@ -115,7 +115,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
}
func TestMuteCommandNotMember(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {
@@ -143,7 +143,7 @@ func TestMuteCommandNotMember(t *testing.T) {
}
func TestMuteCommandNotChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {
@@ -164,7 +164,7 @@ func TestMuteCommandNotChannel(t *testing.T) {
}
func TestMuteCommandDMChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestRemoveProviderDoCommand(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
rp := RemoveProvider{}

Просмотреть файл

@@ -20,7 +20,7 @@ import (
)
func TestMoveCommand(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
sourceTeam := th.CreateTeam()
@@ -55,7 +55,7 @@ func TestMoveCommand(t *testing.T) {
}
func TestCreateCommandPost(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
post := &model.Post{
@@ -75,7 +75,7 @@ func TestCreateCommandPost(t *testing.T) {
}
func TestHandleCommandResponsePost(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
command := &model.Command{}
@@ -207,7 +207,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
}
}
func TestHandleCommandResponse(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
command := &model.Command{}
@@ -267,7 +267,7 @@ func TestHandleCommandResponse(t *testing.T) {
}
func TestDoCommandRequest(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {

Просмотреть файл

@@ -16,7 +16,7 @@ import (
)
func TestConfigListener(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
originalSiteName := th.App.Config().TeamSettings.SiteName
@@ -51,14 +51,14 @@ func TestConfigListener(t *testing.T) {
}
func TestAsymmetricSigningKey(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
assert.NotNil(t, th.App.AsymmetricSigningKey())
assert.NotEmpty(t, th.App.ClientConfig()["AsymmetricSigningPublicKey"])
}
func TestClientConfigWithComputed(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
config := th.App.ClientConfigWithComputed()
@@ -71,7 +71,7 @@ func TestClientConfigWithComputed(t *testing.T) {
}
func TestEnsureInstallationDate(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
tt := []struct {

Просмотреть файл

@@ -57,7 +57,7 @@ func TestPluginActivated(t *testing.T) {
}
func TestDiagnostics(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if testing.Short() {

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestHandleNewNotifications(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
id1 := model.NewId()
@@ -94,7 +94,7 @@ func TestHandleNewNotifications(t *testing.T) {
}
func TestCheckPendingNotifications(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
job := NewEmailBatchingJob(th.Server, 128)
@@ -202,7 +202,7 @@ func TestCheckPendingNotifications(t *testing.T) {
* Ensures that email batch interval defaults to 15 minutes for users that haven't explicitly set this preference
*/
func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
job := NewEmailBatchingJob(th.Server, 128)
@@ -240,7 +240,7 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
* Ensures that email batch interval defaults to 15 minutes if user preference is invalid
*/
func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
job := NewEmailBatchingJob(th.Server, 128)
@@ -286,7 +286,7 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
* Ensures that post contents are not included in notification email when email notification content type is set to generic
*/
func TestRenderBatchedPostGeneric(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
var post = &model.Post{}
@@ -313,7 +313,7 @@ func TestRenderBatchedPostGeneric(t *testing.T) {
* Ensures that post contents included in notification email when email notification content type is set to full
*/
func TestRenderBatchedPostFull(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
var post = &model.Post{}

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestReactionsOfPost(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
post := th.BasicPost
@@ -35,7 +35,7 @@ func TestReactionsOfPost(t *testing.T) {
func TestExportUserNotifyProps(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
userNotifyProps := model.StringMap{
@@ -62,7 +62,7 @@ func TestExportUserNotifyProps(t *testing.T) {
}
func TestExportUserChannels(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channel := th.BasicChannel
user := th.BasicUser
@@ -101,7 +101,7 @@ func TestExportUserChannels(t *testing.T) {
}
func TestDirCreationForEmoji(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
pathToDir := th.App.createDirForEmoji("test.json", "exported_emoji_test")
@@ -112,7 +112,7 @@ func TestDirCreationForEmoji(t *testing.T) {
}
func TestCopyEmojiImages(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
emoji := &model.Emoji{
@@ -148,7 +148,7 @@ func TestCopyEmojiImages(t *testing.T) {
}
func TestExportCustomEmoji(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
filePath := "../demo.json"
@@ -167,14 +167,14 @@ func TestExportCustomEmoji(t *testing.T) {
}
func TestExportAllUsers(t *testing.T) {
th1 := Setup().InitBasic()
th1 := Setup(t).InitBasic()
defer th1.TearDown()
var b bytes.Buffer
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
require.Nil(t, err)
th2 := Setup()
th2 := Setup(t)
defer th2.TearDown()
err, i := th2.App.BulkImport(&b, false, 5)
assert.Nil(t, err)

Просмотреть файл

@@ -57,7 +57,7 @@ func prepareTestImages(tb testing.TB) {
func BenchmarkUploadFile(b *testing.B) {
prepareTestImages(b)
th := Setup().InitBasic()
th := Setup(b).InitBasic()
defer th.TearDown()
// disable logging in the benchmark, as best we can
th.App.Log.SetConsoleLevel(mlog.LevelError)

Просмотреть файл

@@ -41,7 +41,7 @@ func TestGeneratePublicLinkHash(t *testing.T) {
}
func TestDoUploadFile(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
teamId := model.NewId()
@@ -108,7 +108,7 @@ func TestDoUploadFile(t *testing.T) {
}
func TestUploadFile(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
channelId := model.NewId()
@@ -132,7 +132,7 @@ func TestUploadFile(t *testing.T) {
}
func TestGetInfoForFilename(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
post := th.BasicPost
@@ -146,7 +146,7 @@ func TestGetInfoForFilename(t *testing.T) {
}
func TestFindTeamIdForFilename(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
teamId := th.App.FindTeamIdForFilename(th.BasicPost, fmt.Sprintf("/%v/%v/%v/blargh.png", th.BasicChannel.Id, th.BasicUser.Id, "someid"))
@@ -160,7 +160,7 @@ func TestFindTeamIdForFilename(t *testing.T) {
}
func TestMigrateFilenamesToFileInfos(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
post := th.BasicPost
@@ -187,7 +187,7 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) {
}
func TestCopyFileInfos(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
teamId := model.NewId()

Просмотреть файл

@@ -11,7 +11,7 @@ import (
)
func TestGetGroup(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
@@ -25,7 +25,7 @@ func TestGetGroup(t *testing.T) {
}
func TestGetGroupByRemoteID(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
@@ -39,7 +39,7 @@ func TestGetGroupByRemoteID(t *testing.T) {
}
func TestGetGroupsByType(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.CreateGroup()
th.CreateGroup()
@@ -55,7 +55,7 @@ func TestGetGroupsByType(t *testing.T) {
}
func TestCreateGroup(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
id := model.NewId()
@@ -76,7 +76,7 @@ func TestCreateGroup(t *testing.T) {
}
func TestUpdateGroup(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
group.DisplayName = model.NewId()
@@ -87,7 +87,7 @@ func TestUpdateGroup(t *testing.T) {
}
func TestDeleteGroup(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
@@ -101,7 +101,7 @@ func TestDeleteGroup(t *testing.T) {
}
func TestCreateOrRestoreGroupMember(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
@@ -115,7 +115,7 @@ func TestCreateOrRestoreGroupMember(t *testing.T) {
}
func TestDeleteGroupMember(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
groupMember, err := th.App.CreateOrRestoreGroupMember(group.Id, th.BasicUser.Id)
@@ -132,7 +132,7 @@ func TestDeleteGroupMember(t *testing.T) {
}
func TestCreateGroupSyncable(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
groupSyncable := &model.GroupSyncable{
@@ -153,7 +153,7 @@ func TestCreateGroupSyncable(t *testing.T) {
}
func TestGetGroupSyncable(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
groupSyncable := &model.GroupSyncable{
@@ -174,7 +174,7 @@ func TestGetGroupSyncable(t *testing.T) {
}
func TestGetGroupSyncables(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
@@ -198,7 +198,7 @@ func TestGetGroupSyncables(t *testing.T) {
}
func TestDeleteGroupSyncable(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
group := th.CreateGroup()
groupChannel := &model.GroupSyncable{

Просмотреть файл

@@ -33,7 +33,7 @@ type TestHelper struct {
tempWorkspace string
}
func setupTestHelper(enterprise bool) *TestHelper {
func setupTestHelper(enterprise bool, tb testing.TB) *TestHelper {
mainHelper.Store.DropAllTables()
permConfig, err := os.Open(fileutils.FindConfigFile("config.json"))
@@ -53,6 +53,7 @@ func setupTestHelper(enterprise bool) *TestHelper {
options := []Option{ConfigFile(tempConfig.Name(), false)}
options = append(options, StoreOverride(mainHelper.Store))
options = append(options, SetLogger(mlog.NewTestingLogger(tb)))
s, err := NewServer(options...)
if err != nil {
@@ -102,12 +103,12 @@ func setupTestHelper(enterprise bool) *TestHelper {
return th
}
func SetupEnterprise() *TestHelper {
return setupTestHelper(true)
func SetupEnterprise(tb testing.TB) *TestHelper {
return setupTestHelper(true, tb)
}
func Setup() *TestHelper {
return setupTestHelper(false)
func Setup(tb testing.TB) *TestHelper {
return setupTestHelper(false, tb)
}
func (me *TestHelper) InitBasic() *TestHelper {

Просмотреть файл

@@ -17,7 +17,7 @@ import (
)
func TestImportImportScheme(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Mark the phase 2 permissions migration as completed.
@@ -206,7 +206,7 @@ func TestImportImportScheme(t *testing.T) {
}
func TestImportImportRole(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Try importing an invalid role in dryRun mode.
@@ -311,7 +311,7 @@ func TestImportImportRole(t *testing.T) {
}
func TestImportImportTeam(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Mark the phase 2 permissions migration as completed.
@@ -412,7 +412,7 @@ func TestImportImportTeam(t *testing.T) {
}
func TestImportImportChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Mark the phase 2 permissions migration as completed.
@@ -548,7 +548,7 @@ func TestImportImportChannel(t *testing.T) {
}
func TestImportImportUser(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Check how many users are in the database.
@@ -1303,7 +1303,7 @@ func TestImportImportUser(t *testing.T) {
}
func TestImportUserDefaultNotifyProps(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Create a valid new user with some, but not all, notify props populated.
@@ -1341,7 +1341,7 @@ func TestImportUserDefaultNotifyProps(t *testing.T) {
}
func TestImportImportPost(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Create a Team.
@@ -1757,7 +1757,7 @@ func TestImportImportPost(t *testing.T) {
}
func TestImportImportDirectChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// Check how many channels are in the database.
@@ -1933,7 +1933,7 @@ func TestImportImportDirectChannel(t *testing.T) {
}
func TestImportImportDirectPost(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// Create the DIRECT channel.
@@ -2285,7 +2285,7 @@ func TestImportImportDirectPost(t *testing.T) {
}
func TestImportImportEmoji(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
@@ -2324,7 +2324,7 @@ func TestImportImportEmoji(t *testing.T) {
}
func TestImportAttachment(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
testsDir, _ := fileutils.FindDir("tests")
@@ -2347,7 +2347,7 @@ func TestImportAttachment(t *testing.T) {
func TestImportPostAndRepliesWithAttachments(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Create a Team.
@@ -2486,7 +2486,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
func TestImportDirectPostWithAttachments(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
testsDir, _ := fileutils.FindDir("tests")

Просмотреть файл

@@ -104,7 +104,7 @@ func AssertChannelCount(t *testing.T, a *App, channelType string, expectedCount
}
func TestImportImportLine(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// Try import line with an invalid type.
@@ -160,7 +160,7 @@ func TestImportImportLine(t *testing.T) {
}
func TestImportBulkImport(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })

Просмотреть файл

@@ -19,7 +19,7 @@ import (
// Test for MM-13598 where an invalid integration URL was causing a crash
func TestPostActionInvalidURL(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -67,7 +67,7 @@ func TestPostActionInvalidURL(t *testing.T) {
}
func TestPostAction(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -311,7 +311,7 @@ func TestPostAction(t *testing.T) {
}
func TestSubmitInteractiveDialog(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {

Просмотреть файл

@@ -11,7 +11,7 @@ import (
)
func TestGetJob(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
status := &model.Job{
@@ -32,7 +32,7 @@ func TestGetJob(t *testing.T) {
}
func TestGetJobByType(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
jobType := model.NewId()

Просмотреть файл

@@ -11,7 +11,7 @@ import (
)
func TestLoadLicense(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.LoadLicense()
@@ -21,7 +21,7 @@ func TestLoadLicense(t *testing.T) {
}
func TestSaveLicense(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
b1 := []byte("junk")
@@ -32,7 +32,7 @@ func TestSaveLicense(t *testing.T) {
}
func TestRemoveLicense(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
if err := th.App.RemoveLicense(); err != nil {
@@ -41,7 +41,7 @@ func TestRemoveLicense(t *testing.T) {
}
func TestSetLicense(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
l1 := &model.License{}
@@ -73,7 +73,7 @@ func TestSetLicense(t *testing.T) {
}
func TestClientLicenseEtag(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
etag1 := th.App.GetClientLicenseEtag(false)
@@ -94,7 +94,7 @@ func TestClientLicenseEtag(t *testing.T) {
}
func TestGetSanitizedClientLicense(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
l1 := &model.License{}

Просмотреть файл

@@ -9,7 +9,7 @@ import (
)
func TestCheckForClientSideCert(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
var tests = []struct {

Просмотреть файл

@@ -16,7 +16,7 @@ import (
)
func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] New Direct Message from @sender on"
@@ -32,7 +32,7 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
}
func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] New Group Message in sender on"
@@ -49,7 +49,7 @@ func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) {
}
func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] New Group Message on"
@@ -66,7 +66,7 @@ func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) {
}
func TestGetNotificationEmailSubject(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] Notification in team on"
@@ -82,7 +82,7 @@ func TestGetNotificationEmailSubject(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}
@@ -119,7 +119,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}
@@ -156,7 +156,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}
@@ -193,7 +193,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}
@@ -227,7 +227,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{
@@ -258,7 +258,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testi
}
func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{
@@ -300,7 +300,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing
}
func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{
@@ -332,7 +332,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T)
}
func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{
@@ -365,7 +365,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T)
// from here
func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}
@@ -399,7 +399,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
}
func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}
@@ -433,7 +433,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}
@@ -467,7 +467,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
}
func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
recipient := &model.User{}

Просмотреть файл

@@ -537,7 +537,7 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
}
func TestGetPushNotificationMessage(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
for name, tc := range map[string]struct {

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestSendNotifications(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel)
@@ -626,7 +626,7 @@ func TestGetExplicitMentionsAtHere(t *testing.T) {
}
func TestGetMentionKeywords(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
// user with username or custom mentions enabled
@@ -1013,7 +1013,7 @@ func TestPostNotificationGetChannelName(t *testing.T) {
}
func TestPostNotificationGetSenderName(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
defaultChannel := &model.Channel{Type: model.CHANNEL_OPEN}

Просмотреть файл

@@ -17,7 +17,7 @@ import (
)
func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
@@ -66,7 +66,7 @@ func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
}
func TestOAuthRevokeAccessToken(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
if err := th.App.RevokeAccessToken(model.NewRandomString(16)); err == nil {
@@ -102,7 +102,7 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
}
func TestOAuthDeleteApp(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
*th.App.Config().ServiceSettings.EnableOAuthServiceProvider = true
@@ -151,7 +151,7 @@ func TestOAuthDeleteApp(t *testing.T) {
func TestAuthorizeOAuthUser(t *testing.T) {
setup := func(enable, tokenEndpoint, userEndpoint bool, serverURL string) *TestHelper {
th := Setup()
th := Setup(t)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.GitLabSettings.Enable = enable

Просмотреть файл

@@ -4,6 +4,7 @@
package app
import (
"github.com/mattermost/mattermost-server/mlog"
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/config"
@@ -81,6 +82,13 @@ func StartElasticsearch(s *Server) error {
return nil
}
func SetLogger(logger *mlog.Logger) Option {
return func(s *Server) error {
s.Log = logger
return nil
}
}
type AppOption func(a *App)
type AppOptionCreator func() []AppOption

Просмотреть файл

@@ -18,7 +18,7 @@ func (tw testWriter) Write(p []byte) (int, error) {
}
func TestExportPermissions(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var scheme *model.Scheme
@@ -84,7 +84,7 @@ func TestExportPermissions(t *testing.T) {
}
func TestImportPermissions(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
name := model.NewId()
@@ -157,7 +157,7 @@ func TestImportPermissions(t *testing.T) {
}
func TestImportPermissions_idempotentScheme(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
name := model.NewId()
@@ -200,7 +200,7 @@ func TestImportPermissions_idempotentScheme(t *testing.T) {
}
func TestImportPermissions_schemeDeletedOnRoleFailure(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
name := model.NewId()

Просмотреть файл

@@ -48,7 +48,7 @@ func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string,
}
func TestPluginAPIGetUsers(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -135,7 +135,7 @@ func TestPluginAPIGetUsers(t *testing.T) {
}
func TestPluginAPIGetUsersInTeam(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -244,7 +244,7 @@ func TestPluginAPIGetUsersInTeam(t *testing.T) {
}
func TestPluginAPIUpdateUserStatus(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -263,7 +263,7 @@ func TestPluginAPIUpdateUserStatus(t *testing.T) {
}
func TestPluginAPIGetFile(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -288,7 +288,7 @@ func TestPluginAPIGetFile(t *testing.T) {
require.Nil(t, data)
}
func TestPluginAPISavePluginConfig(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
manifest := &model.Manifest{
@@ -335,7 +335,7 @@ func TestPluginAPISavePluginConfig(t *testing.T) {
}
func TestPluginAPIGetPluginConfig(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
manifest := &model.Manifest{
@@ -366,7 +366,7 @@ func TestPluginAPIGetPluginConfig(t *testing.T) {
}
func TestPluginAPILoadPluginConfiguration(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var pluginJson map[string]interface{}
@@ -437,7 +437,7 @@ func TestPluginAPILoadPluginConfiguration(t *testing.T) {
}
func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var pluginJson map[string]interface{}
@@ -511,7 +511,7 @@ func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) {
}
func TestPluginAPIGetProfileImage(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -527,7 +527,7 @@ func TestPluginAPIGetProfileImage(t *testing.T) {
}
func TestPluginAPISetProfileImage(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -557,7 +557,7 @@ func TestPluginAPISetProfileImage(t *testing.T) {
}
func TestPluginAPIGetPlugins(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -615,7 +615,7 @@ func TestPluginAPIGetPlugins(t *testing.T) {
}
func TestPluginAPIGetTeamIcon(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -646,7 +646,7 @@ func TestPluginAPIGetTeamIcon(t *testing.T) {
}
func TestPluginAPISetTeamIcon(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -676,7 +676,7 @@ func TestPluginAPISetTeamIcon(t *testing.T) {
}
func TestPluginAPISearchChannels(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -694,7 +694,7 @@ func TestPluginAPISearchChannels(t *testing.T) {
}
func TestPluginAPISearchPostsInTeam(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -740,7 +740,7 @@ func TestPluginAPISearchPostsInTeam(t *testing.T) {
}
func TestPluginAPIGetChannelsForTeamForUser(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -758,7 +758,7 @@ func TestPluginAPIGetChannelsForTeamForUser(t *testing.T) {
}
func TestPluginAPIRemoveTeamIcon(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -781,7 +781,7 @@ func TestPluginAPIRemoveTeamIcon(t *testing.T) {
}
func TestPluginAPIUpdateUserActive(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -808,7 +808,7 @@ func TestPluginAPIUpdateUserActive(t *testing.T) {
}
func TestPluginAPIGetDirectChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -826,7 +826,7 @@ func TestPluginAPIGetDirectChannel(t *testing.T) {
}
func TestPluginAPISendMail(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
@@ -856,7 +856,7 @@ func TestPluginAPISendMail(t *testing.T) {
}
func TestPluginAPI_SearchTeams(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()

Просмотреть файл

@@ -12,7 +12,7 @@ import (
)
func TestPluginCommand(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
args := &model.CommandArgs{}

Просмотреть файл

@@ -15,7 +15,7 @@ import (
func TestPluginDeadlock(t *testing.T) {
t.Run("Single Plugin", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
pluginPostOnActivate := template.Must(template.New("pluginPostOnActivate").Parse(`
@@ -103,7 +103,7 @@ func TestPluginDeadlock(t *testing.T) {
})
t.Run("Multiple Plugins", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
pluginPostOnHasBeenPosted := template.Must(template.New("pluginPostOnHasBeenPosted").Parse(`

Просмотреть файл

@@ -66,7 +66,7 @@ func SetAppEnvironmentWithPlugins(t *testing.T, pluginCode []string, app *App, a
func TestHookMessageWillBePosted(t *testing.T) {
t.Run("rejected", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := SetAppEnvironmentWithPlugins(t, []string{
@@ -106,7 +106,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
})
t.Run("rejected, returned post ignored", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := SetAppEnvironmentWithPlugins(t, []string{
@@ -147,7 +147,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
})
t.Run("allowed", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := SetAppEnvironmentWithPlugins(t, []string{
@@ -193,7 +193,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
})
t.Run("updated", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := SetAppEnvironmentWithPlugins(t, []string{
@@ -240,7 +240,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
})
t.Run("multiple updated", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := SetAppEnvironmentWithPlugins(t, []string{
@@ -305,7 +305,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
}
func TestHookMessageHasBeenPosted(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var mockAPI plugintest.API
@@ -349,7 +349,7 @@ func TestHookMessageHasBeenPosted(t *testing.T) {
}
func TestHookMessageWillBeUpdated(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
@@ -397,7 +397,7 @@ func TestHookMessageWillBeUpdated(t *testing.T) {
}
func TestHookMessageHasBeenUpdated(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var mockAPI plugintest.API
@@ -449,7 +449,7 @@ func TestHookMessageHasBeenUpdated(t *testing.T) {
func TestHookFileWillBeUploaded(t *testing.T) {
t.Run("rejected", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var mockAPI plugintest.API
@@ -496,7 +496,7 @@ func TestHookFileWillBeUploaded(t *testing.T) {
})
t.Run("rejected, returned file ignored", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var mockAPI plugintest.API
@@ -545,7 +545,7 @@ func TestHookFileWillBeUploaded(t *testing.T) {
})
t.Run("allowed", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var mockAPI plugintest.API
@@ -604,7 +604,7 @@ func TestHookFileWillBeUploaded(t *testing.T) {
})
t.Run("updated", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var mockAPI plugintest.API
@@ -673,7 +673,7 @@ func TestHookFileWillBeUploaded(t *testing.T) {
}
func TestUserWillLogIn_Blocked(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
err := th.App.UpdatePassword(th.BasicUser, "hunter2")
@@ -718,7 +718,7 @@ func TestUserWillLogIn_Blocked(t *testing.T) {
}
func TestUserWillLogInIn_Passed(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
err := th.App.UpdatePassword(th.BasicUser, "hunter2")
@@ -763,7 +763,7 @@ func TestUserWillLogInIn_Passed(t *testing.T) {
}
func TestUserHasLoggedIn(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
err := th.App.UpdatePassword(th.BasicUser, "hunter2")
@@ -817,7 +817,7 @@ func TestUserHasLoggedIn(t *testing.T) {
}
func TestUserHasBeenCreated(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
@@ -864,7 +864,7 @@ func TestUserHasBeenCreated(t *testing.T) {
}
func TestErrorString(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
t.Run("errors.New", func(t *testing.T) {
@@ -936,7 +936,7 @@ func TestErrorString(t *testing.T) {
}
func TestHookContext(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// We don't actually have a session, we are faking it so just set something arbitrarily

Просмотреть файл

@@ -26,7 +26,7 @@ func getHashedKey(key string) string {
}
func TestPluginKeyValueStore(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
pluginId := "testpluginid"
@@ -126,7 +126,7 @@ func TestPluginKeyValueStore(t *testing.T) {
}
func TestServePluginRequest(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
@@ -138,7 +138,7 @@ func TestServePluginRequest(t *testing.T) {
}
func TestPrivateServePluginRequest(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
testCases := []struct {
@@ -184,7 +184,7 @@ func TestPrivateServePluginRequest(t *testing.T) {
}
func TestHandlePluginRequest(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -231,7 +231,7 @@ func TestHandlePluginRequest(t *testing.T) {
}
func TestGetPluginStatusesDisabled(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -244,7 +244,7 @@ func TestGetPluginStatusesDisabled(t *testing.T) {
}
func TestGetPluginStatuses(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {

Просмотреть файл

@@ -29,7 +29,7 @@ import (
func TestPreparePostListForClient(t *testing.T) {
// Most of this logic is covered by TestPreparePostForClient, so this just tests handling of multiple posts
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -63,7 +63,7 @@ func TestPreparePostListForClient(t *testing.T) {
func TestPreparePostForClient(t *testing.T) {
setup := func() *TestHelper {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ImageProxySettings.Enable = false
@@ -417,7 +417,7 @@ func TestPreparePostForClient(t *testing.T) {
func TestPreparePostForClientWithImageProxy(t *testing.T) {
setup := func() *TestHelper {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.SiteURL = "http://mymattermost.com"
@@ -500,7 +500,7 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) {
func TestGetImagesForPost(t *testing.T) {
t.Run("with an image link", func(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -531,7 +531,7 @@ func TestGetImagesForPost(t *testing.T) {
})
t.Run("with an invalid image link", func(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -553,7 +553,7 @@ func TestGetImagesForPost(t *testing.T) {
})
t.Run("for an OpenGraph image with dimensions", func(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -594,7 +594,7 @@ func TestGetImagesForPost(t *testing.T) {
})
t.Run("for an OpenGraph image without dimensions", func(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -647,7 +647,7 @@ func TestGetImagesForPost(t *testing.T) {
})
t.Run("with an OpenGraph image with a secure_url and dimensions", func(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -688,7 +688,7 @@ func TestGetImagesForPost(t *testing.T) {
})
t.Run("with an OpenGraph image with a secure_url and no dimensions", func(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -887,7 +887,7 @@ func TestGetEmojiNamesForPost(t *testing.T) {
}
func TestGetCustomEmojisForPost(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -1244,7 +1244,7 @@ func TestGetImagesInMessageAttachments(t *testing.T) {
func TestGetLinkMetadata(t *testing.T) {
setup := func() *TestHelper {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
@@ -1798,7 +1798,7 @@ func TestResolveMetadataURL(t *testing.T) {
}
func TestParseLinkMetadata(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
imageURL := "http://example.com/test.png"

Просмотреть файл

@@ -19,7 +19,7 @@ import (
)
func TestCreatePostDeduplicate(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
t.Run("duplicate create post is idempotent", func(t *testing.T) {
@@ -188,7 +188,7 @@ func TestCreatePostDeduplicate(t *testing.T) {
func TestAttachFilesToPost(t *testing.T) {
t.Run("should attach files", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
info1 := store.Must(th.App.Srv.Store.FileInfo().Save(&model.FileInfo{
@@ -212,7 +212,7 @@ func TestAttachFilesToPost(t *testing.T) {
})
t.Run("should update File.PostIds after failing to add files", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
info1 := store.Must(th.App.Srv.Store.FileInfo().Save(&model.FileInfo{
@@ -244,7 +244,7 @@ func TestAttachFilesToPost(t *testing.T) {
}
func TestUpdatePostEditAt(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
post := &model.Post{}
@@ -272,7 +272,7 @@ func TestUpdatePostEditAt(t *testing.T) {
}
func TestUpdatePostTimeLimit(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
post := &model.Post{}
@@ -311,7 +311,7 @@ func TestUpdatePostTimeLimit(t *testing.T) {
func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
// This test ensures that when replying to a root post made by a user who has since left the channel, the reply
// post completes successfully. This is a regression test for PLT-6523.
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channel := th.BasicChannel
@@ -343,7 +343,7 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
}
func TestPostChannelMentions(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
channel := th.BasicChannel
@@ -390,7 +390,7 @@ func TestPostChannelMentions(t *testing.T) {
}
func TestImageProxy(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -542,7 +542,7 @@ func TestMaxPostSize(t *testing.T) {
}
func TestDeletePostWithFileAttachments(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
// Create a post with a file attachment.
@@ -588,7 +588,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
func TestCreatePost(t *testing.T) {
t.Run("call PreparePostForClient before returning", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -616,7 +616,7 @@ func TestCreatePost(t *testing.T) {
func TestPatchPost(t *testing.T) {
t.Run("call PreparePostForClient before returning", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -652,7 +652,7 @@ func TestPatchPost(t *testing.T) {
func TestUpdatePost(t *testing.T) {
t.Run("call PreparePostForClient before returning", func(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {

Просмотреть файл

@@ -151,8 +151,9 @@ func NewServer(options ...Option) (*Server, error) {
s.configStore = configStore
}
// Initalize logging
s.Log = mlog.NewLogger(utils.MloggerConfigFromLoggerConfig(&s.Config().LogSettings))
if s.Log == nil {
s.Log = mlog.NewLogger(utils.MloggerConfigFromLoggerConfig(&s.Config().LogSettings))
}
// Redirect default golang logger to this logger
mlog.RedirectStdLog(s.Log)

Просмотреть файл

@@ -13,7 +13,7 @@ import (
)
func TestCache(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
session := &model.Session{
@@ -38,7 +38,7 @@ func TestCache(t *testing.T) {
}
func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
session := &model.Session{

Просмотреть файл

@@ -7,7 +7,7 @@ import (
)
func TestProcessSlackText(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
if th.App.ProcessSlackText("<!channel> foo <!channel>") != "@channel foo @channel" {
@@ -30,7 +30,7 @@ func TestProcessSlackText(t *testing.T) {
}
func TestProcessSlackAnnouncement(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
userId := th.BasicUser.Id

Просмотреть файл

@@ -10,7 +10,7 @@ import (
)
func TestSaveStatus(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.BasicUser

Просмотреть файл

@@ -7,7 +7,7 @@ import (
)
func TestPopulateSyncablesSince(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
singersTeam, err := th.App.CreateTeam(&model.Team{

Просмотреть файл

@@ -15,7 +15,7 @@ import (
)
func TestCreateTeam(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
id := model.NewId()
@@ -37,7 +37,7 @@ func TestCreateTeam(t *testing.T) {
}
func TestCreateTeamWithUser(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
id := model.NewId()
@@ -58,7 +58,7 @@ func TestCreateTeamWithUser(t *testing.T) {
}
func TestUpdateTeam(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.BasicTeam.DisplayName = "Testing 123"
@@ -74,7 +74,7 @@ func TestUpdateTeam(t *testing.T) {
}
func TestAddUserToTeam(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
t.Run("add user", func(t *testing.T) {
@@ -188,7 +188,7 @@ func TestAddUserToTeam(t *testing.T) {
}
func TestAddUserToTeamByToken(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
@@ -289,7 +289,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
}
func TestAddUserToTeamByTeamId(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
t.Run("add user", func(t *testing.T) {
@@ -322,7 +322,7 @@ func TestAddUserToTeamByTeamId(t *testing.T) {
}
func TestPermanentDeleteTeam(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
team, err := th.App.CreateTeam(&model.Team{
@@ -383,7 +383,7 @@ func TestPermanentDeleteTeam(t *testing.T) {
}
func TestSanitizeTeam(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
team := &model.Team{
@@ -513,7 +513,7 @@ func TestSanitizeTeam(t *testing.T) {
}
func TestSanitizeTeams(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
t.Run("not a system admin", func(t *testing.T) {
@@ -597,7 +597,7 @@ func TestSanitizeTeams(t *testing.T) {
}
func TestJoinUserToTeam(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
id := model.NewId()
@@ -685,7 +685,7 @@ func TestJoinUserToTeam(t *testing.T) {
}
func TestAppUpdateTeamScheme(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
team := th.BasicTeam
@@ -703,7 +703,7 @@ func TestAppUpdateTeamScheme(t *testing.T) {
}
func TestGetTeamMembers(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
var userIDs sort.StringSlice
@@ -745,7 +745,7 @@ func TestGetTeamMembers(t *testing.T) {
}
func TestGetTeamStats(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
teamStats, err := th.App.GetTeamStats(th.BasicTeam.Id)

Просмотреть файл

@@ -10,7 +10,7 @@ import (
)
func TestUserTermsOfService(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
userTermsOfService, err := th.App.GetUserTermsOfService(th.BasicUser.Id)

Просмотреть файл

@@ -18,11 +18,11 @@ import (
"github.com/mattermost/mattermost-server/einterfaces"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/model/gitlab"
oauthgitlab "github.com/mattermost/mattermost-server/model/gitlab"
)
func TestIsUsernameTaken(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.BasicUser
@@ -43,7 +43,7 @@ func TestIsUsernameTaken(t *testing.T) {
}
func TestCheckUserDomain(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := th.BasicUser
@@ -71,7 +71,7 @@ func TestCheckUserDomain(t *testing.T) {
}
func TestCreateOAuthUser(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
r := rand.New(rand.NewSource(time.Now().UnixNano()))
@@ -117,7 +117,7 @@ func TestCreateProfileImage(t *testing.T) {
}
func TestSetDefaultProfileImage(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
err := th.App.SetDefaultProfileImage(&model.User{
@@ -136,7 +136,7 @@ func TestSetDefaultProfileImage(t *testing.T) {
}
func TestUpdateUserToRestrictedDomain(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
user := th.CreateUser()
@@ -155,7 +155,7 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) {
}
func TestUpdateUserActive(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
user := th.CreateUser()
@@ -173,7 +173,7 @@ func TestUpdateUserActive(t *testing.T) {
}
func TestUpdateOAuthUserAttrs(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
id := model.NewId()
@@ -321,7 +321,7 @@ func createGitlabUser(t *testing.T, a *App, username string, email string) (*mod
}
func TestGetUsersByStatus(t *testing.T) {
th := Setup()
th := Setup(t)
defer th.TearDown()
team := th.CreateTeam()
@@ -450,7 +450,7 @@ func TestGetUsersByStatus(t *testing.T) {
}
func TestCreateUserWithToken(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
@@ -520,7 +520,7 @@ func TestCreateUserWithToken(t *testing.T) {
}
func TestPermanentDeleteUser(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
b := []byte("testimage")

Просмотреть файл

@@ -14,7 +14,7 @@ import (
)
func TestWebConnShouldSendEvent(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
session, err := th.App.CreateSession(&model.Session{UserId: th.BasicUser.Id, Roles: th.BasicUser.GetRawRoles()})

Просмотреть файл

@@ -47,7 +47,7 @@ func registerDummyWebConn(t *testing.T, a *App, addr net.Addr, userId string) *W
}
func TestHubStopWithMultipleConnections(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
s := httptest.NewServer(http.HandlerFunc(dummyWebsocketHandler(t)))
@@ -65,7 +65,7 @@ func TestHubStopWithMultipleConnections(t *testing.T) {
// TestHubStopRaceCondition verifies that attempts to use the hub after it has shutdown does not
// block the caller indefinitely.
func TestHubStopRaceCondition(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
s := httptest.NewServer(http.HandlerFunc(dummyWebsocketHandler(t)))

Просмотреть файл

@@ -20,7 +20,7 @@ import (
)
func TestCreateIncomingWebhookForChannel(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
type TestCase struct {
@@ -151,7 +151,7 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
}
func TestUpdateIncomingWebhook(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
type TestCase struct {
@@ -289,7 +289,7 @@ func TestUpdateIncomingWebhook(t *testing.T) {
}
func TestCreateWebhookPost(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
@@ -478,7 +478,7 @@ func TestSplitWebhookPost(t *testing.T) {
}
func TestCreateOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
outgoingWebhook := model.OutgoingWebhook{
@@ -597,7 +597,7 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
return testCasesOutgoing
}
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -668,7 +668,7 @@ func (r InfiniteReader) Read(p []byte) (n int, err error) {
}
func TestDoOutgoingWebhookRequest(t *testing.T) {
th := Setup().InitBasic()
th := Setup(t).InitBasic()
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {

42
mlog/testing.go Обычный файл
Просмотреть файл

@@ -0,0 +1,42 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package mlog
import (
"strings"
"testing"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// testingWriter is an io.Writer that writes through t.Log
type testingWriter struct {
tb testing.TB
}
func (tw *testingWriter) Write(b []byte) (int, error) {
tw.tb.Log(strings.TrimSpace(string(b)))
return len(b), nil
}
// NewTestingLogger creates a Logger that proxies logs through a testing interface.
// This allows tests that spin up App instances to avoid spewing logs unless the test fails or -verbose is specified.
func NewTestingLogger(tb testing.TB) *Logger {
logWriter := &testingWriter{tb}
logWriterSync := zapcore.AddSync(logWriter)
testingLogger := &Logger{
consoleLevel: zap.NewAtomicLevelAt(getZapLevel("debug")),
fileLevel: zap.NewAtomicLevelAt(getZapLevel("info")),
}
logWriterCore := zapcore.NewCore(makeEncoder(true), logWriterSync, testingLogger.consoleLevel)
testingLogger.zap = zap.New(logWriterCore,
zap.AddCallerSkip(1),
zap.AddCaller(),
)
return testingLogger
}