From 39ceaa3e868522332d7a92bf2581d94aade6fc89 Mon Sep 17 00:00:00 2001 From: Shreyansh Chouhan Date: Thu, 14 Feb 2019 23:22:11 +0530 Subject: [PATCH] [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 --- app/app_test.go | 6 ++--- app/authorization_test.go | 2 +- app/auto_responder_test.go | 8 +++--- app/channel_test.go | 38 +++++++++++++------------- app/cluster_discovery_test.go | 2 +- app/command_channel_header_test.go | 2 +- app/command_channel_purpose_test.go | 2 +- app/command_channel_rename_test.go | 2 +- app/command_groupmsg_test.go | 2 +- app/command_invite_people_test.go | 2 +- app/command_invite_test.go | 2 +- app/command_join_test.go | 8 +++--- app/command_leave_test.go | 2 +- app/command_msg_test.go | 2 +- app/command_mute_test.go | 12 ++++----- app/command_remove_test.go | 2 +- app/command_test.go | 10 +++---- app/config_test.go | 8 +++--- app/diagnostics_test.go | 2 +- app/email_batching_test.go | 12 ++++----- app/export_test.go | 16 +++++------ app/file_bench_test.go | 2 +- app/file_test.go | 12 ++++----- app/group_test.go | 24 ++++++++--------- app/helper_test.go | 11 ++++---- app/import_functions_test.go | 26 +++++++++--------- app/import_test.go | 4 +-- app/integration_action_test.go | 6 ++--- app/job_test.go | 4 +-- app/license_test.go | 12 ++++----- app/login_test.go | 2 +- app/notification_email_test.go | 32 +++++++++++----------- app/notification_push_test.go | 2 +- app/notification_test.go | 6 ++--- app/oauth_test.go | 8 +++--- app/options.go | 8 ++++++ app/permissions_test.go | 8 +++--- app/plugin_api_test.go | 42 ++++++++++++++--------------- app/plugin_commands_test.go | 2 +- app/plugin_deadlock_test.go | 4 +-- app/plugin_hooks_test.go | 36 ++++++++++++------------- app/plugin_test.go | 12 ++++----- app/post_metadata_test.go | 24 ++++++++--------- app/post_test.go | 24 ++++++++--------- app/server.go | 5 ++-- app/session_test.go | 4 +-- app/slack_test.go | 4 +-- app/status_test.go | 2 +- app/syncables_test.go | 2 +- app/team_test.go | 26 +++++++++--------- app/user_terms_of_service_test.go | 2 +- app/user_test.go | 22 +++++++-------- app/web_conn_test.go | 2 +- app/web_hub_test.go | 4 +-- app/webhook_test.go | 12 ++++----- mlog/testing.go | 42 +++++++++++++++++++++++++++++ 56 files changed, 316 insertions(+), 264 deletions(-) create mode 100644 mlog/testing.go diff --git a/app/app_test.go b/app/app_test.go index 4a622d29c7..107a241a83 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -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 { diff --git a/app/authorization_test.go b/app/authorization_test.go index 1900c9f417..0151985629 100644 --- a/app/authorization_test.go +++ b/app/authorization_test.go @@ -10,7 +10,7 @@ import ( ) func TestCheckIfRolesGrantPermission(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() cases := []struct { diff --git a/app/auto_responder_test.go b/app/auto_responder_test.go index 04a1d5c041..8450b36bd3 100644 --- a/app/auto_responder_test.go +++ b/app/auto_responder_test.go @@ -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() diff --git a/app/channel_test.go b/app/channel_test.go index 0bf4a3d565..1bbdac941e 100644 --- a/app/channel_test.go +++ b/app/channel_test.go @@ -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() diff --git a/app/cluster_discovery_test.go b/app/cluster_discovery_test.go index c9d7e814df..8d1f380528 100644 --- a/app/cluster_discovery_test.go +++ b/app/cluster_discovery_test.go @@ -12,7 +12,7 @@ import ( ) func TestClusterDiscoveryService(t *testing.T) { - th := Setup() + th := Setup(t) defer th.TearDown() ds := th.App.NewClusterDiscoveryService() diff --git a/app/command_channel_header_test.go b/app/command_channel_header_test.go index 99f3b0cc37..1ffcceae4e 100644 --- a/app/command_channel_header_test.go +++ b/app/command_channel_header_test.go @@ -12,7 +12,7 @@ import ( ) func TestHeaderProviderDoCommand(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() hp := HeaderProvider{} diff --git a/app/command_channel_purpose_test.go b/app/command_channel_purpose_test.go index 3bdaa4e4ff..2fdd42b020 100644 --- a/app/command_channel_purpose_test.go +++ b/app/command_channel_purpose_test.go @@ -12,7 +12,7 @@ import ( ) func TestPurposeProviderDoCommand(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() pp := PurposeProvider{} diff --git a/app/command_channel_rename_test.go b/app/command_channel_rename_test.go index d4cdeda51e..74241fb7eb 100644 --- a/app/command_channel_rename_test.go +++ b/app/command_channel_rename_test.go @@ -12,7 +12,7 @@ import ( ) func TestRenameProviderDoCommand(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() rp := RenameProvider{} diff --git a/app/command_groupmsg_test.go b/app/command_groupmsg_test.go index 422679525e..bed14279dc 100644 --- a/app/command_groupmsg_test.go +++ b/app/command_groupmsg_test.go @@ -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() diff --git a/app/command_invite_people_test.go b/app/command_invite_people_test.go index adff12a55a..8c5a94667f 100644 --- a/app/command_invite_people_test.go +++ b/app/command_invite_people_test.go @@ -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) { diff --git a/app/command_invite_test.go b/app/command_invite_test.go index b48d3e13e4..71eb582154 100644 --- a/app/command_invite_test.go +++ b/app/command_invite_test.go @@ -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) diff --git a/app/command_join_test.go b/app/command_join_test.go index e5f42f31e3..67dbe28fb6 100644 --- a/app/command_join_test.go +++ b/app/command_join_test.go @@ -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{ diff --git a/app/command_leave_test.go b/app/command_leave_test.go index a1c185be04..a99f49dbbf 100644 --- a/app/command_leave_test.go +++ b/app/command_leave_test.go @@ -13,7 +13,7 @@ import ( ) func TestLeaveProviderDoCommand(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() lp := LeaveProvider{} diff --git a/app/command_msg_test.go b/app/command_msg_test.go index 9a8ca8eb0c..8fdfd50515 100644 --- a/app/command_msg_test.go +++ b/app/command_msg_test.go @@ -13,7 +13,7 @@ import ( ) func TestMsgProvider(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() team := th.CreateTeam() diff --git a/app/command_mute_test.go b/app/command_mute_test.go index 4551dfa960..5cd538b9b2 100644 --- a/app/command_mute_test.go +++ b/app/command_mute_test.go @@ -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() { diff --git a/app/command_remove_test.go b/app/command_remove_test.go index 66257f5631..6663359a5d 100644 --- a/app/command_remove_test.go +++ b/app/command_remove_test.go @@ -12,7 +12,7 @@ import ( ) func TestRemoveProviderDoCommand(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() rp := RemoveProvider{} diff --git a/app/command_test.go b/app/command_test.go index 11f852f13f..3c718320f4 100644 --- a/app/command_test.go +++ b/app/command_test.go @@ -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) { diff --git a/app/config_test.go b/app/config_test.go index 97084331f5..23d116c8ea 100644 --- a/app/config_test.go +++ b/app/config_test.go @@ -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 { diff --git a/app/diagnostics_test.go b/app/diagnostics_test.go index 39b522e2c5..0ee95a2e24 100644 --- a/app/diagnostics_test.go +++ b/app/diagnostics_test.go @@ -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() { diff --git a/app/email_batching_test.go b/app/email_batching_test.go index 8b1c4a0b84..a8d9d6be1c 100644 --- a/app/email_batching_test.go +++ b/app/email_batching_test.go @@ -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{} diff --git a/app/export_test.go b/app/export_test.go index 11aeb7b375..df1ed88a3b 100644 --- a/app/export_test.go +++ b/app/export_test.go @@ -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) diff --git a/app/file_bench_test.go b/app/file_bench_test.go index da2d1a38aa..1960b43db7 100644 --- a/app/file_bench_test.go +++ b/app/file_bench_test.go @@ -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) diff --git a/app/file_test.go b/app/file_test.go index ab803d3ec7..4848ba0391 100644 --- a/app/file_test.go +++ b/app/file_test.go @@ -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() diff --git a/app/group_test.go b/app/group_test.go index e5cc67b8e4..790144b9c7 100644 --- a/app/group_test.go +++ b/app/group_test.go @@ -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{ diff --git a/app/helper_test.go b/app/helper_test.go index 4453b5af25..e8b35da739 100644 --- a/app/helper_test.go +++ b/app/helper_test.go @@ -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 { diff --git a/app/import_functions_test.go b/app/import_functions_test.go index 7266c4a30d..1be40be5f1 100644 --- a/app/import_functions_test.go +++ b/app/import_functions_test.go @@ -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") diff --git a/app/import_test.go b/app/import_test.go index 9087177a3b..b5f50c8843 100644 --- a/app/import_test.go +++ b/app/import_test.go @@ -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 }) diff --git a/app/integration_action_test.go b/app/integration_action_test.go index 7f76f55e82..d08565a749 100644 --- a/app/integration_action_test.go +++ b/app/integration_action_test.go @@ -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) { diff --git a/app/job_test.go b/app/job_test.go index 35c4a6bc86..ca3d1c7f61 100644 --- a/app/job_test.go +++ b/app/job_test.go @@ -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() diff --git a/app/license_test.go b/app/license_test.go index 4a5f7df0ea..085adf04f8 100644 --- a/app/license_test.go +++ b/app/license_test.go @@ -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{} diff --git a/app/login_test.go b/app/login_test.go index b30b548d80..585865753e 100644 --- a/app/login_test.go +++ b/app/login_test.go @@ -9,7 +9,7 @@ import ( ) func TestCheckForClientSideCert(t *testing.T) { - th := Setup() + th := Setup(t) defer th.TearDown() var tests = []struct { diff --git a/app/notification_email_test.go b/app/notification_email_test.go index c32cd42489..1c920a9b0a 100644 --- a/app/notification_email_test.go +++ b/app/notification_email_test.go @@ -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{} diff --git a/app/notification_push_test.go b/app/notification_push_test.go index 03ba9f8770..cfa47ae9f0 100644 --- a/app/notification_push_test.go +++ b/app/notification_push_test.go @@ -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 { diff --git a/app/notification_test.go b/app/notification_test.go index cde212ba97..f7c583616b 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -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} diff --git a/app/oauth_test.go b/app/oauth_test.go index 6a0438f318..9155cdbcf6 100644 --- a/app/oauth_test.go +++ b/app/oauth_test.go @@ -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 diff --git a/app/options.go b/app/options.go index 2fe02f6a4e..bb8cd65b44 100644 --- a/app/options.go +++ b/app/options.go @@ -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 diff --git a/app/permissions_test.go b/app/permissions_test.go index ca98461e75..d9d31ea176 100644 --- a/app/permissions_test.go +++ b/app/permissions_test.go @@ -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() diff --git a/app/plugin_api_test.go b/app/plugin_api_test.go index 64ae984240..9eb65c3996 100644 --- a/app/plugin_api_test.go +++ b/app/plugin_api_test.go @@ -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() diff --git a/app/plugin_commands_test.go b/app/plugin_commands_test.go index 4fbeda889e..830ef48980 100644 --- a/app/plugin_commands_test.go +++ b/app/plugin_commands_test.go @@ -12,7 +12,7 @@ import ( ) func TestPluginCommand(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() args := &model.CommandArgs{} diff --git a/app/plugin_deadlock_test.go b/app/plugin_deadlock_test.go index 1dcaaa2284..f7dc05f22e 100644 --- a/app/plugin_deadlock_test.go +++ b/app/plugin_deadlock_test.go @@ -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(` diff --git a/app/plugin_hooks_test.go b/app/plugin_hooks_test.go index 20fa9115e5..cf666f260d 100644 --- a/app/plugin_hooks_test.go +++ b/app/plugin_hooks_test.go @@ -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 diff --git a/app/plugin_test.go b/app/plugin_test.go index fe6b33156b..01b03a912d 100644 --- a/app/plugin_test.go +++ b/app/plugin_test.go @@ -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) { diff --git a/app/post_metadata_test.go b/app/post_metadata_test.go index 50b43b0a7e..6ec8beaca1 100644 --- a/app/post_metadata_test.go +++ b/app/post_metadata_test.go @@ -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" diff --git a/app/post_test.go b/app/post_test.go index a06dc00bde..8233160d30 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -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) { diff --git a/app/server.go b/app/server.go index 44281023c9..23896cd8c7 100644 --- a/app/server.go +++ b/app/server.go @@ -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) diff --git a/app/session_test.go b/app/session_test.go index 4eb6999151..53a8558be8 100644 --- a/app/session_test.go +++ b/app/session_test.go @@ -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{ diff --git a/app/slack_test.go b/app/slack_test.go index 370942ba0f..c6c80140be 100644 --- a/app/slack_test.go +++ b/app/slack_test.go @@ -7,7 +7,7 @@ import ( ) func TestProcessSlackText(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() if th.App.ProcessSlackText(" foo ") != "@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 diff --git a/app/status_test.go b/app/status_test.go index bf5736a48b..0a56c8158e 100644 --- a/app/status_test.go +++ b/app/status_test.go @@ -10,7 +10,7 @@ import ( ) func TestSaveStatus(t *testing.T) { - th := Setup().InitBasic() + th := Setup(t).InitBasic() defer th.TearDown() user := th.BasicUser diff --git a/app/syncables_test.go b/app/syncables_test.go index 3396ee2a6c..f5cd202b8c 100644 --- a/app/syncables_test.go +++ b/app/syncables_test.go @@ -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{ diff --git a/app/team_test.go b/app/team_test.go index 15f0356b11..6d025a46eb 100644 --- a/app/team_test.go +++ b/app/team_test.go @@ -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) diff --git a/app/user_terms_of_service_test.go b/app/user_terms_of_service_test.go index bc81f872e7..219cccef08 100644 --- a/app/user_terms_of_service_test.go +++ b/app/user_terms_of_service_test.go @@ -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) diff --git a/app/user_test.go b/app/user_test.go index 52635b503c..33a7409132 100644 --- a/app/user_test.go +++ b/app/user_test.go @@ -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") diff --git a/app/web_conn_test.go b/app/web_conn_test.go index d49c8e9d1f..27c6c203d6 100644 --- a/app/web_conn_test.go +++ b/app/web_conn_test.go @@ -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()}) diff --git a/app/web_hub_test.go b/app/web_hub_test.go index 83b58489a3..088cb35fac 100644 --- a/app/web_hub_test.go +++ b/app/web_hub_test.go @@ -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))) diff --git a/app/webhook_test.go b/app/webhook_test.go index b7a6b3a3ad..fe86eebc59 100644 --- a/app/webhook_test.go +++ b/app/webhook_test.go @@ -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) { diff --git a/mlog/testing.go b/mlog/testing.go new file mode 100644 index 0000000000..7b03b393e4 --- /dev/null +++ b/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 +}