[MM-29049] Fix remaining errcheck errors in app, api4 and web package (#31307)

Co-authored-by: Claude <noreply@anthropic.com>
Этот коммит содержится в:
Ben Schumacher
2025-06-06 07:44:43 +02:00
коммит произвёл GitHub
родитель 7e013f4c1a
Коммит e3452dce94
12 изменённых файлов: 188 добавлений и 115 удалений

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

@@ -157,7 +157,8 @@ func TestUpdateCommand(t *testing.T) {
require.Error(t, err)
CheckNotFoundStatus(t, resp)
})
th.SystemAdminClient.Logout(context.Background())
_, err := th.SystemAdminClient.Logout(context.Background())
require.NoError(t, err)
_, resp, err := th.SystemAdminClient.UpdateCommand(context.Background(), cmd2)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
@@ -216,7 +217,8 @@ func TestMoveCommand(t *testing.T) {
require.Error(t, err)
CheckNotFoundStatus(t, resp)
th.SystemAdminClient.Logout(context.Background())
_, err = th.SystemAdminClient.Logout(context.Background())
require.NoError(t, err)
resp, err = th.SystemAdminClient.MoveCommand(context.Background(), newTeam.Id, rcmd2.Id)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
@@ -275,7 +277,8 @@ func TestDeleteCommand(t *testing.T) {
require.Error(t, err)
CheckNotFoundStatus(t, resp)
th.SystemAdminClient.Logout(context.Background())
_, err = th.SystemAdminClient.Logout(context.Background())
require.NoError(t, err)
resp, err = th.SystemAdminClient.DeleteCommand(context.Background(), rcmd2.Id)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
@@ -300,10 +303,8 @@ func TestListCommands(t *testing.T) {
Method: model.CommandMethodPost,
Trigger: "custom_command",
}
_, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
require.NoError(t, err)
_, _, rootErr := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
require.NoError(t, rootErr)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
listCommands, _, err := c.ListCommands(context.Background(), th.BasicTeam.Id, false)
require.NoError(t, err)
@@ -355,10 +356,13 @@ func TestListCommands(t *testing.T) {
})
t.Run("NoMember", func(t *testing.T) {
client.Logout(context.Background())
_, err := client.Logout(context.Background())
require.NoError(t, err)
user := th.CreateUser()
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
client.Login(context.Background(), user.Email, user.Password)
_, _, err = client.Login(context.Background(), user.Email, user.Password)
require.NoError(t, err)
_, resp, err := client.ListCommands(context.Background(), th.BasicTeam.Id, false)
require.Error(t, err)
CheckForbiddenStatus(t, resp)
@@ -368,7 +372,8 @@ func TestListCommands(t *testing.T) {
})
t.Run("NotLoggedIn", func(t *testing.T) {
client.Logout(context.Background())
_, err := client.Logout(context.Background())
require.NoError(t, err)
_, resp, err := client.ListCommands(context.Background(), th.BasicTeam.Id, false)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
@@ -432,17 +437,21 @@ func TestListAutocompleteCommands(t *testing.T) {
})
t.Run("NoMember", func(t *testing.T) {
client.Logout(context.Background())
_, err := client.Logout(context.Background())
require.NoError(t, err)
user := th.CreateUser()
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
client.Login(context.Background(), user.Email, user.Password)
_, _, err = client.Login(context.Background(), user.Email, user.Password)
require.NoError(t, err)
_, resp, err := client.ListAutocompleteCommands(context.Background(), th.BasicTeam.Id)
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
t.Run("NotLoggedIn", func(t *testing.T) {
client.Logout(context.Background())
_, err := client.Logout(context.Background())
require.NoError(t, err)
_, resp, err := client.ListAutocompleteCommands(context.Background(), th.BasicTeam.Id)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
@@ -526,17 +535,21 @@ func TestListCommandAutocompleteSuggestions(t *testing.T) {
})
t.Run("NoMember", func(t *testing.T) {
client.Logout(context.Background())
_, err := client.Logout(context.Background())
require.NoError(t, err)
user := th.CreateUser()
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
client.Login(context.Background(), user.Email, user.Password)
_, _, err = client.Login(context.Background(), user.Email, user.Password)
require.NoError(t, err)
_, resp, err := client.ListCommandAutocompleteSuggestions(context.Background(), "/", th.BasicTeam.Id)
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
t.Run("NotLoggedIn", func(t *testing.T) {
client.Logout(context.Background())
_, err := client.Logout(context.Background())
require.NoError(t, err)
_, resp, err := client.ListCommandAutocompleteSuggestions(context.Background(), "/", th.BasicTeam.Id)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
@@ -561,9 +574,8 @@ func TestGetCommand(t *testing.T) {
Method: model.CommandMethodPost,
Trigger: "roger",
}
newCmd, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
require.NoError(t, err)
newCmd, _, rootErr := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
require.NoError(t, rootErr)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
t.Run("ValidId", func(t *testing.T) {
cmd, _, err := client.GetCommandById(context.Background(), newCmd.Id)
@@ -589,17 +601,21 @@ func TestGetCommand(t *testing.T) {
})
t.Run("NoMember", func(t *testing.T) {
th.Client.Logout(context.Background())
_, err := th.Client.Logout(context.Background())
require.NoError(t, err)
user := th.CreateUser()
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
th.Client.Login(context.Background(), user.Email, user.Password)
_, _, err = th.Client.Login(context.Background(), user.Email, user.Password)
require.NoError(t, err)
_, resp, err := th.Client.GetCommandById(context.Background(), newCmd.Id)
require.Error(t, err)
CheckNotFoundStatus(t, resp)
})
t.Run("NotLoggedIn", func(t *testing.T) {
th.Client.Logout(context.Background())
_, err := th.Client.Logout(context.Background())
require.NoError(t, err)
_, resp, err := th.Client.GetCommandById(context.Background(), newCmd.Id)
require.Error(t, err)
CheckUnauthorizedStatus(t, resp)
@@ -695,13 +711,15 @@ func TestExecuteInvalidCommand(t *testing.T) {
CheckNotFoundStatus(t, resp)
otherUser := th.CreateUser()
client.Login(context.Background(), otherUser.Email, otherUser.Password)
_, _, err = client.Login(context.Background(), otherUser.Email, otherUser.Password)
require.NoError(t, err)
_, resp, err = client.ExecuteCommand(context.Background(), channel.Id, "/getcommand")
require.Error(t, err)
CheckForbiddenStatus(t, resp)
client.Logout(context.Background())
_, err = client.Logout(context.Background())
require.NoError(t, err)
_, resp, err = client.ExecuteCommand(context.Background(), channel.Id, "/getcommand")
require.Error(t, err)
@@ -803,7 +821,8 @@ func TestExecutePostCommand(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodPost, r.Method)
r.ParseForm()
err := r.ParseForm()
require.NoError(t, err)
require.Equal(t, token, r.FormValue("token"))
require.Equal(t, th.BasicTeam.Name, r.FormValue("team_domain"))
@@ -1042,7 +1061,8 @@ func TestExecuteCommandInTeamUserIsNotOn(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodPost, r.Method)
r.ParseForm()
err := r.ParseForm()
require.NoError(t, err)
require.Equal(t, team2.Name, r.FormValue("team_domain"))
w.Header().Set("Content-Type", "application/json")
@@ -1116,7 +1136,8 @@ func TestExecuteCommandReadOnly(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodPost, r.Method)
r.ParseForm()
err := r.ParseForm()
require.NoError(t, err)
require.Equal(t, th.BasicTeam.Name, r.FormValue("team_domain"))
w.Header().Set("Content-Type", "application/json")
@@ -1145,7 +1166,8 @@ func TestExecuteCommandReadOnly(t *testing.T) {
// Enable Enterprise features
th.App.Srv().SetLicense(model.NewTestLicense())
th.App.SetPhase2PermissionsMigrationStatus(true)
err = th.App.SetPhase2PermissionsMigrationStatus(true)
require.NoError(t, err)
_, appErr = th.App.PatchChannelModerationsForChannel(
th.Context,