Remove remaining t.Fatal from the codebase (#13876)

* Remove remaining t.Fatal from the codebase

* Fix job_store test

* Address review comments

* Remove comments
Этот коммит содержится в:
Miguel de la Cruz
2020-02-13 17:53:23 +01:00
коммит произвёл GitHub
родитель 17523fa5d9
Коммит 84f45634a8
18 изменённых файлов: 119 добавлений и 229 удалений

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

@@ -405,7 +405,7 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
// the user leaves that channel
if err := th.App.LeaveChannel(publicChannel.Id, th.BasicUser.Id); err != nil {
t.Fatal("Failed to remove user from channel. Error: " + err.Message)
require.Fail(t, "Failed to remove user from channel. Error: " + err.Message)
}
histories = store.Must(th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)).([]*model.ChannelMemberHistoryResult)
assert.Len(t, histories, 1)
@@ -477,9 +477,8 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
// create a user and add it to a channel
user := th.CreateUser()
if _, err := th.App.AddTeamMember(th.BasicTeam.Id, user.Id); err != nil {
t.Fatal("Failed to add user to team. Error: " + err.Message)
}
_, err := th.App.AddTeamMember(th.BasicTeam.Id, user.Id)
require.Nil(t, err)
groupUserIds := make([]string, 0)
groupUserIds = append(groupUserIds, th.BasicUser.Id)
@@ -488,7 +487,7 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
userRequestorId := ""
postRootId := ""
_, err := th.App.AddChannelMember(user.Id, channel, userRequestorId, postRootId)
_, err = th.App.AddChannelMember(user.Id, channel, userRequestorId, postRootId)
require.Nil(t, err, "Failed to add user to channel.")
// there should be a ChannelMemberHistory record for the user

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

@@ -70,9 +70,8 @@ func TestCreateCommandPost(t *testing.T) {
skipSlackParsing := false
_, err := th.App.CreateCommandPost(post, th.BasicTeam.Id, resp, skipSlackParsing)
if err == nil || err.Id != "api.context.invalid_param.app_error" {
t.Fatal("should have failed - bad post type")
}
require.NotNil(t, err)
require.Equal(t, err.Id, "api.context.invalid_param.app_error")
}
func TestHandleCommandResponsePost(t *testing.T) {
@@ -208,9 +207,8 @@ func TestHandleCommandResponsePost(t *testing.T) {
args.UserId = th.BasicUser2.Id
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
if err == nil || err.Id != "api.command.command_post.forbidden.app_error" {
t.Fatal("should have failed - forbidden channel post")
}
require.NotNil(t, err)
require.Equal(t, err.Id, "api.command.command_post.forbidden.app_error")
// Test that /code text is not converted with the Slack text conversion.
command.Trigger = "code"
@@ -252,9 +250,8 @@ func TestHandleCommandResponse(t *testing.T) {
builtIn := true
_, err := th.App.HandleCommandResponse(command, args, resp, builtIn)
if err == nil || err.Id != "api.command.execute_command.create_post_failed.app_error" {
t.Fatal("should have failed - invalid post type")
}
require.NotNil(t, err)
require.Equal(t, err.Id, "api.command.execute_command.create_post_failed.app_error")
resp = &model.CommandResponse{
Text: "message 1",
@@ -277,9 +274,8 @@ func TestHandleCommandResponse(t *testing.T) {
}
_, err = th.App.HandleCommandResponse(command, args, resp, builtIn)
if err == nil || err.Id != "api.command.execute_command.create_post_failed.app_error" {
t.Fatal("should have failed - invalid post type on extra response")
}
require.NotNil(t, err)
require.Equal(t, err.Id, "api.command.execute_command.create_post_failed.app_error")
resp = &model.CommandResponse{
ExtraResponses: []*model.CommandResponse{

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

@@ -471,7 +471,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")
}

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

@@ -210,9 +210,7 @@ func TestPluginCommand(t *testing.T) {
}
th.App.RemovePlugin(pluginIds[0])
if killed {
t.Fatal("execute command appears to have deadlocked")
}
require.False(t, killed, "execute command appears to have deadlocked")
})
t.Run("error after plugin command unregistered", func(t *testing.T) {

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

@@ -6,6 +6,8 @@ package app
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestPluginShutdownTest(t *testing.T) {
@@ -67,6 +69,6 @@ func TestPluginShutdownTest(t *testing.T) {
select {
case <-done:
case <-time.After(15 * time.Second):
t.Fatal("failed to force plugin shutdown after 10 seconds")
require.Fail(t, "failed to force plugin shutdown after 10 seconds")
}
}

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

@@ -623,7 +623,7 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
assert.Nil(t, webhookPost.Props["override_username"])
}
case <-time.After(5 * time.Second):
t.Fatal("Timeout, webhook response not created as post")
require.Fail(t, "Timeout, webhook response not created as post")
}
})