From 9bc7af0c5704bbf73f8240b4569d5ea215352e39 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 2 Oct 2017 03:50:56 -0500 Subject: Don't use global app for api / api4 tests (#7528) * don't use global app for api / api4 tests * put sleep back. we're gonna have to do some goroutine wrangling * fix oauth test config assumptions * jobs package, i'm comin' for you next * app test fix * try increasing sleep a little --- api/admin_test.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'api/admin_test.go') diff --git a/api/admin_test.go b/api/admin_test.go index 8263ac038..dadc96c7d 100644 --- a/api/admin_test.go +++ b/api/admin_test.go @@ -8,13 +8,19 @@ import ( "strings" "testing" + "github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" ) +func init() { + app.UseGlobalApp = false +} + func TestGetLogs(t *testing.T) { th := Setup().InitSystemAdmin().InitBasic() + defer th.TearDown() if _, err := th.BasicClient.GetLogs(); err == nil { t.Fatal("Shouldn't have permissions") @@ -32,6 +38,7 @@ func TestGetClusterInfos(t *testing.T) { t.SkipNow() } th := Setup().InitSystemAdmin().InitBasic() + defer th.TearDown() if _, err := th.BasicClient.GetClusterStatus(); err == nil { t.Fatal("Shouldn't have permissions") @@ -44,6 +51,7 @@ func TestGetClusterInfos(t *testing.T) { func TestGetAllAudits(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.GetAllAudits(); err == nil { t.Fatal("Shouldn't have permissions") @@ -58,6 +66,7 @@ func TestGetAllAudits(t *testing.T) { func TestGetConfig(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.GetConfig(); err == nil { t.Fatal("Shouldn't have permissions") @@ -104,6 +113,7 @@ func TestGetConfig(t *testing.T) { func TestReloadConfig(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.ReloadConfig(); err == nil { t.Fatal("Shouldn't have permissions") @@ -119,6 +129,7 @@ func TestReloadConfig(t *testing.T) { func TestInvalidateAllCache(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.InvalidateAllCaches(); err == nil { t.Fatal("Shouldn't have permissions") @@ -131,6 +142,7 @@ func TestInvalidateAllCache(t *testing.T) { func TestSaveConfig(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.SaveConfig(utils.Cfg); err == nil { t.Fatal("Shouldn't have permissions") @@ -147,6 +159,7 @@ func TestSaveConfig(t *testing.T) { func TestRecycleDatabaseConnection(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.RecycleDatabaseConnection(); err == nil { t.Fatal("Shouldn't have permissions") @@ -159,6 +172,7 @@ func TestRecycleDatabaseConnection(t *testing.T) { func TestEmailTest(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() SendEmailNotifications := utils.Cfg.EmailSettings.SendEmailNotifications SMTPServer := utils.Cfg.EmailSettings.SMTPServer @@ -191,6 +205,7 @@ func TestEmailTest(t *testing.T) { func TestLdapTest(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.TestLdap(utils.Cfg); err == nil { t.Fatal("Shouldn't have permissions") @@ -203,6 +218,8 @@ func TestLdapTest(t *testing.T) { func TestGetTeamAnalyticsStandard(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() + th.CreatePrivateChannel(th.BasicClient, th.BasicTeam) if _, err := th.BasicClient.GetTeamAnalytics(th.BasicTeam.Id, "standard"); err == nil { @@ -432,6 +449,7 @@ func TestUserCountsWithPostsByDay(t *testing.T) { func TestGetTeamAnalyticsExtra(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() th.CreatePost(th.BasicClient, th.BasicChannel) @@ -568,6 +586,7 @@ func TestGetTeamAnalyticsExtra(t *testing.T) { func TestAdminResetMfa(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() if _, err := th.BasicClient.AdminResetMfa("12345678901234567890123456"); err == nil { t.Fatal("should have failed - not an admin") @@ -590,12 +609,14 @@ func TestAdminResetMfa(t *testing.T) { func TestAdminResetPassword(t *testing.T) { th := Setup().InitSystemAdmin() + defer th.TearDown() + Client := th.SystemAdminClient team := th.SystemAdminTeam user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) - LinkUserToTeam(user, team) + th.LinkUserToTeam(user, team) store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) if _, err := Client.AdminResetPassword("", "newpwd1"); err == nil { @@ -617,7 +638,7 @@ func TestAdminResetPassword(t *testing.T) { authData := model.NewId() user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", AuthData: &authData, AuthService: "random"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) - LinkUserToTeam(user2, team) + th.LinkUserToTeam(user2, team) store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) if _, err := Client.AdminResetPassword(user.Id, "newpwd1"); err != nil { @@ -635,6 +656,8 @@ func TestAdminResetPassword(t *testing.T) { func TestAdminLdapSyncNow(t *testing.T) { th := Setup().InitSystemAdmin() + defer th.TearDown() + Client := th.SystemAdminClient if _, err := Client.LdapSyncNow(); err != nil { @@ -645,6 +668,7 @@ func TestAdminLdapSyncNow(t *testing.T) { // Needs more work func TestGetRecentlyActiveUsers(t *testing.T) { th := Setup().InitBasic() + defer th.TearDown() if userMap, err := th.BasicClient.GetRecentlyActiveUsers(th.BasicTeam.Id); err != nil { t.Fatal(err) @@ -655,6 +679,8 @@ func TestGetRecentlyActiveUsers(t *testing.T) { func TestDisableAPIv3(t *testing.T) { th := Setup().InitBasic() + defer th.TearDown() + Client := th.BasicClient enableAPIv3 := *utils.Cfg.ServiceSettings.EnableAPIv3 -- cgit v1.2.3-1-g7c22