Replacing require.nil in api layer (#16906)

* Replacing require.nil in api layer

* Fixing some tests

* Fixing tests

* Addressing PR review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2021-02-17 09:52:18 +01:00
коммит произвёл GitHub
родитель 9992a27a90
Коммит 31a80a5351
22 изменённых файлов: 226 добавлений и 227 удалений

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

@@ -1231,10 +1231,10 @@ func TestSetBotIconImage(t *testing.T) {
defer th.App.PermanentDeleteBot(bot.UserId)
badData, err := testutils.ReadTestFile("test.png")
require.Nil(t, err)
require.NoError(t, err)
goodData, err := testutils.ReadTestFile("test.svg")
require.Nil(t, err)
require.NoError(t, err)
// SetBotIconImage only allowed for bots
_, resp = th.SystemAdminClient.SetBotIconImage(user.Id, goodData)
@@ -1268,14 +1268,14 @@ func TestSetBotIconImage(t *testing.T) {
CheckNoError(t, resp)
fpath := fmt.Sprintf("/bots/%v/icon.svg", bot.UserId)
actualData, err := th.App.ReadFile(fpath)
require.Nil(t, err)
actualData, appErr := th.App.ReadFile(fpath)
require.Nil(t, appErr)
require.NotNil(t, actualData)
require.Equal(t, goodData, actualData)
info := &model.FileInfo{Path: fpath}
err = th.cleanupTestFile(info)
require.Nil(t, err)
require.NoError(t, err)
}
func TestGetBotIconImage(t *testing.T) {
@@ -1315,8 +1315,8 @@ func TestGetBotIconImage(t *testing.T) {
svgFile.Seek(0, 0)
fpath := fmt.Sprintf("/bots/%v/icon.svg", bot.UserId)
_, err = th.App.WriteFile(svgFile, fpath)
require.Nil(t, err)
_, appErr := th.App.WriteFile(svgFile, fpath)
require.Nil(t, appErr)
data, resp = th.Client.GetBotIconImage(bot.UserId)
CheckNoError(t, resp)
@@ -1337,7 +1337,7 @@ func TestGetBotIconImage(t *testing.T) {
info := &model.FileInfo{Path: "/bots/" + bot.UserId + "/icon.svg"}
err = th.cleanupTestFile(info)
require.Nil(t, err)
require.NoError(t, err)
}
func TestDeleteBotIconImage(t *testing.T) {
@@ -1368,14 +1368,14 @@ func TestDeleteBotIconImage(t *testing.T) {
// Set an icon image
svgData, err := testutils.ReadTestFile("test.svg")
require.Nil(t, err)
require.NoError(t, err)
_, resp = th.Client.SetBotIconImage(bot.UserId, svgData)
CheckNoError(t, resp)
fpath := fmt.Sprintf("/bots/%v/icon.svg", bot.UserId)
exists, err := th.App.FileExists(fpath)
require.Nil(t, err)
exists, appErr := th.App.FileExists(fpath)
require.Nil(t, appErr)
require.True(t, exists, "icon.svg needs to exist for the user")
data, resp = th.Client.GetBotIconImage(bot.UserId)
@@ -1399,8 +1399,8 @@ func TestDeleteBotIconImage(t *testing.T) {
CheckUnauthorizedStatus(t, resp)
require.False(t, success)
exists, err = th.App.FileExists(fpath)
require.Nil(t, err)
exists, appErr = th.App.FileExists(fpath)
require.Nil(t, appErr)
require.False(t, exists, "icon.svg should not for the user")
}