[MM-49989] Pass a context.Context to Client4 methods (#22922)

* Migrate all method in model/client4.go to accept a context.Context

* Fix th.*Client

* Fix remaining issues

* Empty commit to triger CI

* Fix test

* Add cancellation test

* Test that returned error is context.Canceled

* Fix bad merge

* Update mmctl code

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ben Schumacher
2023-06-06 23:29:29 +02:00
коммит произвёл GitHub
родитель 7116e9267a
Коммит 6c82605df0
140 изменённых файлов: 7516 добавлений и 7333 удалений

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

@@ -4,6 +4,7 @@
package commands
import (
"context"
"errors"
"fmt"
"net/http"
@@ -18,7 +19,7 @@ func (s *MmctlUnitTestSuite) TestGetChannelArgs() {
s.client.
EXPECT().
GetChannel(notFoundChannel, "").
GetChannel(context.Background(), notFoundChannel, "").
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
Times(1)
@@ -33,7 +34,7 @@ func (s *MmctlUnitTestSuite) TestGetChannelArgs() {
s.client.
EXPECT().
GetChannel(badRequestChannel, "").
GetChannel(context.Background(), badRequestChannel, "").
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
Times(1)
@@ -48,7 +49,7 @@ func (s *MmctlUnitTestSuite) TestGetChannelArgs() {
s.client.
EXPECT().
GetChannel(forbidden, "").
GetChannel(context.Background(), forbidden, "").
Return(nil, &model.Response{StatusCode: http.StatusForbidden}, forbiddenErr).
Times(1)
@@ -63,7 +64,7 @@ func (s *MmctlUnitTestSuite) TestGetChannelArgs() {
s.client.
EXPECT().
GetChannel(errChannel, "").
GetChannel(context.Background(), errChannel, "").
Return(nil, &model.Response{StatusCode: http.StatusInternalServerError}, internalServerErrorErr).
Times(1)
@@ -78,7 +79,7 @@ func (s *MmctlUnitTestSuite) TestGetChannelArgs() {
s.client.
EXPECT().
GetChannel(successID, "").
GetChannel(context.Background(), successID, "").
Return(successChannel, nil, nil).
Times(1)
@@ -96,12 +97,12 @@ func (s *MmctlUnitTestSuite) TestGetChannelArgs() {
s.client.
EXPECT().
GetTeam(teamID, "").
GetTeam(context.Background(), teamID, "").
Return(successTeam, nil, nil).
Times(1)
s.client.
EXPECT().
GetChannelByNameIncludeDeleted(channelID, teamID, "").
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
Return(successChannel, nil, nil).
Times(1)