[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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7116e9267a
Коммит
6c82605df0
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -24,13 +25,13 @@ func (s *MmctlUnitTestSuite) TestMakeAdminCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(mockUser.Id, newRoles).
|
||||
UpdateUserRoles(context.Background(), mockUser.Id, newRoles).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -50,7 +51,7 @@ func (s *MmctlUnitTestSuite) TestMakeAdminCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -68,19 +69,19 @@ func (s *MmctlUnitTestSuite) TestMakeAdminCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(emailArg, "").
|
||||
GetUserByEmail(context.Background(), emailArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(emailArg, "").
|
||||
GetUserByUsername(context.Background(), emailArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(emailArg, "").
|
||||
GetUser(context.Background(), emailArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -100,13 +101,13 @@ func (s *MmctlUnitTestSuite) TestMakeAdminCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(mockUser.Id, newRoles).
|
||||
UpdateUserRoles(context.Background(), mockUser.Id, newRoles).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -127,13 +128,13 @@ func (s *MmctlUnitTestSuite) TestMakeMemberCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(mockUser.Id, "system_user").
|
||||
UpdateUserRoles(context.Background(), mockUser.Id, "system_user").
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -152,7 +153,7 @@ func (s *MmctlUnitTestSuite) TestMakeMemberCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -170,13 +171,13 @@ func (s *MmctlUnitTestSuite) TestMakeMemberCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(mockUser.Id, "system_user").
|
||||
UpdateUserRoles(context.Background(), mockUser.Id, "system_user").
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -195,19 +196,19 @@ func (s *MmctlUnitTestSuite) TestMakeMemberCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(emailArg, "").
|
||||
GetUserByEmail(context.Background(), emailArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(emailArg, "").
|
||||
GetUserByUsername(context.Background(), emailArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(emailArg, "").
|
||||
GetUser(context.Background(), emailArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user