* api4: fix TestGetUsersNotInTeam assertions

This test was relying on data from a previous test run. With the data cleared before each test, the assertions much match reality.

* *testlib: always InitSystemAdmin

Some tests implicitly relied on the basic user having system
administrator privileges because it was the first user created as such.
Eliminate `InitSystemAdmin` and explicitly create the system admin user
instead to avoid this ambiguity going forward.

* *testlib: drop all tables before each test

* api4: split up TestChannelDelete to avoid duplicate InitBasic

* api4: teardown in TestResetPassword, for when this test comes back

* invalidate cache on DropAllTables

This is necessary since the test store persists across tests.

* disable parallel tests

While tests within a package must be explicitly parallelized using `t.Parallel()`, tests across packages are run in parallel by default.  This causes problems given that the tests all currently share the same database instance.

Unfortunately, this also means that running the tests is much slower, but we can return to this later.
Этот коммит содержится в:
Jesse Hallam
2018-11-20 20:16:25 -05:00
коммит произвёл Joram Wilander
родитель 2555a5d45d
Коммит a78913178c
35 изменённых файлов: 271 добавлений и 327 удалений

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

@@ -17,7 +17,7 @@ import (
)
func TestCreateUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
AdminClient := th.SystemAdminClient
@@ -93,7 +93,7 @@ func TestCreateUser(t *testing.T) {
}
func TestCreateUserWithToken(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -232,7 +232,7 @@ func TestCreateUserWithToken(t *testing.T) {
}
func TestCreateUserWithInviteId(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
AdminClient := th.SystemAdminClient
@@ -353,7 +353,7 @@ func TestGetMe(t *testing.T) {
}
func TestGetUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -424,7 +424,7 @@ func TestGetUser(t *testing.T) {
}
func TestGetUserByUsername(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -492,7 +492,7 @@ func TestGetUserByUsername(t *testing.T) {
}
func TestGetUserByEmail(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -557,7 +557,7 @@ func TestGetUserByEmail(t *testing.T) {
}
func TestSearchUsers(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -747,7 +747,7 @@ func findUserInList(id string, users []*model.User) bool {
}
func TestAutocompleteUsers(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
teamId := th.BasicTeam.Id
@@ -880,7 +880,7 @@ func TestAutocompleteUsers(t *testing.T) {
}
func TestGetProfileImage(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
user := th.BasicUser
@@ -984,7 +984,7 @@ func TestGetUsersByUsernames(t *testing.T) {
}
func TestGetTotalUsersStat(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -999,7 +999,7 @@ func TestGetTotalUsersStat(t *testing.T) {
}
func TestUpdateUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1064,7 +1064,7 @@ func TestUpdateUser(t *testing.T) {
}
func TestPatchUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1160,7 +1160,7 @@ func TestPatchUser(t *testing.T) {
}
func TestUpdateUserAuth(t *testing.T) {
th := Setup().InitSystemAdmin().InitBasic()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.SystemAdminClient
@@ -1222,7 +1222,7 @@ func TestUpdateUserAuth(t *testing.T) {
}
func TestDeleteUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1254,7 +1254,7 @@ func TestDeleteUser(t *testing.T) {
}
func TestUpdateUserRoles(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1309,7 +1309,7 @@ func assertWebsocketEventUserUpdatedWithEmail(t *testing.T, client *model.WebSoc
func TestUpdateUserActive(t *testing.T) {
t.Run("basic tests", func(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1376,7 +1376,7 @@ func TestUpdateUserActive(t *testing.T) {
})
t.Run("websocket events", func(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
SystemAdminClient := th.SystemAdminClient
@@ -1535,7 +1535,7 @@ func TestGetRecentlyActiveUsersInTeam(t *testing.T) {
}
func TestGetUsersWithoutTeam(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
SystemAdminClient := th.SystemAdminClient
@@ -1585,7 +1585,7 @@ func TestGetUsersWithoutTeam(t *testing.T) {
}
func TestGetUsersInTeam(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
teamId := th.BasicTeam.Id
@@ -1631,7 +1631,7 @@ func TestGetUsersInTeam(t *testing.T) {
}
func TestGetUsersNotInTeam(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
teamId := th.BasicTeam.Id
@@ -1641,27 +1641,22 @@ func TestGetUsersNotInTeam(t *testing.T) {
for _, u := range rusers {
CheckUserSanitization(t, u)
}
require.Len(t, rusers, 1, "should be 1 user in total")
rusers, resp = Client.GetUsersNotInTeam(teamId, 0, 60, resp.Etag)
CheckEtag(t, rusers, resp)
rusers, resp = Client.GetUsersNotInTeam(teamId, 0, 1, "")
CheckNoError(t, resp)
if len(rusers) != 1 {
t.Fatal("should be 1 per page")
}
require.Len(t, rusers, 1, "should be 1 per page")
rusers, resp = Client.GetUsersNotInTeam(teamId, 1, 1, "")
CheckNoError(t, resp)
if len(rusers) != 1 {
t.Fatal("should be 1 per page")
}
require.Len(t, rusers, 0, "should be no users")
rusers, resp = Client.GetUsersNotInTeam(teamId, 10000, 100, "")
CheckNoError(t, resp)
if len(rusers) != 0 {
t.Fatal("should be no users")
}
require.Len(t, rusers, 0, "should be no users")
Client.Logout()
_, resp = Client.GetUsersNotInTeam(teamId, 0, 60, "")
@@ -1677,7 +1672,7 @@ func TestGetUsersNotInTeam(t *testing.T) {
}
func TestGetUsersInChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
channelId := th.BasicChannel.Id
@@ -1720,7 +1715,7 @@ func TestGetUsersInChannel(t *testing.T) {
}
func TestGetUsersNotInChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
teamId := th.BasicTeam.Id
@@ -1761,7 +1756,7 @@ func TestGetUsersNotInChannel(t *testing.T) {
}
func TestUpdateUserMfa(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1777,7 +1772,7 @@ func TestUpdateUserMfa(t *testing.T) {
}
func TestCheckUserMfa(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1823,7 +1818,7 @@ func TestCheckUserMfa(t *testing.T) {
}
func TestGenerateMfaSecret(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1856,7 +1851,7 @@ func TestGenerateMfaSecret(t *testing.T) {
}
func TestUpdateUserPassword(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -1925,6 +1920,7 @@ func TestUpdateUserPassword(t *testing.T) {
/*func TestResetPassword(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
Client.Logout()
user := th.BasicUser
@@ -2009,7 +2005,7 @@ func TestUpdateUserPassword(t *testing.T) {
}*/
func TestGetSessions(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -2049,7 +2045,7 @@ func TestGetSessions(t *testing.T) {
}
func TestRevokeSessions(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -2122,8 +2118,6 @@ func TestRevokeAllSessions(t *testing.T) {
_, resp := Client.RevokeAllSessions(th.BasicUser2.Id)
CheckForbiddenStatus(t, resp)
th.InitSystemAdmin()
_, resp = Client.RevokeAllSessions("junk" + user.Id)
CheckBadRequestStatus(t, resp)
@@ -2187,7 +2181,7 @@ func TestAttachDeviceId(t *testing.T) {
}
func TestGetUserAudits(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
user := th.BasicUser
@@ -2260,7 +2254,7 @@ func TestSendVerificationEmail(t *testing.T) {
}
func TestSetProfileImage(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
user := th.BasicUser
@@ -2311,7 +2305,7 @@ func TestSetProfileImage(t *testing.T) {
}
func TestSetDefaultProfileImage(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
user := th.BasicUser
@@ -2407,7 +2401,7 @@ func TestCBALogin(t *testing.T) {
}
func TestSwitchAccount(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -2535,7 +2529,7 @@ func TestSwitchAccount(t *testing.T) {
}
func TestCreateUserAccessToken(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
AdminClient := th.SystemAdminClient
@@ -2616,7 +2610,7 @@ func TestCreateUserAccessToken(t *testing.T) {
}
func TestGetUserAccessToken(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
AdminClient := th.SystemAdminClient
@@ -2700,7 +2694,7 @@ func TestGetUserAccessToken(t *testing.T) {
}
func TestSearchUserAccessToken(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
AdminClient := th.SystemAdminClient
@@ -2746,7 +2740,7 @@ func TestSearchUserAccessToken(t *testing.T) {
}
func TestRevokeUserAccessToken(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
AdminClient := th.SystemAdminClient
@@ -2790,7 +2784,7 @@ func TestRevokeUserAccessToken(t *testing.T) {
}
func TestDisableUserAccessToken(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
AdminClient := th.SystemAdminClient
@@ -2834,7 +2828,7 @@ func TestDisableUserAccessToken(t *testing.T) {
}
func TestEnableUserAccessToken(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -2876,7 +2870,7 @@ func TestEnableUserAccessToken(t *testing.T) {
}
func TestUserAccessTokenInactiveUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -2899,7 +2893,7 @@ func TestUserAccessTokenInactiveUser(t *testing.T) {
}
func TestUserAccessTokenDisableConfig(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
@@ -3092,7 +3086,6 @@ func TestRegisterTermsOfServiceAction(t *testing.T) {
}
}
func TestGetUserTermsOfService(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()