From 4a2715974df55b71cfe038ef7179687cbedd62dd Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 22 Jul 2020 13:50:33 +0530 Subject: [PATCH] MM-27149: optimize initBasic (#15063) * MM-27149: optimize initBasic Mostly, all tests just needed the user initialization part and not the channel and group creation. So we move the user initialization inside the Setup call. This avoids unnecessary DB calls which take around 250-300ms on average. And we make the login requests concurrently to shave off a few more ms. According to my tests, the 2 login calls take 140 ms on average, which shaves off 70ms. So approximately, we shave off 350ms per test. And there are 114 occurences of these. So around 39 seconds. * make initlogin only for Setup/SetupEnterprise Co-authored-by: Mattermod --- api4/apitestlib.go | 30 ++++++++++++++++++++++++------ api4/bleve_test.go | 2 +- api4/bot_test.go | 10 +++++----- api4/brand_test.go | 6 +++--- api4/channel_test.go | 2 +- api4/cluster_test.go | 2 +- api4/config_test.go | 16 ++++++++-------- api4/data_retention_test.go | 2 +- api4/elasticsearch_test.go | 4 ++-- api4/group_test.go | 8 ++++---- api4/handlers_test.go | 2 +- api4/image_test.go | 2 +- api4/job_test.go | 10 +++++----- api4/ldap_test.go | 12 ++++++------ api4/license_test.go | 6 +++--- api4/oauth_test.go | 12 ++++++------ api4/plugin_test.go | 20 ++++++++++---------- api4/role_test.go | 8 ++++---- api4/saml_test.go | 2 +- api4/scheme_test.go | 6 +++--- api4/system_test.go | 36 ++++++++++++++++++------------------ api4/team_test.go | 26 +++++++++++++------------- api4/user_test.go | 28 ++++++++++++++-------------- api4/websocket_test.go | 4 ++-- 24 files changed, 137 insertions(+), 119 deletions(-) diff --git a/api4/apitestlib.go b/api4/apitestlib.go index e48dbfdcae..8798050c5f 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -188,7 +188,9 @@ func SetupEnterprise(tb testing.TB) *TestHelper { dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() searchEngine := mainHelper.GetSearchEngine() - return setupTestHelper(dbStore, searchEngine, true, true, nil) + th := setupTestHelper(dbStore, searchEngine, true, true, nil) + th.InitLogin() + return th } func Setup(tb testing.TB) *TestHelper { @@ -204,7 +206,9 @@ func Setup(tb testing.TB) *TestHelper { dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() searchEngine := mainHelper.GetSearchEngine() - return setupTestHelper(dbStore, searchEngine, false, true, nil) + th := setupTestHelper(dbStore, searchEngine, false, true, nil) + th.InitLogin() + return th } func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper { @@ -220,7 +224,9 @@ func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelpe dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() searchEngine := mainHelper.GetSearchEngine() - return setupTestHelper(dbStore, searchEngine, false, true, updateConfig) + th := setupTestHelper(dbStore, searchEngine, false, true, updateConfig) + th.InitLogin() + return th } func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper { @@ -283,7 +289,7 @@ var userCache struct { BasicUser2 *model.User } -func (me *TestHelper) InitBasic() *TestHelper { +func (me *TestHelper) InitLogin() *TestHelper { me.waitForConnectivity() // create users once and cache them because password hashing is slow @@ -318,9 +324,21 @@ func (me *TestHelper) InitBasic() *TestHelper { me.BasicUser.Password = "Pa$$word11" me.BasicUser2.Password = "Pa$$word11" - me.LoginSystemAdmin() - me.LoginTeamAdmin() + var wg sync.WaitGroup + wg.Add(2) + go func() { + me.LoginSystemAdmin() + wg.Done() + }() + go func() { + me.LoginTeamAdmin() + wg.Done() + }() + wg.Wait() + return me +} +func (me *TestHelper) InitBasic() *TestHelper { me.BasicTeam = me.CreateTeam() me.BasicChannel = me.CreatePublicChannel() me.BasicPrivateChannel = me.CreatePrivateChannel() diff --git a/api4/bleve_test.go b/api4/bleve_test.go index 3eab830f59..f5664680b4 100644 --- a/api4/bleve_test.go +++ b/api4/bleve_test.go @@ -10,7 +10,7 @@ import ( ) func TestBlevePurgeIndexes(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("as system user", func(t *testing.T) { diff --git a/api4/bot_test.go b/api4/bot_test.go index 19b6b501e0..8f3efa339a 100644 --- a/api4/bot_test.go +++ b/api4/bot_test.go @@ -20,7 +20,7 @@ import ( func TestCreateBot(t *testing.T) { t.Run("create bot without permissions", func(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { @@ -137,7 +137,7 @@ func TestCreateBot(t *testing.T) { func TestPatchBot(t *testing.T) { t.Run("patch non-existent bot", func(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions()) @@ -204,7 +204,7 @@ func TestPatchBot(t *testing.T) { }) t.Run("patch someone else's bot without permission", func(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions()) @@ -1278,7 +1278,7 @@ func TestSetBotIconImage(t *testing.T) { } func TestGetBotIconImage(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions()) @@ -1340,7 +1340,7 @@ func TestGetBotIconImage(t *testing.T) { } func TestDeleteBotIconImage(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions()) diff --git a/api4/brand_test.go b/api4/brand_test.go index c01074a46e..512f0c82af 100644 --- a/api4/brand_test.go +++ b/api4/brand_test.go @@ -12,7 +12,7 @@ import ( ) func TestGetBrandImage(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -28,7 +28,7 @@ func TestGetBrandImage(t *testing.T) { } func TestUploadBrandImage(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -55,7 +55,7 @@ func TestUploadBrandImage(t *testing.T) { } func TestDeleteBrandImage(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() data, err := testutils.ReadTestFile("test.png") diff --git a/api4/channel_test.go b/api4/channel_test.go index 24ccb2bcc4..4a2ab35504 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -3180,7 +3180,7 @@ func TestAutocompleteChannelsForSearchGuestUsers(t *testing.T) { } func TestUpdateChannelScheme(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicense("")) diff --git a/api4/cluster_test.go b/api4/cluster_test.go index 69f568980b..a245a4aacb 100644 --- a/api4/cluster_test.go +++ b/api4/cluster_test.go @@ -11,7 +11,7 @@ import ( ) func TestGetClusterStatus(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("as system user", func(t *testing.T) { diff --git a/api4/config_test.go b/api4/config_test.go index 6407c62d62..337aaa8c9f 100644 --- a/api4/config_test.go +++ b/api4/config_test.go @@ -15,7 +15,7 @@ import ( ) func TestGetConfig(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -54,7 +54,7 @@ func TestGetConfig(t *testing.T) { } func TestReloadConfig(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -80,7 +80,7 @@ func TestReloadConfig(t *testing.T) { } func TestUpdateConfig(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -179,7 +179,7 @@ func TestUpdateConfig(t *testing.T) { } func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() messageExportEnabled := *th.App.Config().MessageExportSettings.EnableExport @@ -247,7 +247,7 @@ func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) { } func TestUpdateConfigRestrictSystemAdmin(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true }) @@ -293,7 +293,7 @@ func TestGetEnvironmentConfig(t *testing.T) { defer os.Unsetenv("MM_SERVICESETTINGS_SITEURL") defer os.Unsetenv("MM_SERVICESETTINGS_ENABLECUSTOMEMOJI") - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("as system admin", func(t *testing.T) { @@ -350,7 +350,7 @@ func TestGetEnvironmentConfig(t *testing.T) { } func TestGetOldClientConfig(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() testKey := "supersecretkey" @@ -402,7 +402,7 @@ func TestGetOldClientConfig(t *testing.T) { } func TestPatchConfig(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("config is missing", func(t *testing.T) { diff --git a/api4/data_retention_test.go b/api4/data_retention_test.go index b068ad9322..80fe760768 100644 --- a/api4/data_retention_test.go +++ b/api4/data_retention_test.go @@ -8,7 +8,7 @@ import ( ) func TestDataRetentionGetPolicy(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() _, resp := th.Client.GetDataRetentionPolicy() diff --git a/api4/elasticsearch_test.go b/api4/elasticsearch_test.go index e3260c483b..1671c5c406 100644 --- a/api4/elasticsearch_test.go +++ b/api4/elasticsearch_test.go @@ -10,7 +10,7 @@ import ( ) func TestElasticsearchTest(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("as system user", func(t *testing.T) { @@ -32,7 +32,7 @@ func TestElasticsearchTest(t *testing.T) { } func TestElasticsearchPurgeIndexes(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("as system user", func(t *testing.T) { diff --git a/api4/group_test.go b/api4/group_test.go index 3ce54ba4e9..37703c6a98 100644 --- a/api4/group_test.go +++ b/api4/group_test.go @@ -15,7 +15,7 @@ import ( ) func TestGetGroup(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() id := model.NewId() @@ -60,7 +60,7 @@ func TestGetGroup(t *testing.T) { } func TestPatchGroup(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() id := model.NewId() @@ -408,7 +408,7 @@ func TestGetGroupChannel(t *testing.T) { } func TestGetGroupTeams(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() id := model.NewId() @@ -1073,7 +1073,7 @@ func TestGetGroupStats(t *testing.T) { } func TestGetGroupsGroupConstrainedParentTeam(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicense("ldap")) diff --git a/api4/handlers_test.go b/api4/handlers_test.go index fb076420e8..cc7d142fc8 100644 --- a/api4/handlers_test.go +++ b/api4/handlers_test.go @@ -65,7 +65,7 @@ func testAPIHandlerNoGzipMode(t *testing.T, name string, h http.Handler, token s } func TestAPIHandlersWithGzip(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() api := Init(th.Server, th.Server.AppOptions, th.Server.Router) diff --git a/api4/image_test.go b/api4/image_test.go index 0a6f18cbad..562a4bd4f9 100644 --- a/api4/image_test.go +++ b/api4/image_test.go @@ -17,7 +17,7 @@ import ( ) func TestGetImage(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() // Prevent the test client from following a redirect diff --git a/api4/job_test.go b/api4/job_test.go index 7c61bdf9a3..80275c5158 100644 --- a/api4/job_test.go +++ b/api4/job_test.go @@ -12,7 +12,7 @@ import ( ) func TestCreateJob(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() job := &model.Job{ @@ -39,7 +39,7 @@ func TestCreateJob(t *testing.T) { } func TestGetJob(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() job := &model.Job{ @@ -68,7 +68,7 @@ func TestGetJob(t *testing.T) { } func TestGetJobs(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() jobType := model.NewId() @@ -115,7 +115,7 @@ func TestGetJobs(t *testing.T) { } func TestGetJobsByType(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() jobType := model.NewId() @@ -173,7 +173,7 @@ func TestGetJobsByType(t *testing.T) { } func TestCancelJob(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() jobs := []*model.Job{ diff --git a/api4/ldap_test.go b/api4/ldap_test.go index 1e7418ddfc..298410eb56 100644 --- a/api4/ldap_test.go +++ b/api4/ldap_test.go @@ -12,7 +12,7 @@ import ( ) func TestTestLdap(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -37,7 +37,7 @@ func TestTestLdap(t *testing.T) { } func TestSyncLdap(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -59,7 +59,7 @@ func TestSyncLdap(t *testing.T) { } func TestGetLdapGroups(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() _, resp := th.Client.GetLdapGroups() @@ -74,7 +74,7 @@ func TestGetLdapGroups(t *testing.T) { func TestLinkLdapGroup(t *testing.T) { const entryUUID string = "foo" - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() _, resp := th.Client.LinkLdapGroup(entryUUID) @@ -87,7 +87,7 @@ func TestLinkLdapGroup(t *testing.T) { func TestUnlinkLdapGroup(t *testing.T) { const entryUUID string = "foo" - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() _, resp := th.Client.UnlinkLdapGroup(entryUUID) @@ -98,7 +98,7 @@ func TestUnlinkLdapGroup(t *testing.T) { } func TestMigrateIdLdap(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() _, resp := th.Client.MigrateIdLdap("objectGUID") diff --git a/api4/license_test.go b/api4/license_test.go index dbb23b3306..7053b1ee3a 100644 --- a/api4/license_test.go +++ b/api4/license_test.go @@ -13,7 +13,7 @@ import ( ) func TestGetOldClientLicense(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -44,7 +44,7 @@ func TestGetOldClientLicense(t *testing.T) { } func TestUploadLicenseFile(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client LocalClient := th.LocalClient @@ -78,7 +78,7 @@ func TestUploadLicenseFile(t *testing.T) { } func TestRemoveLicenseFile(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client LocalClient := th.LocalClient diff --git a/api4/oauth_test.go b/api4/oauth_test.go index d907a46e05..82d11912e5 100644 --- a/api4/oauth_test.go +++ b/api4/oauth_test.go @@ -14,7 +14,7 @@ import ( ) func TestCreateOAuthApp(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client AdminClient := th.SystemAdminClient @@ -188,7 +188,7 @@ func TestUpdateOAuthApp(t *testing.T) { } func TestGetOAuthApps(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client AdminClient := th.SystemAdminClient @@ -254,7 +254,7 @@ func TestGetOAuthApps(t *testing.T) { } func TestGetOAuthApp(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client AdminClient := th.SystemAdminClient @@ -318,7 +318,7 @@ func TestGetOAuthApp(t *testing.T) { } func TestGetOAuthAppInfo(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client AdminClient := th.SystemAdminClient @@ -382,7 +382,7 @@ func TestGetOAuthAppInfo(t *testing.T) { } func TestDeleteOAuthApp(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client AdminClient := th.SystemAdminClient @@ -449,7 +449,7 @@ func TestDeleteOAuthApp(t *testing.T) { } func TestRegenerateOAuthAppSecret(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client AdminClient := th.SystemAdminClient diff --git a/api4/plugin_test.go b/api4/plugin_test.go index 24e8a16390..03d2503839 100644 --- a/api4/plugin_test.go +++ b/api4/plugin_test.go @@ -30,7 +30,7 @@ import ( ) func TestPlugin(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -273,7 +273,7 @@ func TestPlugin(t *testing.T) { } func TestNotifyClusterPluginEvent(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() testCluster := &testlib.FakeClusterInterface{} @@ -384,11 +384,11 @@ func TestDisableOnRemove(t *testing.T) { }, } + th := Setup(t).InitBasic() + defer th.TearDown() + for _, tc := range testCases { t.Run(tc.Description, func(t *testing.T) { - th := Setup(t).InitBasic() - defer th.TearDown() - th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = true @@ -470,7 +470,7 @@ func TestDisableOnRemove(t *testing.T) { } func TestGetMarketplacePlugins(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { @@ -666,7 +666,7 @@ func TestGetInstalledMarketplacePlugins(t *testing.T) { require.NoError(t, err) t.Run("marketplace client returns not-installed plugin", func(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { @@ -728,7 +728,7 @@ func TestGetInstalledMarketplacePlugins(t *testing.T) { }) t.Run("marketplace client returns installed plugin", func(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { @@ -908,7 +908,7 @@ func TestSearchGetMarketplacePlugins(t *testing.T) { } func TestGetLocalPluginInMarketplace(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() samplePlugins := []*model.MarketplacePlugin{ @@ -1072,7 +1072,7 @@ func TestGetLocalPluginInMarketplace(t *testing.T) { } func TestGetPrepackagedPluginInMarketplace(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() marketplacePlugins := []*model.MarketplacePlugin{ diff --git a/api4/role_test.go b/api4/role_test.go index be7de78e19..53f0b40c6e 100644 --- a/api4/role_test.go +++ b/api4/role_test.go @@ -14,7 +14,7 @@ import ( ) func TestGetRole(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() role := &model.Role{ @@ -51,7 +51,7 @@ func TestGetRole(t *testing.T) { } func TestGetRoleByName(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() role := &model.Role{ @@ -88,7 +88,7 @@ func TestGetRoleByName(t *testing.T) { } func TestGetRolesByNames(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() role1 := &model.Role{ @@ -158,7 +158,7 @@ func TestGetRolesByNames(t *testing.T) { } func TestPatchRole(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() role := &model.Role{ diff --git a/api4/saml_test.go b/api4/saml_test.go index ecad799217..2625cb4eab 100644 --- a/api4/saml_test.go +++ b/api4/saml_test.go @@ -13,7 +13,7 @@ import ( ) func TestGetSamlMetadata(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client diff --git a/api4/scheme_test.go b/api4/scheme_test.go index 16155e5652..6d5997c5e8 100644 --- a/api4/scheme_test.go +++ b/api4/scheme_test.go @@ -14,7 +14,7 @@ import ( ) func TestCreateScheme(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes")) @@ -472,7 +472,7 @@ func TestGetChannelsForScheme(t *testing.T) { } func TestPatchScheme(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes")) @@ -579,7 +579,7 @@ func TestPatchScheme(t *testing.T) { } func TestDeleteScheme(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("ValidTeamScheme", func(t *testing.T) { diff --git a/api4/system_test.go b/api4/system_test.go index 391ac0c6b9..0619000339 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -20,7 +20,7 @@ import ( ) func TestGetPing(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("basic ping", func(t *testing.T) { @@ -66,7 +66,7 @@ func TestGetPing(t *testing.T) { } func TestGetAudits(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -94,7 +94,7 @@ func TestGetAudits(t *testing.T) { } func TestEmailTest(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -148,7 +148,7 @@ func TestEmailTest(t *testing.T) { } func TestSiteURLTest(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -189,7 +189,7 @@ func TestSiteURLTest(t *testing.T) { } func TestDatabaseRecycle(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -212,7 +212,7 @@ func TestDatabaseRecycle(t *testing.T) { } func TestInvalidateCaches(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -238,7 +238,7 @@ func TestInvalidateCaches(t *testing.T) { } func TestGetLogs(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() for i := 0; i < 20; i++ { @@ -272,7 +272,7 @@ func TestGetLogs(t *testing.T) { } func TestPostLog(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -381,7 +381,7 @@ func TestGetAnalyticsOld(t *testing.T) { } func TestS3TestConnection(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -450,7 +450,7 @@ func TestS3TestConnection(t *testing.T) { } func TestSupportedTimezones(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -473,7 +473,7 @@ func TestRedirectLocation(t *testing.T) { mockBitlyLink := testServer.URL - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client enableLinkPreviews := *th.App.Config().ServiceSettings.EnableLinkPreviews @@ -518,7 +518,7 @@ func TestRedirectLocation(t *testing.T) { } func TestSetServerBusy(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() const secs = 30 @@ -539,7 +539,7 @@ func TestSetServerBusy(t *testing.T) { } func TestSetServerBusyInvalidParam(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) { @@ -554,7 +554,7 @@ func TestSetServerBusyInvalidParam(t *testing.T) { } func TestClearServerBusy(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().Busy.Set(time.Second * 30) @@ -575,7 +575,7 @@ func TestClearServerBusy(t *testing.T) { } func TestGetServerBusy(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().Busy.Set(time.Second * 30) @@ -594,7 +594,7 @@ func TestGetServerBusy(t *testing.T) { } func TestGetServerBusyExpires(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().Busy.Set(time.Second * 30) @@ -612,7 +612,7 @@ func TestGetServerBusyExpires(t *testing.T) { } func TestServerBusy503(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().Busy.Set(time.Second * 30) @@ -651,7 +651,7 @@ func TestServerBusy503(t *testing.T) { } func TestPushNotificationAck(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) api := Init(th.Server, th.Server.AppOptions, th.Server.Router) session, _ := th.App.GetSession(th.Client.AuthToken) defer th.TearDown() diff --git a/api4/team_test.go b/api4/team_test.go index d2e716b176..8b950f0aa3 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -22,7 +22,7 @@ import ( ) func TestCreateTeam(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -84,7 +84,7 @@ func TestCreateTeam(t *testing.T) { } func TestCreateTeamSanitization(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() // Non-admin users can create a team, but they become a team admin by doing so @@ -253,7 +253,7 @@ func TestGetTeamUnread(t *testing.T) { } func TestUpdateTeam(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { @@ -351,7 +351,7 @@ func TestUpdateTeam(t *testing.T) { } func TestUpdateTeamSanitization(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() team, resp := th.Client.CreateTeam(&model.Team{ @@ -470,7 +470,7 @@ func TestPatchTeam(t *testing.T) { } func TestRestoreTeam(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -539,7 +539,7 @@ func TestRestoreTeam(t *testing.T) { } func TestPatchTeamSanitization(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() team, resp := th.Client.CreateTeam(&model.Team{ @@ -571,7 +571,7 @@ func TestPatchTeamSanitization(t *testing.T) { } func TestUpdateTeamPrivacy(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -648,7 +648,7 @@ func TestUpdateTeamPrivacy(t *testing.T) { } func TestTeamUnicodeNames(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -715,7 +715,7 @@ func TestTeamUnicodeNames(t *testing.T) { } func TestRegenerateTeamInviteId(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -770,7 +770,7 @@ func TestSoftDeleteTeam(t *testing.T) { } func TestPermanentDeleteTeam(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() enableAPITeamDeletion := *th.App.Config().ServiceSettings.EnableAPITeamDeletion @@ -987,7 +987,7 @@ func TestGetAllTeams(t *testing.T) { } func TestGetAllTeamsSanitization(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() team, resp := th.Client.CreateTeam(&model.Team{ @@ -1210,7 +1210,7 @@ func TestSearchAllTeams(t *testing.T) { } func TestSearchAllTeamsPaged(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() commonRandom := model.NewId() teams := [3]*model.Team{} @@ -3044,7 +3044,7 @@ func TestRemoveTeamIcon(t *testing.T) { } func TestUpdateTeamScheme(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicense("")) diff --git a/api4/user_test.go b/api4/user_test.go index e988a42a81..d97e5e1dc4 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -23,7 +23,7 @@ import ( ) func TestCreateUser(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID} @@ -80,7 +80,7 @@ func TestCreateUser(t *testing.T) { } func TestCreateUserInputFilter(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("DomainRestriction", func(t *testing.T) { @@ -580,7 +580,7 @@ func TestGetMe(t *testing.T) { } func TestGetUser(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() user := th.CreateUser() @@ -630,7 +630,7 @@ func TestGetUser(t *testing.T) { } func TestGetUserWithAcceptedTermsOfServiceForOtherUser(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() user := th.CreateUser() @@ -829,7 +829,7 @@ func TestGetUserByUsernameWithAcceptedTermsOfService(t *testing.T) { } func TestGetUserByEmail(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() user := th.CreateUser() @@ -1477,7 +1477,7 @@ func TestGetUsersByIds(t *testing.T) { func TestGetUsersByIdsWithOptions(t *testing.T) { t.Run("should only return specified users that have been updated since the given time", func(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() // Users before the timestamp shouldn't be returned @@ -1559,7 +1559,7 @@ func TestGetUsersByUsernames(t *testing.T) { } func TestGetTotalUsersStat(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() total, _ := th.Server.Store.User().Count(model.UserCountOptions{ @@ -1574,7 +1574,7 @@ func TestGetTotalUsersStat(t *testing.T) { } func TestUpdateUser(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() user := th.CreateUser() @@ -1737,7 +1737,7 @@ func TestPatchUser(t *testing.T) { } func TestUserUnicodeNames(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() Client := th.Client @@ -1800,7 +1800,7 @@ func TestUserUnicodeNames(t *testing.T) { } func TestUpdateUserAuth(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() team := th.CreateTeamWithClient(th.SystemAdminClient) @@ -2167,7 +2167,7 @@ func TestUpdateUserActive(t *testing.T) { } func TestGetUsers(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() rusers, resp := th.Client.GetUsers(0, 60, "") @@ -3060,7 +3060,7 @@ func TestGetUserAudits(t *testing.T) { } func TestVerifyUserEmail(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() email := th.GenerateTestEmail() @@ -4491,7 +4491,7 @@ func TestUserAccessTokenDisableConfig(t *testing.T) { } func TestUserAccessTokenDisableConfigBotsExcluded(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { @@ -4872,7 +4872,7 @@ func TestPromoteGuestToUser(t *testing.T) { } func TestVerifyUserEmailWithoutToken(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() t.Run("Should verify a new user", func(t *testing.T) { diff --git a/api4/websocket_test.go b/api4/websocket_test.go index bc6d627b4b..e24e9e1fb9 100644 --- a/api4/websocket_test.go +++ b/api4/websocket_test.go @@ -63,7 +63,7 @@ func TestWebSocket(t *testing.T) { } func TestWebSocketTrailingSlash(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() url := fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port) @@ -196,7 +196,7 @@ func TestCreateDirectChannelWithSocket(t *testing.T) { } func TestWebsocketOriginSecurity(t *testing.T) { - th := Setup(t).InitBasic() + th := Setup(t) defer th.TearDown() url := fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port)