Remove remaining t.Fatal from the codebase (#13876)
* Remove remaining t.Fatal from the codebase * Fix job_store test * Address review comments * Remove comments
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
17523fa5d9
Коммит
84f45634a8
@@ -169,7 +169,7 @@ func (me *TestHelper) ShutdownApp() {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(30 * time.Second):
|
||||
// panic instead of t.Fatal to terminate all tests in this package, otherwise the
|
||||
// panic instead of fatal to terminate all tests in this package, otherwise the
|
||||
// still running App could spuriously fail subsequent tests.
|
||||
panic("failed to shutdown App within 30 seconds")
|
||||
}
|
||||
|
||||
@@ -636,9 +636,7 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
|
||||
|
||||
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
if len(channels) != numInitialChannelsForTeam+3 {
|
||||
t.Fatal("should be 3 deleted channels")
|
||||
}
|
||||
require.Len(t, channels, numInitialChannelsForTeam+3)
|
||||
|
||||
// Login as different user and create private channel
|
||||
th.LoginBasic2()
|
||||
@@ -650,9 +648,7 @@ func TestGetDeletedChannelsForTeam(t *testing.T) {
|
||||
|
||||
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
if len(channels) != numInitialChannelsForTeam+3 {
|
||||
t.Fatal("should still be 3 deleted channels", len(channels), numInitialChannelsForTeam+3)
|
||||
}
|
||||
require.Len(t, channels, numInitialChannelsForTeam+3)
|
||||
|
||||
channels, resp = Client.GetDeletedChannelsForTeam(team.Id, 0, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
@@ -976,18 +972,14 @@ func TestSearchArchivedChannels(t *testing.T) {
|
||||
|
||||
found := false
|
||||
for _, c := range channels {
|
||||
if c.Type != model.CHANNEL_OPEN {
|
||||
t.Fatal("should only return public channels")
|
||||
}
|
||||
require.Equal(t, model.CHANNEL_OPEN, c.Type)
|
||||
|
||||
if c.Id == th.BasicChannel.Id {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatal("didn't find channel")
|
||||
}
|
||||
require.True(t, found)
|
||||
|
||||
search.Term = th.BasicPrivateChannel.Name
|
||||
Client.DeleteChannel(th.BasicPrivateChannel.Id)
|
||||
@@ -1002,9 +994,7 @@ func TestSearchArchivedChannels(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Fatal("couldn't find private channel")
|
||||
}
|
||||
require.True(t, found)
|
||||
|
||||
search.Term = ""
|
||||
_, resp = Client.SearchArchivedChannels(th.BasicTeam.Id, search)
|
||||
|
||||
@@ -317,13 +317,8 @@ func TestGetOldClientConfig(t *testing.T) {
|
||||
config, resp := Client.GetOldClientConfig("")
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(config["Version"]) == 0 {
|
||||
t.Fatal("config not returned correctly")
|
||||
}
|
||||
|
||||
if config["GoogleDeveloperKey"] != testKey {
|
||||
t.Fatal("config missing developer key")
|
||||
}
|
||||
require.NotEmpty(t, config["Version"], "config not returned correctly")
|
||||
require.Equal(t, testKey, config["GoogleDeveloperKey"])
|
||||
})
|
||||
|
||||
t.Run("without session", func(t *testing.T) {
|
||||
@@ -336,29 +331,24 @@ func TestGetOldClientConfig(t *testing.T) {
|
||||
config, resp := Client.GetOldClientConfig("")
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(config["Version"]) == 0 {
|
||||
t.Fatal("config not returned correctly")
|
||||
}
|
||||
|
||||
if _, ok := config["GoogleDeveloperKey"]; ok {
|
||||
t.Fatal("config should be missing developer key")
|
||||
}
|
||||
require.NotEmpty(t, config["Version"], "config not returned correctly")
|
||||
require.Empty(t, config["GoogleDeveloperKey"], "config should be missing developer key")
|
||||
})
|
||||
|
||||
t.Run("missing format", func(t *testing.T) {
|
||||
Client := th.Client
|
||||
|
||||
if _, err := Client.DoApiGet("/config/client", ""); err == nil || err.StatusCode != http.StatusNotImplemented {
|
||||
t.Fatal("should have errored with 501")
|
||||
}
|
||||
_, err := Client.DoApiGet("/config/client", "")
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, http.StatusNotImplemented, err.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("invalid format", func(t *testing.T) {
|
||||
Client := th.Client
|
||||
|
||||
if _, err := Client.DoApiGet("/config/client?format=junk", ""); err == nil || err.StatusCode != http.StatusBadRequest {
|
||||
t.Fatal("should have errored with 400")
|
||||
}
|
||||
_, err := Client.DoApiGet("/config/client?format=junk", "")
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, http.StatusBadRequest, err.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@ func TestGetOldClientLicense(t *testing.T) {
|
||||
license, resp = th.SystemAdminClient.GetOldClientLicense("")
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(license["IsLicensed"]) == 0 {
|
||||
t.Fatal("license not returned correctly")
|
||||
}
|
||||
require.NotEmpty(t, license["IsLicensed"], "license not returned correctly")
|
||||
}
|
||||
|
||||
func TestUploadLicenseFile(t *testing.T) {
|
||||
@@ -53,17 +51,13 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
ok, resp := Client.UploadLicenseFile([]byte{})
|
||||
CheckForbiddenStatus(t, resp)
|
||||
if ok {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
require.False(t, ok)
|
||||
})
|
||||
|
||||
t.Run("as system admin user", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.UploadLicenseFile([]byte{})
|
||||
CheckBadRequestStatus(t, resp)
|
||||
if ok {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
require.False(t, ok)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin user", func(t *testing.T) {
|
||||
@@ -71,9 +65,7 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
|
||||
ok, resp := th.SystemAdminClient.UploadLicenseFile([]byte{})
|
||||
CheckForbiddenStatus(t, resp)
|
||||
if ok {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
require.False(t, ok)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -85,17 +77,13 @@ func TestRemoveLicenseFile(t *testing.T) {
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
ok, resp := Client.RemoveLicenseFile()
|
||||
CheckForbiddenStatus(t, resp)
|
||||
if ok {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
require.False(t, ok)
|
||||
})
|
||||
|
||||
t.Run("as system admin user", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.RemoveLicenseFile()
|
||||
CheckNoError(t, resp)
|
||||
if !ok {
|
||||
t.Fatal("should pass")
|
||||
}
|
||||
require.True(t, ok)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin user", func(t *testing.T) {
|
||||
@@ -103,8 +91,6 @@ func TestRemoveLicenseFile(t *testing.T) {
|
||||
|
||||
ok, resp := th.SystemAdminClient.RemoveLicenseFile()
|
||||
CheckForbiddenStatus(t, resp)
|
||||
if ok {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
require.False(t, ok)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -328,9 +328,7 @@ func TestDeletePreferences(t *testing.T) {
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
prefs, _ = Client.GetPreferences(th.BasicUser.Id)
|
||||
if len(prefs) != originalCount {
|
||||
t.Fatal("should've deleted preferences")
|
||||
}
|
||||
require.Len(t, prefs, originalCount, "should've deleted preferences")
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.DeletePreferences(th.BasicUser.Id, &preferences)
|
||||
@@ -358,15 +356,12 @@ func TestDeletePreferencesWebsocket(t *testing.T) {
|
||||
CheckNoError(t, resp)
|
||||
|
||||
WebSocketClient, err := th.CreateWebSocketClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, err)
|
||||
|
||||
WebSocketClient.Listen()
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
if resp := <-WebSocketClient.ResponseChannel; resp.Status != model.STATUS_OK {
|
||||
t.Fatal("should have responded OK to authentication challenge")
|
||||
}
|
||||
wsResp := <-WebSocketClient.ResponseChannel
|
||||
require.Equal(t, model.STATUS_OK, wsResp.Status, "should have responded OK to authentication challenge")
|
||||
|
||||
_, resp = th.Client.DeletePreferences(userId, preferences)
|
||||
CheckNoError(t, resp)
|
||||
@@ -383,19 +378,17 @@ func TestDeletePreferencesWebsocket(t *testing.T) {
|
||||
}
|
||||
|
||||
received, err := model.PreferencesFromJson(strings.NewReader(event.GetData()["preferences"].(string)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Nil(t, err)
|
||||
|
||||
for i, preference := range *preferences {
|
||||
if preference.UserId != received[i].UserId || preference.Category != received[i].Category || preference.Name != received[i].Name {
|
||||
t.Fatal("received incorrect preference")
|
||||
}
|
||||
require.Equal(t, preference.UserId, received[i].UserId)
|
||||
require.Equal(t, preference.Category, received[i].Category)
|
||||
require.Equal(t, preference.Name, received[i].Name)
|
||||
}
|
||||
|
||||
waiting = false
|
||||
case <-timeout:
|
||||
t.Fatal("timed out waiting for preference delete event")
|
||||
require.Fail(t, "timed out waiting for preference delete event")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1681,7 +1681,7 @@ func assertExpectedWebsocketEvent(t *testing.T, client *model.WebSocketClient, e
|
||||
return
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("failed to receive expected event %s", model.WEBSOCKET_EVENT_USER_UPDATED)
|
||||
require.Failf(t, "failed to receive expected event %s", model.WEBSOCKET_EVENT_USER_UPDATED)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2713,7 +2713,7 @@ func TestSetProfileImage(t *testing.T) {
|
||||
} else if resp.StatusCode == http.StatusUnauthorized {
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
} else {
|
||||
t.Fatal("Should have failed either forbidden or unauthorized")
|
||||
require.Fail(t, "Should have failed either forbidden or unauthorized")
|
||||
}
|
||||
|
||||
buser, err := th.App.GetUser(user.Id)
|
||||
@@ -2753,7 +2753,7 @@ func TestSetDefaultProfileImage(t *testing.T) {
|
||||
} else if resp.StatusCode == http.StatusUnauthorized {
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
} else {
|
||||
t.Fatal("Should have failed either forbidden or unauthorized")
|
||||
require.Fail(t, "Should have failed either forbidden or unauthorized")
|
||||
}
|
||||
|
||||
_, resp = th.SystemAdminClient.SetDefaultProfileImage(user.Id)
|
||||
|
||||
Ссылка в новой задаче
Block a user