[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
@@ -5,6 +5,7 @@ package commands
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -166,6 +167,8 @@ func loginCmdF(cmd *cobra.Command, args []string) error {
|
||||
url := strings.TrimRight(args[0], "/")
|
||||
method := MethodPassword
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
if name == "" {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Printf("Connection name: ")
|
||||
@@ -203,10 +206,10 @@ func loginCmdF(cmd *cobra.Command, args []string) error {
|
||||
var c *model.Client4
|
||||
var err error
|
||||
if mfaToken != "" {
|
||||
c, _, err = InitClientWithMFA(username, password, mfaToken, url, allowInsecureSHA1, allowInsecureTLS)
|
||||
c, _, err = InitClientWithMFA(ctx, username, password, mfaToken, url, allowInsecureSHA1, allowInsecureTLS)
|
||||
method = MethodMFA
|
||||
} else {
|
||||
c, _, err = InitClientWithUsernameAndPassword(username, password, url, allowInsecureSHA1, allowInsecureTLS)
|
||||
c, _, err = InitClientWithUsernameAndPassword(ctx, username, password, url, allowInsecureSHA1, allowInsecureTLS)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not initiate client: %w", err)
|
||||
@@ -219,7 +222,7 @@ func loginCmdF(cmd *cobra.Command, args []string) error {
|
||||
InstanceURL: url,
|
||||
AuthToken: accessToken,
|
||||
}
|
||||
if _, _, err := InitClientWithCredentials(&credentials, allowInsecureSHA1, allowInsecureTLS); err != nil {
|
||||
if _, _, err := InitClientWithCredentials(ctx, &credentials, allowInsecureSHA1, allowInsecureTLS); err != nil {
|
||||
return fmt.Errorf("could not initiate client: %w", err)
|
||||
}
|
||||
}
|
||||
@@ -350,6 +353,8 @@ func renewCmdF(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
if (credentials.AuthMethod == MethodPassword || credentials.AuthMethod == MethodMFA) && password == "" {
|
||||
if password == "" {
|
||||
fmt.Printf("Password: ")
|
||||
@@ -363,7 +368,7 @@ func renewCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
switch credentials.AuthMethod {
|
||||
case MethodPassword:
|
||||
c, _, err := InitClientWithUsernameAndPassword(credentials.Username, password, credentials.InstanceURL, allowInsecureSHA1, allowInsecureTLS)
|
||||
c, _, err := InitClientWithUsernameAndPassword(ctx, credentials.Username, password, credentials.InstanceURL, allowInsecureSHA1, allowInsecureTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -376,7 +381,7 @@ func renewCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
credentials.AuthToken = accessToken
|
||||
if _, _, err := InitClientWithCredentials(credentials, allowInsecureSHA1, allowInsecureTLS); err != nil {
|
||||
if _, _, err := InitClientWithCredentials(ctx, credentials, allowInsecureSHA1, allowInsecureTLS); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -385,7 +390,7 @@ func renewCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("requires the --mfa-token parameter to be set")
|
||||
}
|
||||
|
||||
c, _, err := InitClientWithMFA(credentials.Username, password, mfaToken, credentials.InstanceURL, allowInsecureSHA1, allowInsecureTLS)
|
||||
c, _, err := InitClientWithMFA(ctx, credentials.Username, password, mfaToken, credentials.InstanceURL, allowInsecureSHA1, allowInsecureTLS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
@@ -103,7 +104,7 @@ func botCreateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
displayName, _ := cmd.Flags().GetString("display-name")
|
||||
description, _ := cmd.Flags().GetString("description")
|
||||
|
||||
bot, _, err := c.CreateBot(&model.Bot{
|
||||
bot, _, err := c.CreateBot(context.TODO(), &model.Bot{
|
||||
Username: username,
|
||||
DisplayName: displayName,
|
||||
Description: description,
|
||||
@@ -144,7 +145,7 @@ func botUpdateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
patch.Description = &description
|
||||
}
|
||||
|
||||
bot, _, err := c.PatchBot(user.Id, &patch)
|
||||
bot, _, err := c.PatchBot(context.TODO(), user.Id, &patch)
|
||||
if err != nil {
|
||||
return errors.Errorf("could not update bot: %s", err)
|
||||
}
|
||||
@@ -165,11 +166,11 @@ func botListCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
var bots []*model.Bot
|
||||
var err error
|
||||
if all { //nolint:gocritic
|
||||
bots, _, err = c.GetBotsIncludeDeleted(page, perPage, "")
|
||||
bots, _, err = c.GetBotsIncludeDeleted(context.TODO(), page, perPage, "")
|
||||
} else if orphaned {
|
||||
bots, _, err = c.GetBotsOrphaned(page, perPage, "")
|
||||
bots, _, err = c.GetBotsOrphaned(context.TODO(), page, perPage, "")
|
||||
} else {
|
||||
bots, _, err = c.GetBots(page, perPage, "")
|
||||
bots, _, err = c.GetBots(context.TODO(), page, perPage, "")
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to fetch bots")
|
||||
@@ -180,7 +181,7 @@ func botListCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
userIds = append(userIds, bot.OwnerId)
|
||||
}
|
||||
|
||||
users, _, err := c.GetUsersByIds(userIds)
|
||||
users, _, err := c.GetUsersByIds(context.TODO(), userIds)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to fetch bots")
|
||||
}
|
||||
@@ -227,7 +228,7 @@ func botEnableCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
bot, _, err := c.EnableBot(user.Id)
|
||||
bot, _, err := c.EnableBot(context.TODO(), user.Id)
|
||||
if err != nil {
|
||||
printer.PrintError(fmt.Sprintf("could not enable bot '%v'", args[i]))
|
||||
result = multierror.Append(result, fmt.Errorf("could not enable bot %q: %w", args[i], err))
|
||||
@@ -251,7 +252,7 @@ func botDisableCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
bot, _, err := c.DisableBot(user.Id)
|
||||
bot, _, err := c.DisableBot(context.TODO(), user.Id)
|
||||
if err != nil {
|
||||
printer.PrintError(fmt.Sprintf("could not disable bot '%v'", args[i]))
|
||||
result = multierror.Append(result, fmt.Errorf("could not disable bot %q: %w", args[i], err))
|
||||
@@ -274,7 +275,7 @@ func botAssignCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
return errors.New("unable to find user '" + args[1] + "'")
|
||||
}
|
||||
|
||||
newBot, _, err := c.AssignBot(botUser.Id, newOwnerUser.Id)
|
||||
newBot, _, err := c.AssignBot(context.TODO(), botUser.Id, newOwnerUser.Id)
|
||||
if err != nil {
|
||||
return errors.Errorf("can not assign bot '%s' to user '%s'", args[0], args[1])
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
@@ -27,7 +28,7 @@ func (s *MmctlUnitTestSuite) TestBotCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateBot(&mockBot).
|
||||
CreateBot(context.Background(), &mockBot).
|
||||
Return(&mockBot, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -51,25 +52,25 @@ func (s *MmctlUnitTestSuite) TestBotCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateBot(&mockBot).
|
||||
CreateBot(context.Background(), &mockBot).
|
||||
Return(&mockBot, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(model.UserFromBot(&mockBot), &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateUserAccessToken(mockBot.UserId, "autogenerated").
|
||||
CreateUserAccessToken(context.Background(), mockBot.UserId, "autogenerated").
|
||||
Return(&mockToken, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -88,7 +89,7 @@ func (s *MmctlUnitTestSuite) TestBotCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateBot(&mockBot).
|
||||
CreateBot(context.Background(), &mockBot).
|
||||
Return(nil, &model.Response{}, errors.New("some-error")).
|
||||
Times(1)
|
||||
|
||||
@@ -117,19 +118,19 @@ func (s *MmctlUnitTestSuite) TestBotUpdateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchBot(mockUser.Id, gomock.Any()).
|
||||
PatchBot(context.Background(), mockUser.Id, gomock.Any()).
|
||||
Return(&mockBot, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -149,19 +150,19 @@ func (s *MmctlUnitTestSuite) TestBotUpdateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(botArg, "").
|
||||
GetUser(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -184,19 +185,19 @@ func (s *MmctlUnitTestSuite) TestBotUpdateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchBot(mockUser.Id, gomock.Any()).
|
||||
PatchBot(context.Background(), mockUser.Id, gomock.Any()).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -220,13 +221,13 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBotsIncludeDeleted(0, 200, "").
|
||||
GetBotsIncludeDeleted(context.Background(), 0, 200, "").
|
||||
Return([]*model.Bot{&mockBot}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUsersByIds([]string{mockBot.OwnerId}).
|
||||
GetUsersByIds(context.Background(), []string{mockBot.OwnerId}).
|
||||
Return([]*model.User{&mockUser}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -246,7 +247,7 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBotsIncludeDeleted(0, 200, "").
|
||||
GetBotsIncludeDeleted(context.Background(), 0, 200, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -268,13 +269,13 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBotsOrphaned(0, 200, "").
|
||||
GetBotsOrphaned(context.Background(), 0, 200, "").
|
||||
Return([]*model.Bot{&mockBot}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUsersByIds([]string{mockBot.OwnerId}).
|
||||
GetUsersByIds(context.Background(), []string{mockBot.OwnerId}).
|
||||
Return([]*model.User{&mockUser}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -294,7 +295,7 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBotsOrphaned(0, 200, "").
|
||||
GetBotsOrphaned(context.Background(), 0, 200, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -316,13 +317,13 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBots(0, 200, "").
|
||||
GetBots(context.Background(), 0, 200, "").
|
||||
Return([]*model.Bot{&mockBot}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUsersByIds([]string{mockBot.OwnerId}).
|
||||
GetUsersByIds(context.Background(), []string{mockBot.OwnerId}).
|
||||
Return([]*model.User{&mockUser}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -343,13 +344,13 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBots(0, 200, "").
|
||||
GetBots(context.Background(), 0, 200, "").
|
||||
Return([]*model.Bot{&mockBot}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUsersByIds([]string{mockBot.OwnerId}).
|
||||
GetUsersByIds(context.Background(), []string{mockBot.OwnerId}).
|
||||
Return([]*model.User{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -369,7 +370,7 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBots(0, 200, "").
|
||||
GetBots(context.Background(), 0, 200, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -390,13 +391,13 @@ func (s *MmctlUnitTestSuite) TestBotListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetBots(0, 200, "").
|
||||
GetBots(context.Background(), 0, 200, "").
|
||||
Return([]*model.Bot{&mockBot}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUsersByIds([]string{mockBot.OwnerId}).
|
||||
GetUsersByIds(context.Background(), []string{mockBot.OwnerId}).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -418,19 +419,19 @@ func (s *MmctlUnitTestSuite) TestBotDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DisableBot(mockUser.Id).
|
||||
DisableBot(context.Background(), mockUser.Id).
|
||||
Return(&mockBot, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -447,19 +448,19 @@ func (s *MmctlUnitTestSuite) TestBotDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(botArg, "").
|
||||
GetUser(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -482,19 +483,19 @@ func (s *MmctlUnitTestSuite) TestBotDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DisableBot(mockUser.Id).
|
||||
DisableBot(context.Background(), mockUser.Id).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -516,19 +517,19 @@ func (s *MmctlUnitTestSuite) TestBotEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
EnableBot(mockUser.Id).
|
||||
EnableBot(context.Background(), mockUser.Id).
|
||||
Return(&mockBot, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -545,19 +546,19 @@ func (s *MmctlUnitTestSuite) TestBotEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(botArg, "").
|
||||
GetUser(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -580,19 +581,19 @@ func (s *MmctlUnitTestSuite) TestBotEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
EnableBot(mockUser.Id).
|
||||
EnableBot(context.Background(), mockUser.Id).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -616,31 +617,31 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockBotUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userArg, "").
|
||||
GetUserByEmail(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(userArg, "").
|
||||
GetUserByUsername(context.Background(), userArg, "").
|
||||
Return(&mockNewOwner, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
AssignBot(mockBotUser.Id, mockNewOwner.Id).
|
||||
AssignBot(context.Background(), mockBotUser.Id, mockNewOwner.Id).
|
||||
Return(&mockBot, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -658,19 +659,19 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(botArg, "").
|
||||
GetUser(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -690,31 +691,31 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockBotUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(userArg, "").
|
||||
GetUserByUsername(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(userArg, "").
|
||||
GetUser(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userArg, "").
|
||||
GetUserByEmail(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -735,31 +736,31 @@ func (s *MmctlUnitTestSuite) TestBotAssignCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(botArg, "").
|
||||
GetUserByEmail(context.Background(), botArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(botArg, "").
|
||||
GetUserByUsername(context.Background(), botArg, "").
|
||||
Return(&mockBotUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userArg, "").
|
||||
GetUserByEmail(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(userArg, "").
|
||||
GetUserByUsername(context.Background(), userArg, "").
|
||||
Return(&mockNewOwner, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
AssignBot(mockBotUser.Id, mockNewOwner.Id).
|
||||
AssignBot(context.Background(), mockBotUser.Id, mockNewOwner.Id).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -246,7 +247,7 @@ func createChannelCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
CreatorId: "",
|
||||
}
|
||||
|
||||
newChannel, _, err := c.CreateChannel(channel)
|
||||
newChannel, _, err := c.CreateChannel(context.TODO(), channel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -269,7 +270,7 @@ func archiveChannelsCmdF(c client.Client, cmd *cobra.Command, args []string) err
|
||||
errors = multierror.Append(errors, fmt.Errorf("unable to find channel %q", args[i]))
|
||||
continue
|
||||
}
|
||||
if _, err := c.DeleteChannel(channel.Id); err != nil {
|
||||
if _, err := c.DeleteChannel(context.TODO(), channel.Id); err != nil {
|
||||
printer.PrintError("Unable to archive channel '" + channel.Name + "' error: " + err.Error())
|
||||
errors = multierror.Append(errors, fmt.Errorf("unable to archive channel %q, error: %w", channel.Name, err))
|
||||
}
|
||||
@@ -283,7 +284,7 @@ func getAllPublicChannelsForTeam(c client.Client, teamID string) ([]*model.Chann
|
||||
page := 0
|
||||
|
||||
for {
|
||||
channelsPage, _, err := c.GetPublicChannelsForTeam(teamID, page, web.PerPageMaximum, "")
|
||||
channelsPage, _, err := c.GetPublicChannelsForTeam(context.TODO(), teamID, page, web.PerPageMaximum, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -304,7 +305,7 @@ func getAllDeletedChannelsForTeam(c client.Client, teamID string) ([]*model.Chan
|
||||
page := 0
|
||||
|
||||
for {
|
||||
channelsPage, _, err := c.GetDeletedChannelsForTeam(teamID, page, web.PerPageMaximum, "")
|
||||
channelsPage, _, err := c.GetDeletedChannelsForTeam(context.TODO(), teamID, page, web.PerPageMaximum, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -374,7 +375,7 @@ func unarchiveChannelsCmdF(c client.Client, cmd *cobra.Command, args []string) e
|
||||
printer.PrintError("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if _, _, err := c.RestoreChannel(channel.Id); err != nil {
|
||||
if _, _, err := c.RestoreChannel(context.TODO(), channel.Id); err != nil {
|
||||
printer.PrintError("Unable to unarchive channel '" + args[i] + "'. Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
@@ -396,7 +397,7 @@ func makeChannelPrivateCmdF(c client.Client, cmd *cobra.Command, args []string)
|
||||
return errors.New("you can only change the type of public channels")
|
||||
}
|
||||
|
||||
if _, _, err := c.UpdateChannelPrivacy(channel.Id, model.ChannelTypePrivate); err != nil {
|
||||
if _, _, err := c.UpdateChannelPrivacy(context.TODO(), channel.Id, model.ChannelTypePrivate); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -425,7 +426,7 @@ func modifyChannelCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
privacy = model.ChannelTypePrivate
|
||||
}
|
||||
|
||||
if _, _, err := c.UpdateChannelPrivacy(channel.Id, privacy); err != nil {
|
||||
if _, _, err := c.UpdateChannelPrivacy(context.TODO(), channel.Id, privacy); err != nil {
|
||||
return errors.Errorf("failed to update channel (%q) privacy: %s", args[0], err.Error())
|
||||
}
|
||||
|
||||
@@ -467,7 +468,7 @@ func renameChannelCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
// Using PatchChannel API to rename channel
|
||||
updatedChannel, _, err := c.PatchChannel(channel.Id, channelPatch)
|
||||
updatedChannel, _, err := c.PatchChannel(context.TODO(), channel.Id, channelPatch)
|
||||
if err != nil {
|
||||
return errors.Errorf("cannot rename channel %q, error: %s", channel.Name, err.Error())
|
||||
}
|
||||
@@ -488,7 +489,7 @@ func searchChannelCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
var err error
|
||||
channel, _, err = c.GetChannelByName(args[0], team.Id, "")
|
||||
channel, _, err = c.GetChannelByName(context.TODO(), args[0], team.Id, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -496,13 +497,13 @@ func searchChannelCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
return errors.Errorf("channel %s was not found in team %s", args[0], teamArg)
|
||||
}
|
||||
} else {
|
||||
teams, _, err := c.GetAllTeams("", 0, 9999)
|
||||
teams, _, err := c.GetAllTeams(context.TODO(), "", 0, 9999)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, team := range teams {
|
||||
channel, _, _ = c.GetChannelByName(args[0], team.Id, "")
|
||||
channel, _, _ = c.GetChannelByName(context.TODO(), args[0], team.Id, "")
|
||||
if channel != nil && channel.Name == args[0] {
|
||||
break
|
||||
}
|
||||
@@ -542,7 +543,7 @@ func moveChannelCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
newChannel, _, err := c.MoveChannel(channel.Id, team.Id, force)
|
||||
newChannel, _, err := c.MoveChannel(context.TODO(), channel.Id, team.Id, force)
|
||||
if err != nil {
|
||||
result = multierror.Append(result, fmt.Errorf("unable to move channel %q: %w", channel.Name, err))
|
||||
continue
|
||||
@@ -558,7 +559,7 @@ func getPrivateChannels(c client.Client, teamID string) ([]*model.Channel, error
|
||||
withoutError := true
|
||||
|
||||
for {
|
||||
channelsPage, _, err := c.GetPrivateChannelsForTeam(teamID, page, web.PerPageMaximum, "")
|
||||
channelsPage, _, err := c.GetPrivateChannelsForTeam(context.TODO(), teamID, page, web.PerPageMaximum, "")
|
||||
if err != nil && viper.GetBool("local") {
|
||||
return nil, err
|
||||
} else if err != nil {
|
||||
@@ -586,7 +587,7 @@ func getPrivateChannels(c client.Client, teamID string) ([]*model.Channel, error
|
||||
|
||||
// We are definitely not in local mode here so we can safely use
|
||||
// "GetChannelsForTeamForUser" and "me" for userId
|
||||
allChannels, response, err := c.GetChannelsForTeamForUser(teamID, "me", false, "")
|
||||
allChannels, response, err := c.GetChannelsForTeamForUser(context.TODO(), teamID, "me", false, "")
|
||||
if err != nil {
|
||||
if response.StatusCode == http.StatusNotFound { // user doesn't belong to any channels
|
||||
return nil, nil
|
||||
@@ -619,7 +620,7 @@ func deleteChannelsCmdF(c client.Client, cmd *cobra.Command, args []string) erro
|
||||
result = multierror.Append(result, fmt.Errorf("unable to find channel '%s'", args[i]))
|
||||
continue
|
||||
}
|
||||
if _, err := c.PermanentDeleteChannel(channel.Id); err != nil {
|
||||
if _, err := c.PermanentDeleteChannel(context.TODO(), channel.Id); err != nil {
|
||||
result = multierror.Append(result, fmt.Errorf("unable to delete channel '%q' error: %w", channel.Name, err))
|
||||
} else {
|
||||
printer.PrintT("Deleted channel '{{.Name}}'", channel)
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
@@ -72,7 +73,7 @@ func addUserToChannel(c client.Client, channel *model.Channel, user *model.User,
|
||||
printer.PrintError("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if _, _, err := c.AddChannelMember(channel.Id, user.Id); err != nil {
|
||||
if _, _, err := c.AddChannelMember(context.TODO(), channel.Id, user.Id); err != nil {
|
||||
printer.PrintError("Unable to add '" + userArg + "' to " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
@@ -111,21 +112,21 @@ func removeUserFromChannel(c client.Client, channel *model.Channel, user *model.
|
||||
printer.PrintError("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if _, err := c.RemoveUserFromChannel(channel.Id, user.Id); err != nil {
|
||||
if _, err := c.RemoveUserFromChannel(context.TODO(), channel.Id, user.Id); err != nil {
|
||||
printer.PrintError("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func removeAllUsersFromChannel(c client.Client, channel *model.Channel) error {
|
||||
var result *multierror.Error
|
||||
members, _, err := c.GetChannelMembers(channel.Id, 0, 10000, "")
|
||||
members, _, err := c.GetChannelMembers(context.TODO(), channel.Id, 0, 10000, "")
|
||||
if err != nil {
|
||||
printer.PrintError("Unable to remove all users from " + channel.Name + ". Error: " + err.Error())
|
||||
return fmt.Errorf("unable to remove all users from %q: %w", channel.Name, err)
|
||||
}
|
||||
|
||||
for _, member := range members {
|
||||
if _, err := c.RemoveUserFromChannel(channel.Id, member.UserId); err != nil {
|
||||
if _, err := c.RemoveUserFromChannel(context.TODO(), channel.Id, member.UserId); err != nil {
|
||||
result = multierror.Append(result, fmt.Errorf("unable to remove %q from %q Error: %w", member.UserId, channel.Name, err))
|
||||
printer.PrintError("Unable to remove '" + member.UserId + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -43,24 +44,24 @@ func (s *MmctlUnitTestSuite) TestChannelUsersAddCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, teamID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userEmail, "").
|
||||
GetUserByEmail(context.Background(), userEmail, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
AddChannelMember(channelID, userID).
|
||||
AddChannelMember(context.Background(), channelID, userID).
|
||||
Return(&model.ChannelMember{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
err := channelUsersAddCmdF(s.client, cmd, []string{channelArg, userEmail})
|
||||
@@ -74,19 +75,19 @@ func (s *MmctlUnitTestSuite) TestChannelUsersAddCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
// No channel is returned by client.
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelName, "").
|
||||
GetChannel(context.Background(), channelName, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -102,12 +103,12 @@ func (s *MmctlUnitTestSuite) TestChannelUsersAddCmdF() {
|
||||
// No team is returned by client.
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamID, "").
|
||||
GetTeamByName(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -123,38 +124,38 @@ func (s *MmctlUnitTestSuite) TestChannelUsersAddCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, teamID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(nilUserArg, "").
|
||||
GetUserByEmail(context.Background(), nilUserArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(nilUserArg, "").
|
||||
GetUserByUsername(context.Background(), nilUserArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(nilUserArg, "").
|
||||
GetUser(context.Background(), nilUserArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userEmail, "").
|
||||
GetUserByEmail(context.Background(), userEmail, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
AddChannelMember(channelID, userID).
|
||||
AddChannelMember(context.Background(), channelID, userID).
|
||||
Return(&model.ChannelMember{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
err := channelUsersAddCmdF(s.client, cmd, []string{channelArg, nilUserArg, userEmail})
|
||||
@@ -169,24 +170,24 @@ func (s *MmctlUnitTestSuite) TestChannelUsersAddCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, teamID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userEmail, "").
|
||||
GetUserByEmail(context.Background(), userEmail, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
AddChannelMember(channelID, userID).
|
||||
AddChannelMember(context.Background(), channelID, userID).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
err := channelUsersAddCmdF(s.client, cmd, []string{channelArg, userEmail})
|
||||
@@ -224,25 +225,25 @@ func (s *MmctlUnitTestSuite) TestChannelUsersRemoveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(foundTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, foundTeam.Id, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, foundTeam.Id, "").
|
||||
Return(foundChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userEmail, "").
|
||||
GetUserByEmail(context.Background(), userEmail, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveUserFromChannel(foundChannel.Id, mockUser.Id).
|
||||
RemoveUserFromChannel(context.Background(), foundChannel.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -288,37 +289,37 @@ func (s *MmctlUnitTestSuite) TestChannelUsersRemoveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(foundTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, foundTeam.Id, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, foundTeam.Id, "").
|
||||
Return(foundChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelMembers(foundChannel.Id, 0, 10000, "").
|
||||
GetChannelMembers(context.Background(), foundChannel.Id, 0, 10000, "").
|
||||
Return(mockChannelMembers, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveUserFromChannel(foundChannel.Id, mockUser.Id).
|
||||
RemoveUserFromChannel(context.Background(), foundChannel.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveUserFromChannel(foundChannel.Id, mockUser2.Id).
|
||||
RemoveUserFromChannel(context.Background(), foundChannel.Id, mockUser2.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveUserFromChannel(foundChannel.Id, mockUser3.Id).
|
||||
RemoveUserFromChannel(context.Background(), foundChannel.Id, mockUser3.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -348,37 +349,37 @@ func (s *MmctlUnitTestSuite) TestChannelUsersRemoveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(foundTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, foundTeam.Id, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, foundTeam.Id, "").
|
||||
Return(foundChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userEmail, "").
|
||||
GetUserByEmail(context.Background(), userEmail, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser2.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser2.Email, "").
|
||||
Return(&mockUser2, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveUserFromChannel(foundChannel.Id, mockUser.Id).
|
||||
RemoveUserFromChannel(context.Background(), foundChannel.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveUserFromChannel(foundChannel.Id, mockUser2.Id).
|
||||
RemoveUserFromChannel(context.Background(), foundChannel.Id, mockUser2.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -411,25 +412,25 @@ func (s *MmctlUnitTestSuite) TestChannelUsersRemoveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(foundTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelName, foundTeam.Id, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelName, foundTeam.Id, "").
|
||||
Return(foundChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelMembers(foundChannel.Id, 0, 10000, "").
|
||||
GetChannelMembers(context.Background(), foundChannel.Id, 0, 10000, "").
|
||||
Return(mockChannelMembers, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveUserFromChannel(foundChannel.Id, mockUser.Id).
|
||||
RemoveUserFromChannel(context.Background(), foundChannel.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusNotFound}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -50,11 +51,11 @@ func getChannelFromChannelArg(c client.Client, channelArg string) *model.Channel
|
||||
return nil
|
||||
}
|
||||
|
||||
channel, _, _ = c.GetChannelByNameIncludeDeleted(channelPart, team.Id, "")
|
||||
channel, _, _ = c.GetChannelByNameIncludeDeleted(context.TODO(), channelPart, team.Id, "")
|
||||
}
|
||||
|
||||
if channel == nil {
|
||||
channel, _, _ = c.GetChannel(channelPart, "")
|
||||
channel, _, _ = c.GetChannel(context.TODO(), channelPart, "")
|
||||
}
|
||||
|
||||
return channel
|
||||
@@ -94,7 +95,7 @@ func getChannelFromArg(c client.Client, arg string) (*model.Channel, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channel, response, err = c.GetChannelByNameIncludeDeleted(channelArg, team.Id, "")
|
||||
channel, response, err = c.GetChannelByNameIncludeDeleted(context.TODO(), channelArg, team.Id, "")
|
||||
if err != nil {
|
||||
err = ExtractErrorFromResponse(response, err)
|
||||
var nfErr *NotFoundError
|
||||
@@ -108,7 +109,7 @@ func getChannelFromArg(c client.Client, arg string) (*model.Channel, error) {
|
||||
return channel, nil
|
||||
}
|
||||
var err error
|
||||
channel, response, err = c.GetChannel(channelArg, "")
|
||||
channel, response, err = c.GetChannel(context.TODO(), channelArg, "")
|
||||
if err != nil {
|
||||
nErr := ExtractErrorFromResponse(response, err)
|
||||
var nfErr *NotFoundError
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -174,7 +175,7 @@ func createCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
URL: url,
|
||||
}
|
||||
|
||||
createdCommand, _, err := c.CreateCommand(newCommand)
|
||||
createdCommand, _, err := c.CreateCommand(context.TODO(), newCommand)
|
||||
if err != nil {
|
||||
return errors.New("unable to create command '" + newCommand.DisplayName + "'. " + err.Error())
|
||||
}
|
||||
@@ -187,7 +188,7 @@ func createCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
func listCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
var teams []*model.Team
|
||||
if len(args) < 1 {
|
||||
teamList, _, err := c.GetAllTeams("", 0, 10000)
|
||||
teamList, _, err := c.GetAllTeams(context.TODO(), "", 0, 10000)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -203,7 +204,7 @@ func listCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
errs = multierror.Append(errs, fmt.Errorf("unable to find team '%s'", args[i]))
|
||||
continue
|
||||
}
|
||||
commands, _, err := c.ListCommands(team.Id, true)
|
||||
commands, _, err := c.ListCommands(context.TODO(), team.Id, true)
|
||||
if err != nil {
|
||||
printer.PrintError("Unable to list commands for '" + team.Id + "'")
|
||||
errs = multierror.Append(errs, fmt.Errorf("unable to list commands for '%s': %w", team.Id, err))
|
||||
@@ -217,7 +218,7 @@ func listCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func archiveCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
resp, err := c.DeleteCommand(args[0])
|
||||
resp, err := c.DeleteCommand(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return errors.New("Unable to archive command '" + args[0] + "' error: " + err.Error())
|
||||
}
|
||||
@@ -289,7 +290,7 @@ func modifyCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
}
|
||||
|
||||
modifiedCommand, _, err := c.UpdateCommand(command)
|
||||
modifiedCommand, _, err := c.UpdateCommand(context.TODO(), command)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to modify command '%s'. %s", command.DisplayName, err.Error())
|
||||
}
|
||||
@@ -311,7 +312,7 @@ func moveCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("unable to find command '%s'", args[1])
|
||||
}
|
||||
|
||||
resp, err := c.MoveCommand(newTeam.Id, command.Id)
|
||||
resp, err := c.MoveCommand(context.TODO(), newTeam.Id, command.Id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to move command '%s'. %s", command.Id, err.Error())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
@@ -262,7 +263,7 @@ func (s *MmctlE2ETestSuite) TestModifyCommandCmdF() {
|
||||
Trigger: "trigger",
|
||||
}
|
||||
|
||||
command, _, _ := s.th.SystemAdminClient.CreateCommand(newCmd)
|
||||
command, _, _ := s.th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
index := 0
|
||||
s.RunForSystemAdminAndLocal("modifyCommandCmdF", func(c client.Client) {
|
||||
printer.Clean()
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -68,17 +69,17 @@ func (s *MmctlUnitTestSuite) TestCommandCreateCmd() {
|
||||
// createCommandCmdF will call getTeamFromTeamArg, getUserFromUserArg which then calls GetUserByEmail
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(creatorIDArg, "").
|
||||
GetUserByEmail(context.Background(), creatorIDArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateCommand(&mockCommand).
|
||||
CreateCommand(context.Background(), &mockCommand).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -116,17 +117,17 @@ func (s *MmctlUnitTestSuite) TestCommandCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(creatorIDArg, "").
|
||||
GetUserByEmail(context.Background(), creatorIDArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateCommand(&mockCommand).
|
||||
CreateCommand(context.Background(), &mockCommand).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -145,12 +146,12 @@ func (s *MmctlUnitTestSuite) TestCommandCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -196,12 +197,12 @@ func (s *MmctlUnitTestSuite) TestCommandCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(creatorIDArg, "").
|
||||
GetUserByEmail(context.Background(), creatorIDArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -247,12 +248,12 @@ func (s *MmctlUnitTestSuite) TestCommandCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(creatorIDArg, "").
|
||||
GetUserByEmail(context.Background(), creatorIDArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -312,18 +313,18 @@ func (s *MmctlUnitTestSuite) TestCommandCreateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(creatorIDArg, "").
|
||||
GetUserByEmail(context.Background(), creatorIDArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
mockError := errors.New("mock error, simulated error for CreateCommand")
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateCommand(&mockCommand).
|
||||
CreateCommand(context.Background(), &mockCommand).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -343,7 +344,7 @@ func (s *MmctlUnitTestSuite) TestArchiveCommandCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteCommand(arg).
|
||||
DeleteCommand(context.Background(), arg).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -361,7 +362,7 @@ func (s *MmctlUnitTestSuite) TestArchiveCommandCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteCommand(arg).
|
||||
DeleteCommand(context.Background(), arg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -379,7 +380,7 @@ func (s *MmctlUnitTestSuite) TestArchiveCommandCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteCommand(arg).
|
||||
DeleteCommand(context.Background(), arg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -416,9 +417,9 @@ func (s *MmctlUnitTestSuite) TestCommandListCmdF() {
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{}
|
||||
s.client.EXPECT().GetAllTeams("", 0, 10000).Return(teams, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(team1ID, true).Return(team1Commands, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(team2Id, true).Return(team2Commands, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().GetAllTeams(context.Background(), "", 0, 10000).Return(teams, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(context.Background(), team1ID, true).Return(team1Commands, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(context.Background(), team2Id, true).Return(team2Commands, &model.Response{}, nil).Times(1)
|
||||
err := listCommandCmdF(s.client, cmd, []string{})
|
||||
s.Require().Nil(err)
|
||||
s.Len(printer.GetLines(), 2)
|
||||
@@ -439,8 +440,8 @@ func (s *MmctlUnitTestSuite) TestCommandListCmdF() {
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{}
|
||||
s.client.EXPECT().GetTeam(teamID, "").Return(team, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(teamID, true).Return(teamCommand, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().GetTeam(context.Background(), teamID, "").Return(team, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(context.Background(), teamID, true).Return(teamCommand, &model.Response{}, nil).Times(1)
|
||||
err := listCommandCmdF(s.client, cmd, []string{teamID})
|
||||
s.Require().Nil(err)
|
||||
s.Len(printer.GetLines(), 1)
|
||||
@@ -453,9 +454,9 @@ func (s *MmctlUnitTestSuite) TestCommandListCmdF() {
|
||||
printer.Clean()
|
||||
cmd := &cobra.Command{}
|
||||
// first try to get team by id
|
||||
s.client.EXPECT().GetTeam(teamID, "").Return(nil, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().GetTeam(context.Background(), teamID, "").Return(nil, &model.Response{}, nil).Times(1)
|
||||
// second try to search the team by name
|
||||
s.client.EXPECT().GetTeamByName(teamID, "").Return(nil, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().GetTeamByName(context.Background(), teamID, "").Return(nil, &model.Response{}, nil).Times(1)
|
||||
err := listCommandCmdF(s.client, cmd, []string{teamID})
|
||||
s.Require().Error(err)
|
||||
s.Len(printer.GetLines(), 0)
|
||||
@@ -468,8 +469,8 @@ func (s *MmctlUnitTestSuite) TestCommandListCmdF() {
|
||||
printer.Clean()
|
||||
cmd := &cobra.Command{}
|
||||
team := &model.Team{Id: teamID}
|
||||
s.client.EXPECT().GetTeam(teamID, "").Return(team, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(teamID, true).Return(nil, &model.Response{}, errors.New("")).Times(1)
|
||||
s.client.EXPECT().GetTeam(context.Background(), teamID, "").Return(team, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(context.Background(), teamID, true).Return(nil, &model.Response{}, errors.New("")).Times(1)
|
||||
err := listCommandCmdF(s.client, cmd, []string{teamID})
|
||||
s.Require().Error(err)
|
||||
s.Len(printer.GetLines(), 0)
|
||||
@@ -541,17 +542,17 @@ func (s *MmctlUnitTestSuite) TestCommandModifyCmd() {
|
||||
// modifyCommandCmdF will call getCommandById, GetUserByEmail and UpdateCommand
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(arg).
|
||||
GetCommandById(context.Background(), arg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockCommandModified.CreatorId, "").
|
||||
GetUserByEmail(context.Background(), mockCommandModified.CreatorId, "").
|
||||
Return(&model.User{Id: mockCommandModified.CreatorId}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateCommand(&mockCommand).
|
||||
UpdateCommand(context.Background(), &mockCommand).
|
||||
Return(mockCommandModified, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -582,7 +583,7 @@ func (s *MmctlUnitTestSuite) TestCommandModifyCmd() {
|
||||
// modifyCommandCmdF will call getCommandById
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(arg).
|
||||
GetCommandById(context.Background(), arg).
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -615,22 +616,22 @@ func (s *MmctlUnitTestSuite) TestCommandModifyCmd() {
|
||||
// via email, username, and id.
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(arg).
|
||||
GetCommandById(context.Background(), arg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(bogusUsername, "").
|
||||
GetUserByEmail(context.Background(), bogusUsername, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(bogusUsername, "").
|
||||
GetUserByUsername(context.Background(), bogusUsername, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(bogusUsername, "").
|
||||
GetUser(context.Background(), bogusUsername, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -661,7 +662,7 @@ func (s *MmctlUnitTestSuite) TestCommandModifyCmd() {
|
||||
// modifyCommandCmdF will call getCommandById
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(arg).
|
||||
GetCommandById(context.Background(), arg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -692,7 +693,7 @@ func (s *MmctlUnitTestSuite) TestCommandModifyCmd() {
|
||||
// modifyCommandCmdF will call getCommandById
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(arg).
|
||||
GetCommandById(context.Background(), arg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -723,13 +724,13 @@ func (s *MmctlUnitTestSuite) TestCommandModifyCmd() {
|
||||
// modifyCommandCmdF will call getCommandById then UpdateCommand
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(arg).
|
||||
GetCommandById(context.Background(), arg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
mockError := errors.New("mock error, simulated error for CreateCommand")
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateCommand(&mockCommand).
|
||||
UpdateCommand(context.Background(), &mockCommand).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -792,22 +793,22 @@ func (s *MmctlUnitTestSuite) TestCommandMoveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(&mockTeamDest, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(commandArg).
|
||||
GetCommandById(context.Background(), commandArg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
MoveCommand(teamArg, mockCommand.Id).
|
||||
MoveCommand(context.Background(), teamArg, mockCommand.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -822,12 +823,12 @@ func (s *MmctlUnitTestSuite) TestCommandMoveCmd() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArgBogus, "").
|
||||
GetTeam(context.Background(), teamArgBogus, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArgBogus, "").
|
||||
GetTeamByName(context.Background(), teamArgBogus, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -842,12 +843,12 @@ func (s *MmctlUnitTestSuite) TestCommandMoveCmd() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeamDest, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(commandArgBogus).
|
||||
GetCommandById(context.Background(), commandArgBogus).
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -862,17 +863,17 @@ func (s *MmctlUnitTestSuite) TestCommandMoveCmd() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeamDest, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(commandArg).
|
||||
GetCommandById(context.Background(), commandArg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
MoveCommand(teamArg, commandArg).
|
||||
MoveCommand(context.Background(), teamArg, commandArg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -887,17 +888,17 @@ func (s *MmctlUnitTestSuite) TestCommandMoveCmd() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeamDest, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(commandArg).
|
||||
GetCommandById(context.Background(), commandArg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
MoveCommand(teamArg, commandArg).
|
||||
MoveCommand(context.Background(), teamArg, commandArg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -936,7 +937,7 @@ func (s *MmctlUnitTestSuite) TestCommandShowCmd() {
|
||||
// showCommandCmdF will look up command by id
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(commandArg).
|
||||
GetCommandById(context.Background(), commandArg).
|
||||
Return(&mockCommand, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -952,7 +953,7 @@ func (s *MmctlUnitTestSuite) TestCommandShowCmd() {
|
||||
// showCommandCmdF will look up command by id
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(commandArgBogus).
|
||||
GetCommandById(context.Background(), commandArgBogus).
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -972,13 +973,13 @@ func (s *MmctlUnitTestSuite) TestCommandShowCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(mockTeam.Name, "").
|
||||
GetTeamByName(context.Background(), mockTeam.Name, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ListCommands(mockTeam.Id, false).
|
||||
ListCommands(context.Background(), mockTeam.Id, false).
|
||||
Return(list, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1001,13 +1002,13 @@ func (s *MmctlUnitTestSuite) TestCommandShowCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamName, "").
|
||||
GetTeamByName(context.Background(), teamName, "").
|
||||
Return(nil, &model.Response{}, errors.New("team not found")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(teamTrigger).
|
||||
GetCommandById(context.Background(), teamTrigger).
|
||||
Return(nil, &model.Response{}, errors.New("command not found")).
|
||||
Times(1)
|
||||
|
||||
@@ -1029,19 +1030,19 @@ func (s *MmctlUnitTestSuite) TestCommandShowCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(mockTeam.Name, "").
|
||||
GetTeamByName(context.Background(), mockTeam.Name, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ListCommands(mockTeam.Id, false).
|
||||
ListCommands(context.Background(), mockTeam.Id, false).
|
||||
Return(list, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetCommandById(teamTrigger).
|
||||
GetCommandById(context.Background(), teamTrigger).
|
||||
Return(nil, &model.Response{}, errors.New("bogus")).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/client"
|
||||
@@ -19,7 +20,7 @@ func getCommandFromCommandArg(c client.Client, commandArg string) *model.Command
|
||||
|
||||
cmd := getCommandFromTeamTrigger(c, commandArg)
|
||||
if cmd == nil {
|
||||
cmd, _, _ = c.GetCommandById(commandArg)
|
||||
cmd, _, _ = c.GetCommandById(context.TODO(), commandArg)
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
@@ -31,7 +32,7 @@ func getCommandFromTeamTrigger(c client.Client, teamTrigger string) *model.Comma
|
||||
return nil
|
||||
}
|
||||
|
||||
team, _, _ := c.GetTeamByName(arr[0], "")
|
||||
team, _, _ := c.GetTeamByName(context.TODO(), arr[0], "")
|
||||
if team == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -41,7 +42,7 @@ func getCommandFromTeamTrigger(c client.Client, teamTrigger string) *model.Comma
|
||||
return nil
|
||||
}
|
||||
|
||||
list, _, _ := c.ListCommands(team.Id, false)
|
||||
list, _, _ := c.ListCommands(context.TODO(), team.Id, false)
|
||||
if list == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -324,7 +325,7 @@ func configGetCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
printer.SetSingle(true)
|
||||
printer.SetFormat(printer.FormatJSON)
|
||||
|
||||
config, _, err := c.GetConfig()
|
||||
config, _, err := c.GetConfig(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -344,7 +345,7 @@ func configGetCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func configSetCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
config, _, err := c.GetConfig()
|
||||
config, _, err := c.GetConfig(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -357,7 +358,7 @@ func configSetCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
|
||||
return cErr
|
||||
}
|
||||
newConfig, _, err := c.PatchConfig(config)
|
||||
newConfig, _, err := c.PatchConfig(context.TODO(), config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -372,7 +373,7 @@ func configPatchCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
config, _, err := c.GetConfig()
|
||||
config, _, err := c.GetConfig(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -381,7 +382,7 @@ func configPatchCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
return jErr
|
||||
}
|
||||
|
||||
newConfig, _, err := c.PatchConfig(config)
|
||||
newConfig, _, err := c.PatchConfig(context.TODO(), config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -391,7 +392,7 @@ func configPatchCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func configEditCmdF(c client.Client, _ *cobra.Command, _ []string) error {
|
||||
config, _, err := c.GetConfig()
|
||||
config, _, err := c.GetConfig(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -436,7 +437,7 @@ func configEditCmdF(c client.Client, _ *cobra.Command, _ []string) error {
|
||||
return jErr
|
||||
}
|
||||
|
||||
newConfig, _, err := c.UpdateConfig(config)
|
||||
newConfig, _, err := c.UpdateConfig(context.TODO(), config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -458,7 +459,7 @@ func configResetCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
|
||||
defaultConfig := &model.Config{}
|
||||
defaultConfig.SetDefaults()
|
||||
config, _, err := c.GetConfig()
|
||||
config, _, err := c.GetConfig(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -474,7 +475,7 @@ func configResetCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
return nErr
|
||||
}
|
||||
}
|
||||
newConfig, _, err := c.UpdateConfig(config)
|
||||
newConfig, _, err := c.UpdateConfig(context.TODO(), config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -486,7 +487,7 @@ func configResetCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
func configShowCmdF(c client.Client, _ *cobra.Command, _ []string) error {
|
||||
printer.SetSingle(true)
|
||||
printer.SetFormat(printer.FormatJSON)
|
||||
config, _, err := c.GetConfig()
|
||||
config, _, err := c.GetConfig(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -501,7 +502,7 @@ func parseConfigPath(configPath string) []string {
|
||||
}
|
||||
|
||||
func configReloadCmdF(c client.Client, _ *cobra.Command, _ []string) error {
|
||||
_, err := c.ReloadConfig()
|
||||
_, err := c.ReloadConfig(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -515,7 +516,7 @@ func configMigrateCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
return errors.New("this command is only available in local mode. Please set the --local flag")
|
||||
}
|
||||
|
||||
_, err := c.MigrateConfig(args[0], args[1])
|
||||
_, err := c.MigrateConfig(context.TODO(), args[0], args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -32,7 +33,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -51,7 +52,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -70,7 +71,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -89,7 +90,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -108,7 +109,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -129,7 +130,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -150,7 +151,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -170,7 +171,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{StatusCode: 500}, errors.New("")).
|
||||
Times(1)
|
||||
|
||||
@@ -197,7 +198,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(7)
|
||||
|
||||
@@ -255,7 +256,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(0)
|
||||
|
||||
@@ -272,7 +273,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(outputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -296,12 +297,12 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -324,12 +325,12 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -352,12 +353,12 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -380,12 +381,12 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -407,12 +408,12 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -434,7 +435,7 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -453,7 +454,7 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -475,12 +476,12 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{StatusCode: 500}, errors.New("")).
|
||||
Times(1)
|
||||
|
||||
@@ -515,13 +516,13 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(3)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{}, nil).
|
||||
Times(3)
|
||||
|
||||
@@ -555,7 +556,7 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -576,7 +577,7 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -617,12 +618,12 @@ func (s *MmctlUnitTestSuite) TestConfigPatchCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchConfig(inputConfig).
|
||||
PatchConfig(context.Background(), inputConfig).
|
||||
Return(inputConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -640,7 +641,7 @@ func (s *MmctlUnitTestSuite) TestConfigPatchCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -668,12 +669,12 @@ func (s *MmctlUnitTestSuite) TestConfigResetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateConfig(defaultConfig).
|
||||
UpdateConfig(context.Background(), defaultConfig).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -694,12 +695,12 @@ func (s *MmctlUnitTestSuite) TestConfigResetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateConfig(defaultConfig).
|
||||
UpdateConfig(context.Background(), defaultConfig).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -721,7 +722,7 @@ func (s *MmctlUnitTestSuite) TestConfigResetCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(defaultConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -742,7 +743,7 @@ func (s *MmctlUnitTestSuite) TestConfigShowCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(mockConfig, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -759,7 +760,7 @@ func (s *MmctlUnitTestSuite) TestConfigShowCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetConfig().
|
||||
GetConfig(context.Background()).
|
||||
Return(nil, &model.Response{}, configError).
|
||||
Times(1)
|
||||
|
||||
@@ -775,7 +776,7 @@ func (s *MmctlUnitTestSuite) TestConfigReloadCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ReloadConfig().
|
||||
ReloadConfig(context.Background()).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -789,7 +790,7 @@ func (s *MmctlUnitTestSuite) TestConfigReloadCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ReloadConfig().
|
||||
ReloadConfig(context.Background()).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("some-error")).
|
||||
Times(1)
|
||||
|
||||
@@ -813,7 +814,7 @@ func (s *MmctlUnitTestSuite) TestConfigMigrateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
MigrateConfig(args[0], args[1]).
|
||||
MigrateConfig(context.Background(), args[0], args[1]).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -831,7 +832,7 @@ func (s *MmctlUnitTestSuite) TestConfigMigrateCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
MigrateConfig(args[0], args[1]).
|
||||
MigrateConfig(context.Background(), args[0], args[1]).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("some-error")).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -127,7 +128,7 @@ func exportCreateCmdF(c client.Client, command *cobra.Command, args []string) er
|
||||
data["include_attachments"] = "true"
|
||||
}
|
||||
|
||||
job, _, err := c.CreateJob(&model.Job{
|
||||
job, _, err := c.CreateJob(context.TODO(), &model.Job{
|
||||
Type: model.JobTypeExportProcess,
|
||||
Data: data,
|
||||
})
|
||||
@@ -141,7 +142,7 @@ func exportCreateCmdF(c client.Client, command *cobra.Command, args []string) er
|
||||
}
|
||||
|
||||
func exportListCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
exports, _, err := c.ListExports()
|
||||
exports, _, err := c.ListExports(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list exports: %w", err)
|
||||
}
|
||||
@@ -161,7 +162,7 @@ func exportListCmdF(c client.Client, command *cobra.Command, args []string) erro
|
||||
func exportDeleteCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
if _, err := c.DeleteExport(name); err != nil {
|
||||
if _, err := c.DeleteExport(context.TODO(), name); err != nil {
|
||||
return fmt.Errorf("failed to delete export: %w", err)
|
||||
}
|
||||
|
||||
@@ -211,7 +212,7 @@ func exportDownloadCmdF(c client.Client, command *cobra.Command, args []string)
|
||||
return fmt.Errorf("failed to seek export file: %w", err)
|
||||
}
|
||||
|
||||
if _, _, err := c.DownloadExport(name, outFile, off); err != nil {
|
||||
if _, _, err := c.DownloadExport(context.TODO(), name, outFile, off); err != nil {
|
||||
printer.PrintWarning(fmt.Sprintf("failed to download export file: %v. Retrying...", err))
|
||||
i++
|
||||
continue
|
||||
@@ -231,7 +232,7 @@ func exportJobListCmdF(c client.Client, command *cobra.Command, args []string) e
|
||||
}
|
||||
|
||||
func exportJobShowCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
job, _, err := c.GetJob(args[0])
|
||||
job, _, err := c.GetJob(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get export job: %w", err)
|
||||
}
|
||||
@@ -242,12 +243,12 @@ func exportJobShowCmdF(c client.Client, command *cobra.Command, args []string) e
|
||||
}
|
||||
|
||||
func exportJobCancelCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
job, _, err := c.GetJob(args[0])
|
||||
job, _, err := c.GetJob(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get export job: %w", err)
|
||||
}
|
||||
|
||||
if _, err := c.CancelJob(job.Id); err != nil {
|
||||
if _, err := c.CancelJob(context.TODO(), job.Id); err != nil {
|
||||
return fmt.Errorf("failed to cancel export job: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -23,7 +24,7 @@ func (s *MmctlUnitTestSuite) TestExportCreateCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateJob(mockJob).
|
||||
CreateJob(context.Background(), mockJob).
|
||||
Return(mockJob, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -43,7 +44,7 @@ func (s *MmctlUnitTestSuite) TestExportCreateCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateJob(mockJob).
|
||||
CreateJob(context.Background(), mockJob).
|
||||
Return(mockJob, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -65,7 +66,7 @@ func (s *MmctlUnitTestSuite) TestExportDeleteCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteExport(exportName).
|
||||
DeleteExport(context.Background(), exportName).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -83,7 +84,7 @@ func (s *MmctlUnitTestSuite) TestExportListCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ListExports().
|
||||
ListExports(context.Background()).
|
||||
Return(mockExports, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -104,7 +105,7 @@ func (s *MmctlUnitTestSuite) TestExportListCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ListExports().
|
||||
ListExports(context.Background()).
|
||||
Return(mockExports, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -80,7 +81,7 @@ func extractRunCmdF(c client.Client, command *cobra.Command, args []string) erro
|
||||
to = model.GetMillis() / 1000
|
||||
}
|
||||
|
||||
job, _, err := c.CreateJob(&model.Job{
|
||||
job, _, err := c.CreateJob(context.TODO(), &model.Job{
|
||||
Type: model.JobTypeExtractContent,
|
||||
Data: map[string]string{
|
||||
"from": strconv.FormatInt(from, 10),
|
||||
@@ -97,7 +98,7 @@ func extractRunCmdF(c client.Client, command *cobra.Command, args []string) erro
|
||||
}
|
||||
|
||||
func extractJobShowCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
job, _, err := c.GetJob(args[0])
|
||||
job, _, err := c.GetJob(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get content extraction job: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -45,7 +46,7 @@ func (s *MmctlE2ETestSuite) TestExtractRunCmdF() {
|
||||
info, err := file.Stat()
|
||||
s.Require().NoError(err)
|
||||
|
||||
us, _, err := s.th.SystemAdminClient.CreateUpload(&model.UploadSession{
|
||||
us, _, err := s.th.SystemAdminClient.CreateUpload(context.Background(), &model.UploadSession{
|
||||
ChannelId: s.th.BasicChannel.Id,
|
||||
Filename: info.Name(),
|
||||
FileSize: info.Size(),
|
||||
@@ -53,7 +54,7 @@ func (s *MmctlE2ETestSuite) TestExtractRunCmdF() {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(us)
|
||||
|
||||
_, _, err = s.th.SystemAdminClient.UploadData(us.Id, file)
|
||||
_, _, err = s.th.SystemAdminClient.UploadData(context.Background(), us.Id, file)
|
||||
s.Require().NoError(err)
|
||||
|
||||
cmd := &cobra.Command{}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
@@ -149,7 +150,7 @@ func init() {
|
||||
}
|
||||
|
||||
func listLdapGroupsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
groups, _, err := c.GetLdapGroups()
|
||||
groups, _, err := c.GetLdapGroups(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -174,7 +175,7 @@ func channelGroupEnableCmdF(c client.Client, cmd *cobra.Command, args []string)
|
||||
},
|
||||
}
|
||||
|
||||
groups, _, _, err := c.GetGroupsByChannel(channel.Id, *groupOpts)
|
||||
groups, _, _, err := c.GetGroupsByChannel(context.TODO(), channel.Id, *groupOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -184,7 +185,7 @@ func channelGroupEnableCmdF(c client.Client, cmd *cobra.Command, args []string)
|
||||
}
|
||||
|
||||
channelPatch := model.ChannelPatch{GroupConstrained: model.NewBool(true)}
|
||||
if _, _, err = c.PatchChannel(channel.Id, &channelPatch); err != nil {
|
||||
if _, _, err = c.PatchChannel(context.TODO(), channel.Id, &channelPatch); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -198,7 +199,7 @@ func channelGroupDisableCmdF(c client.Client, cmd *cobra.Command, args []string)
|
||||
}
|
||||
|
||||
channelPatch := model.ChannelPatch{GroupConstrained: model.NewBool(false)}
|
||||
if _, _, err := c.PatchChannel(channel.Id, &channelPatch); err != nil {
|
||||
if _, _, err := c.PatchChannel(context.TODO(), channel.Id, &channelPatch); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -234,7 +235,7 @@ func channelGroupListCmdF(c client.Client, cmd *cobra.Command, args []string) er
|
||||
PerPage: 9999,
|
||||
},
|
||||
}
|
||||
groups, _, _, err := c.GetGroupsByChannel(channel.Id, groupOpts)
|
||||
groups, _, _, err := c.GetGroupsByChannel(context.TODO(), channel.Id, groupOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -258,7 +259,7 @@ func teamGroupEnableCmdF(c client.Client, cmd *cobra.Command, args []string) err
|
||||
PerPage: 10,
|
||||
},
|
||||
}
|
||||
groups, _, _, err := c.GetGroupsByTeam(team.Id, groupOpts)
|
||||
groups, _, _, err := c.GetGroupsByTeam(context.TODO(), team.Id, groupOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -268,7 +269,7 @@ func teamGroupEnableCmdF(c client.Client, cmd *cobra.Command, args []string) err
|
||||
}
|
||||
|
||||
teamPatch := model.TeamPatch{GroupConstrained: model.NewBool(true)}
|
||||
if _, _, err = c.PatchTeam(team.Id, &teamPatch); err != nil {
|
||||
if _, _, err = c.PatchTeam(context.TODO(), team.Id, &teamPatch); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -282,7 +283,7 @@ func teamGroupDisableCmdF(c client.Client, cmd *cobra.Command, args []string) er
|
||||
}
|
||||
|
||||
teamPatch := model.TeamPatch{GroupConstrained: model.NewBool(false)}
|
||||
if _, _, err := c.PatchTeam(team.Id, &teamPatch); err != nil {
|
||||
if _, _, err := c.PatchTeam(context.TODO(), team.Id, &teamPatch); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -318,7 +319,7 @@ func teamGroupListCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
PerPage: 9999,
|
||||
},
|
||||
}
|
||||
groups, _, _, err := c.GetGroupsByTeam(team.Id, groupOpts)
|
||||
groups, _, _, err := c.GetGroupsByTeam(context.TODO(), team.Id, groupOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -332,7 +333,7 @@ func teamGroupListCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
|
||||
func userGroupRestoreCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
groupID := args[0]
|
||||
_, resp, err := c.RestoreGroup(groupID, "")
|
||||
_, resp, err := c.RestoreGroup(context.TODO(), groupID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -22,7 +23,7 @@ func (s *MmctlUnitTestSuite) TestListLdapGroupsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetLdapGroups().
|
||||
GetLdapGroups(context.Background()).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -42,7 +43,7 @@ func (s *MmctlUnitTestSuite) TestListLdapGroupsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetLdapGroups().
|
||||
GetLdapGroups(context.Background()).
|
||||
Return(mockList, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -64,13 +65,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(arg, "").
|
||||
GetTeam(context.Background(), arg, "").
|
||||
Return(nil, &model.Response{}, errors.New("")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(arg, "").
|
||||
GetTeamByName(context.Background(), arg, "").
|
||||
Return(nil, &model.Response{}, errors.New("")).
|
||||
Times(1)
|
||||
|
||||
@@ -95,13 +96,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(arg, "").
|
||||
GetTeam(context.Background(), arg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByTeam(mockTeam.Id, groupOpts).
|
||||
GetGroupsByTeam(context.Background(), mockTeam.Id, groupOpts).
|
||||
Return(nil, 0, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -125,13 +126,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(arg, "").
|
||||
GetTeam(context.Background(), arg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByTeam(mockTeam.Id, groupOpts).
|
||||
GetGroupsByTeam(context.Background(), mockTeam.Id, groupOpts).
|
||||
Return([]*model.GroupWithSchemeAdmin{}, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -157,19 +158,19 @@ func (s *MmctlUnitTestSuite) TestTeamGroupEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(arg, "").
|
||||
GetTeam(context.Background(), arg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByTeam(mockTeam.Id, groupOpts).
|
||||
GetGroupsByTeam(context.Background(), mockTeam.Id, groupOpts).
|
||||
Return([]*model.GroupWithSchemeAdmin{{}}, 1, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchTeam(mockTeam.Id, &teamPatch).
|
||||
PatchTeam(context.Background(), mockTeam.Id, &teamPatch).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -194,19 +195,19 @@ func (s *MmctlUnitTestSuite) TestTeamGroupEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(arg, "").
|
||||
GetTeam(context.Background(), arg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByTeam(mockTeam.Id, groupOpts).
|
||||
GetGroupsByTeam(context.Background(), mockTeam.Id, groupOpts).
|
||||
Return([]*model.GroupWithSchemeAdmin{{}}, 1, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchTeam(mockTeam.Id, &teamPatch).
|
||||
PatchTeam(context.Background(), mockTeam.Id, &teamPatch).
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -226,13 +227,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchTeam(teamArg, &teamPatch).
|
||||
PatchTeam(context.Background(), teamArg, &teamPatch).
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -247,13 +248,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -273,13 +274,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchTeam(teamArg, &teamPatch).
|
||||
PatchTeam(context.Background(), teamArg, &teamPatch).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -315,19 +316,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelID, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelID, *groupOpts).
|
||||
Return(mockGroups, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -362,19 +363,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelID, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelID, *groupOpts).
|
||||
Return(mockGroups, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -407,19 +408,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelID, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelID, *groupOpts).
|
||||
Return(mockGroups, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -441,19 +442,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelID, "").
|
||||
GetChannel(context.Background(), channelID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -474,13 +475,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamID, "").
|
||||
GetTeamByName(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -512,19 +513,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelID, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelID, *groupOpts).
|
||||
Return(nil, 0, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -547,19 +548,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelID, "").
|
||||
GetChannel(context.Background(), channelID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -581,13 +582,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamID, "").
|
||||
GetTeamByName(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -604,13 +605,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("team1", "").
|
||||
GetTeam(context.Background(), "team1", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName("team1", "").
|
||||
GetTeamByName(context.Background(), "team1", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -645,13 +646,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("team1", "").
|
||||
GetTeam(context.Background(), "team1", "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByTeam("team1", groupOpts).
|
||||
GetGroupsByTeam(context.Background(), "team1", groupOpts).
|
||||
Return(groups, 2, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -684,13 +685,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("team1", "").
|
||||
GetTeam(context.Background(), "team1", "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByTeam("team1", groupOpts).
|
||||
GetGroupsByTeam(context.Background(), "team1", groupOpts).
|
||||
Return(groups, 2, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -715,13 +716,13 @@ func (s *MmctlUnitTestSuite) TestTeamGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamID, "").
|
||||
GetTeamByName(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -741,7 +742,7 @@ func (s *MmctlUnitTestSuite) TestTeamGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(team, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -764,7 +765,7 @@ func (s *MmctlUnitTestSuite) TestTeamGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(team, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -787,7 +788,7 @@ func (s *MmctlUnitTestSuite) TestTeamGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(team, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -812,13 +813,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamID, "").
|
||||
GetTeamByName(context.Background(), teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -840,19 +841,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(team, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelID, "").
|
||||
GetChannel(context.Background(), channelID, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -875,13 +876,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(team, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(channel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -907,13 +908,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(team, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(channel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -939,13 +940,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(team, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelID, teamID, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelID, teamID, "").
|
||||
Return(channel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -978,25 +979,25 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelPart, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelPart, *groupOpts).
|
||||
Return(mockGroups, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchChannel(channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(true)}).
|
||||
PatchChannel(context.Background(), channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(true)}).
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1016,13 +1017,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -1044,19 +1045,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelPart, "").
|
||||
GetChannel(context.Background(), channelPart, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -1085,19 +1086,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelPart, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelPart, *groupOpts).
|
||||
Return(nil, 0, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -1128,25 +1129,25 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelPart, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelPart, *groupOpts).
|
||||
Return(mockGroups, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchChannel(channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(true)}).
|
||||
PatchChannel(context.Background(), channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(true)}).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -1175,19 +1176,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelPart, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelPart, *groupOpts).
|
||||
Return(mockGroups, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1207,13 +1208,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1234,19 +1235,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelPart, "").
|
||||
GetChannel(context.Background(), channelPart, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1277,31 +1278,31 @@ func (s *MmctlUnitTestSuite) TestChannelGroupEnableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelPart, "").
|
||||
GetChannel(context.Background(), channelPart, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetGroupsByChannel(channelPart, *groupOpts).
|
||||
GetGroupsByChannel(context.Background(), channelPart, *groupOpts).
|
||||
Return(mockGroups, 0, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchChannel(channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(true)}).
|
||||
PatchChannel(context.Background(), channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(true)}).
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1324,19 +1325,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupDisableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchChannel(channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(false)}).
|
||||
PatchChannel(context.Background(), channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(false)}).
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1355,13 +1356,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupDisableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1382,19 +1383,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupDisableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelPart, "").
|
||||
GetChannel(context.Background(), channelPart, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1417,25 +1418,25 @@ func (s *MmctlUnitTestSuite) TestChannelGroupDisableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchChannel(channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(false)}).
|
||||
PatchChannel(context.Background(), channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(false)}).
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1455,13 +1456,13 @@ func (s *MmctlUnitTestSuite) TestChannelGroupDisableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -1483,19 +1484,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupDisableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelPart, "").
|
||||
GetChannel(context.Background(), channelPart, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -1518,19 +1519,19 @@ func (s *MmctlUnitTestSuite) TestChannelGroupDisableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannelByNameIncludeDeleted(channelPart, teamArg, "").
|
||||
GetChannelByNameIncludeDeleted(context.Background(), channelPart, teamArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchChannel(channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(false)}).
|
||||
PatchChannel(context.Background(), channelPart, &model.ChannelPatch{GroupConstrained: model.NewBool(false)}).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -1548,7 +1549,7 @@ func (s *MmctlUnitTestSuite) TestUserGroupRestoreCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RestoreGroup("groupId", "").
|
||||
RestoreGroup(context.Background(), "groupId", "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -1565,7 +1566,7 @@ func (s *MmctlUnitTestSuite) TestUserGroupRestoreCmd() {
|
||||
mockError := errors.New("no group found")
|
||||
s.client.
|
||||
EXPECT().
|
||||
RestoreGroup("groupId", "").
|
||||
RestoreGroup(context.Background(), "groupId", "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, mockError).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -132,7 +133,7 @@ func importListIncompleteCmdF(c client.Client, command *cobra.Command, args []st
|
||||
userID = model.UploadNoUserID
|
||||
}
|
||||
|
||||
uploads, _, err := c.GetUploadsForUser(userID)
|
||||
uploads, _, err := c.GetUploadsForUser(context.TODO(), userID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get uploads: %w", err)
|
||||
}
|
||||
@@ -155,7 +156,7 @@ func importListIncompleteCmdF(c client.Client, command *cobra.Command, args []st
|
||||
}
|
||||
|
||||
func importListAvailableCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
imports, _, err := c.ListImports()
|
||||
imports, _, err := c.ListImports(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list imports: %w", err)
|
||||
}
|
||||
@@ -194,7 +195,7 @@ func importUploadCmdF(c client.Client, command *cobra.Command, args []string) er
|
||||
return errors.New("upload session ID is missing or invalid")
|
||||
}
|
||||
|
||||
us, _, err = c.GetUpload(uploadID)
|
||||
us, _, err = c.GetUpload(context.TODO(), uploadID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get upload session: %w", err)
|
||||
}
|
||||
@@ -213,7 +214,7 @@ func importUploadCmdF(c client.Client, command *cobra.Command, args []string) er
|
||||
userID = model.UploadNoUserID
|
||||
}
|
||||
|
||||
us, _, err = c.CreateUpload(&model.UploadSession{
|
||||
us, _, err = c.CreateUpload(context.TODO(), &model.UploadSession{
|
||||
Filename: info.Name(),
|
||||
FileSize: info.Size(),
|
||||
Type: model.UploadTypeImport,
|
||||
@@ -226,7 +227,7 @@ func importUploadCmdF(c client.Client, command *cobra.Command, args []string) er
|
||||
printer.PrintT("Upload session successfully created, ID: {{.Id}} ", us)
|
||||
}
|
||||
|
||||
finfo, _, err := c.UploadData(us.Id, file)
|
||||
finfo, _, err := c.UploadData(context.TODO(), us.Id, file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to upload data: %w", err)
|
||||
}
|
||||
@@ -239,7 +240,7 @@ func importUploadCmdF(c client.Client, command *cobra.Command, args []string) er
|
||||
func importProcessCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
importFile := args[0]
|
||||
|
||||
job, _, err := c.CreateJob(&model.Job{
|
||||
job, _, err := c.CreateJob(context.TODO(), &model.Job{
|
||||
Type: model.JobTypeImportProcess,
|
||||
Data: map[string]string{
|
||||
"import_file": importFile,
|
||||
@@ -273,7 +274,7 @@ func printJob(job *model.Job) {
|
||||
}
|
||||
|
||||
func importJobShowCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
job, _, err := c.GetJob(args[0])
|
||||
job, _, err := c.GetJob(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get import job: %w", err)
|
||||
}
|
||||
@@ -302,7 +303,7 @@ func jobListCmdF(c client.Client, command *cobra.Command, jobType string) error
|
||||
}
|
||||
|
||||
for {
|
||||
jobs, _, err := c.GetJobsByType(jobType, page, perPage)
|
||||
jobs, _, err := c.GetJobsByType(context.TODO(), jobType, page, perPage)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get jobs: %w", err)
|
||||
}
|
||||
@@ -356,7 +357,9 @@ func importValidateCmdF(command *cobra.Command, args []string) error {
|
||||
)
|
||||
|
||||
err := withClient(func(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
users, err := getPages(c.GetUsers, 250)
|
||||
users, err := getPages(func(page, numPerPage int, etag string) ([]*model.User, *model.Response, error) {
|
||||
return c.GetUsers(context.TODO(), page, numPerPage, etag)
|
||||
}, 250)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -369,7 +372,7 @@ func importValidateCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
teams, err := getPages(func(page, numPerPage int, etag string) ([]*model.Team, *model.Response, error) {
|
||||
return c.GetAllTeams(etag, page, numPerPage)
|
||||
return c.GetAllTeams(context.TODO(), etag, page, numPerPage)
|
||||
}, 250)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -380,14 +383,14 @@ func importValidateCmdF(command *cobra.Command, args []string) error {
|
||||
serverTeams[team.Name] = team
|
||||
|
||||
publicChannels, err := getPages(func(page, numPerPage int, etag string) ([]*model.Channel, *model.Response, error) {
|
||||
return c.GetPublicChannelsForTeam(team.Id, page, numPerPage, etag)
|
||||
return c.GetPublicChannelsForTeam(context.TODO(), team.Id, page, numPerPage, etag)
|
||||
}, 250)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
privateChannels, err := getPages(func(page, numPerPage int, etag string) ([]*model.Channel, *model.Response, error) {
|
||||
return c.GetPrivateChannelsForTeam(team.Id, page, numPerPage, etag)
|
||||
return c.GetPrivateChannelsForTeam(context.TODO(), team.Id, page, numPerPage, etag)
|
||||
}, 250)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -67,7 +68,7 @@ func (s *MmctlE2ETestSuite) TestImportUploadCmdF() {
|
||||
userID = "nouser"
|
||||
}
|
||||
|
||||
us, _, err := c.CreateUpload(&model.UploadSession{
|
||||
us, _, err := c.CreateUpload(context.TODO(), &model.UploadSession{
|
||||
Filename: importName,
|
||||
FileSize: 276051,
|
||||
Type: model.UploadTypeImport,
|
||||
@@ -197,7 +198,7 @@ func (s *MmctlE2ETestSuite) TestImportListIncompleteCmdF() {
|
||||
cmd := &cobra.Command{}
|
||||
userID := "nouser"
|
||||
if c == s.th.SystemAdminClient {
|
||||
user, _, err := s.th.SystemAdminClient.GetMe("")
|
||||
user, _, err := s.th.SystemAdminClient.GetMe(context.Background(), "")
|
||||
s.Require().NoError(err)
|
||||
userID = user.Id
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -21,7 +22,7 @@ func (s *MmctlUnitTestSuite) TestImportListAvailableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ListImports().
|
||||
ListImports(context.Background()).
|
||||
Return(mockImports, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -42,7 +43,7 @@ func (s *MmctlUnitTestSuite) TestImportListAvailableCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ListImports().
|
||||
ListImports(context.Background()).
|
||||
Return(mockImports, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -63,7 +64,7 @@ func (s *MmctlUnitTestSuite) TestImportListIncompleteCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUploadsForUser("me").
|
||||
GetUploadsForUser(context.Background(), "me").
|
||||
Return(mockUploads, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -93,7 +94,7 @@ func (s *MmctlUnitTestSuite) TestImportListIncompleteCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUploadsForUser("me").
|
||||
GetUploadsForUser(context.Background(), "me").
|
||||
Return(mockUploads, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -114,7 +115,7 @@ func (s *MmctlUnitTestSuite) TestImportJobShowCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetJob(jobID).
|
||||
GetJob(context.Background(), jobID).
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, errors.New("not found")).
|
||||
Times(1)
|
||||
|
||||
@@ -132,7 +133,7 @@ func (s *MmctlUnitTestSuite) TestImportJobShowCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetJob(mockJob.Id).
|
||||
GetJob(context.Background(), mockJob.Id).
|
||||
Return(mockJob, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -157,7 +158,7 @@ func (s *MmctlUnitTestSuite) TestImportJobListCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetJobsByType(model.JobTypeImportProcess, 0, perPage).
|
||||
GetJobsByType(context.Background(), model.JobTypeImportProcess, 0, perPage).
|
||||
Return(mockJobs, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -190,7 +191,7 @@ func (s *MmctlUnitTestSuite) TestImportJobListCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetJobsByType(model.JobTypeImportProcess, 0, perPage).
|
||||
GetJobsByType(context.Background(), model.JobTypeImportProcess, 0, perPage).
|
||||
Return(mockJobs, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -214,7 +215,7 @@ func (s *MmctlUnitTestSuite) TestImportProcessCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateJob(mockJob).
|
||||
CreateJob(context.Background(), mockJob).
|
||||
Return(mockJob, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
@@ -72,7 +73,9 @@ func withClient(fn func(c client.Client, cmd *cobra.Command, args []string) erro
|
||||
return fn(c, cmd, args)
|
||||
}
|
||||
|
||||
c, serverVersion, err := InitClient(viper.GetBool("insecure-sha1-intermediate"), viper.GetBool("insecure-tls-version"))
|
||||
ctx := context.TODO()
|
||||
|
||||
c, serverVersion, err := InitClient(ctx, viper.GetBool("insecure-sha1-intermediate"), viper.GetBool("insecure-tls-version"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -163,32 +166,32 @@ func NewAPIv4Client(instanceURL string, allowInsecureSHA1, allowInsecureTLS bool
|
||||
return client
|
||||
}
|
||||
|
||||
func InitClientWithUsernameAndPassword(username, password, instanceURL string, allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
func InitClientWithUsernameAndPassword(ctx context.Context, username, password, instanceURL string, allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
client := NewAPIv4Client(instanceURL, allowInsecureSHA1, allowInsecureTLS)
|
||||
|
||||
_, resp, err := client.Login(username, password)
|
||||
_, resp, err := client.Login(ctx, username, password)
|
||||
if err != nil {
|
||||
return nil, "", checkInsecureTLSError(err, allowInsecureTLS)
|
||||
}
|
||||
return client, resp.ServerVersion, nil
|
||||
}
|
||||
|
||||
func InitClientWithMFA(username, password, mfaToken, instanceURL string, allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
func InitClientWithMFA(ctx context.Context, username, password, mfaToken, instanceURL string, allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
client := NewAPIv4Client(instanceURL, allowInsecureSHA1, allowInsecureTLS)
|
||||
_, resp, err := client.LoginWithMFA(username, password, mfaToken)
|
||||
_, resp, err := client.LoginWithMFA(ctx, username, password, mfaToken)
|
||||
if err != nil {
|
||||
return nil, "", checkInsecureTLSError(err, allowInsecureTLS)
|
||||
}
|
||||
return client, resp.ServerVersion, nil
|
||||
}
|
||||
|
||||
func InitClientWithCredentials(credentials *Credentials, allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
func InitClientWithCredentials(ctx context.Context, credentials *Credentials, allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
client := NewAPIv4Client(credentials.InstanceURL, allowInsecureSHA1, allowInsecureTLS)
|
||||
|
||||
client.AuthType = model.HeaderBearer
|
||||
client.AuthToken = credentials.AuthToken
|
||||
|
||||
_, resp, err := client.GetMe("")
|
||||
_, resp, err := client.GetMe(ctx, "")
|
||||
if err != nil {
|
||||
return nil, "", checkInsecureTLSError(err, allowInsecureTLS)
|
||||
}
|
||||
@@ -196,12 +199,12 @@ func InitClientWithCredentials(credentials *Credentials, allowInsecureSHA1, allo
|
||||
return client, resp.ServerVersion, nil
|
||||
}
|
||||
|
||||
func InitClient(allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
func InitClient(ctx context.Context, allowInsecureSHA1, allowInsecureTLS bool) (*model.Client4, string, error) {
|
||||
credentials, err := GetCurrentCredentials()
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return InitClientWithCredentials(credentials, allowInsecureSHA1, allowInsecureTLS)
|
||||
return InitClientWithCredentials(ctx, credentials, allowInsecureSHA1, allowInsecureTLS)
|
||||
}
|
||||
|
||||
func InitWebSocketClient() (*model.WebSocketClient, error) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"net"
|
||||
@@ -189,7 +190,7 @@ func TestNewAPIv4Client(t *testing.T) {
|
||||
defer os.Unsetenv("HTTP_PROXY")
|
||||
|
||||
client := NewAPIv4Client("http://somethingelse:"+port, false, false)
|
||||
_, _, err = client.GetMe("")
|
||||
_, _, err = client.GetMe(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
@@ -84,7 +85,7 @@ func integrityCmdF(c client.Client, command *cobra.Command, args []string) error
|
||||
|
||||
verboseFlag, _ := command.Flags().GetBool("verbose")
|
||||
|
||||
results, _, err := c.CheckIntegrity()
|
||||
results, _, err := c.CheckIntegrity(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to perform integrity check. Error: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
@@ -40,7 +41,7 @@ func (s *MmctlUnitTestSuite) TestIntegrityCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
CheckIntegrity().
|
||||
CheckIntegrity(context.Background()).
|
||||
Return(mockResults, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -58,7 +59,7 @@ func (s *MmctlUnitTestSuite) TestIntegrityCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CheckIntegrity().
|
||||
CheckIntegrity(context.Background()).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -98,7 +99,7 @@ func (s *MmctlUnitTestSuite) TestIntegrityCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
CheckIntegrity().
|
||||
CheckIntegrity(context.Background()).
|
||||
Return(mockResults, &model.Response{}, nil).
|
||||
Times(1)
|
||||
var expected error
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -53,7 +54,7 @@ func ldapSyncCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
|
||||
includeRemovedMembers, _ := cmd.Flags().GetBool("include-removed-members")
|
||||
|
||||
resp, err := c.SyncLdap(includeRemovedMembers)
|
||||
resp, err := c.SyncLdap(context.TODO(), includeRemovedMembers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -69,7 +70,7 @@ func ldapSyncCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
|
||||
func ldapIDMigrateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
toAttribute := args[0]
|
||||
resp, err := c.MigrateIdLdap(toAttribute)
|
||||
resp, err := c.MigrateIdLdap(context.TODO(), toAttribute)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
@@ -21,7 +22,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SyncLdap(false).
|
||||
SyncLdap(context.Background(), false).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -38,7 +39,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SyncLdap(false).
|
||||
SyncLdap(context.Background(), false).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -55,7 +56,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SyncLdap(false).
|
||||
SyncLdap(context.Background(), false).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -73,7 +74,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SyncLdap(true).
|
||||
SyncLdap(context.Background(), true).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -88,7 +89,7 @@ func (s *MmctlUnitTestSuite) TestLdapMigrateID() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
MigrateIdLdap("test-id").
|
||||
MigrateIdLdap(context.Background(), "test-id").
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -104,7 +105,7 @@ func (s *MmctlUnitTestSuite) TestLdapMigrateID() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
MigrateIdLdap("test-id").
|
||||
MigrateIdLdap(context.Background(), "test-id").
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("test-error")).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
|
||||
@@ -56,7 +57,7 @@ func uploadLicenseStringCmdF(c client.Client, cmd *cobra.Command, args []string)
|
||||
|
||||
licenseBytes := []byte(args[0])
|
||||
|
||||
if _, err := c.UploadLicenseFile(licenseBytes); err != nil {
|
||||
if _, err := c.UploadLicenseFile(context.TODO(), licenseBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ func uploadLicenseCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := c.UploadLicenseFile(fileBytes); err != nil {
|
||||
if _, err := c.UploadLicenseFile(context.TODO(), fileBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ func uploadLicenseCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
func removeLicenseCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
if _, err := c.RemoveLicenseFile(); err != nil {
|
||||
if _, err := c.RemoveLicenseFile(context.TODO()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -25,7 +26,7 @@ func (s *MmctlUnitTestSuite) TestRemoveLicenseCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveLicenseFile().
|
||||
RemoveLicenseFile(context.Background()).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -42,7 +43,7 @@ func (s *MmctlUnitTestSuite) TestRemoveLicenseCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveLicenseFile().
|
||||
RemoveLicenseFile(context.Background()).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockErr).
|
||||
Times(1)
|
||||
|
||||
@@ -72,7 +73,7 @@ func (s *MmctlUnitTestSuite) TestUploadLicenseCmdF() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadLicenseFile(mockLicenseFile).
|
||||
UploadLicenseFile(context.Background(), mockLicenseFile).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -86,7 +87,7 @@ func (s *MmctlUnitTestSuite) TestUploadLicenseCmdF() {
|
||||
errMsg := "open " + path + ": no such file or directory"
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadLicenseFile(mockLicenseFile).
|
||||
UploadLicenseFile(context.Background(), mockLicenseFile).
|
||||
Times(0)
|
||||
|
||||
err := uploadLicenseCmdF(s.client, &cobra.Command{}, []string{path})
|
||||
@@ -110,7 +111,7 @@ func (s *MmctlUnitTestSuite) TestUploadLicenseStringCmdF() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadLicenseFile(mockLicenseFile).
|
||||
UploadLicenseFile(context.Background(), mockLicenseFile).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -39,7 +40,7 @@ func logsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
number, _ := cmd.Flags().GetInt("number")
|
||||
logLines, _, err := c.GetLogs(0, number)
|
||||
logLines, _, err := c.GetLogs(context.TODO(), 0, number)
|
||||
if err != nil {
|
||||
return errors.New("Unable to retrieve logs. Error: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -31,7 +32,7 @@ func (s *MmctlUnitTestSuite) TestLogsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetLogs(0, 1).
|
||||
GetLogs(context.Background(), 0, 1).
|
||||
Return(mockSingleLogLine, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -48,7 +49,7 @@ func (s *MmctlUnitTestSuite) TestLogsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetLogs(0, 0).
|
||||
GetLogs(context.Background(), 0, 0).
|
||||
Return(mockSingleLogLine, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -67,7 +68,7 @@ func (s *MmctlUnitTestSuite) TestLogsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetLogs(0, 1).
|
||||
GetLogs(context.Background(), 0, 1).
|
||||
Return(mockSingleLogLine, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -33,25 +34,25 @@ func (s *MmctlUnitTestSuite) TestAssignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Username, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Username, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Username, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(mockUser.Id, fmt.Sprintf("%s %s", mockUser.Roles, mockRole.Name)).
|
||||
UpdateUserRoles(context.Background(), mockUser.Id, fmt.Sprintf("%s %s", mockUser.Roles, mockRole.Name)).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -85,45 +86,45 @@ func (s *MmctlUnitTestSuite) TestAssignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
for _, user := range []*model.User{mockUser1, mockUser2} {
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(user.Username, "").
|
||||
GetUserByEmail(context.Background(), user.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(user.Username, "").
|
||||
GetUserByUsername(context.Background(), user.Username, "").
|
||||
Return(user, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(user.Id, fmt.Sprintf("%s %s", user.Roles, mockRole.Name)).
|
||||
UpdateUserRoles(context.Background(), user.Id, fmt.Sprintf("%s %s", user.Roles, mockRole.Name)).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
}
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(notFoundUser.Username, "").
|
||||
GetUserByEmail(context.Background(), notFoundUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(notFoundUser.Username, "").
|
||||
GetUserByUsername(context.Background(), notFoundUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(notFoundUser.Username, "").
|
||||
GetUser(context.Background(), notFoundUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -141,7 +142,7 @@ func (s *MmctlUnitTestSuite) TestAssignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName("non-existent").
|
||||
GetRoleByName(context.Background(), "non-existent").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, expectedError).
|
||||
Times(1)
|
||||
|
||||
@@ -166,19 +167,19 @@ func (s *MmctlUnitTestSuite) TestAssignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Username, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Username, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Username, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -198,25 +199,25 @@ func (s *MmctlUnitTestSuite) TestAssignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(requestedUser, "").
|
||||
GetUserByEmail(context.Background(), requestedUser, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(requestedUser, "").
|
||||
GetUserByUsername(context.Background(), requestedUser, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(requestedUser, "").
|
||||
GetUser(context.Background(), requestedUser, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -242,19 +243,19 @@ func (s *MmctlUnitTestSuite) TestUnassignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Username, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Username, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Username, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(mockUser.Id, "system_user team_admin").
|
||||
UpdateUserRoles(context.Background(), mockUser.Id, "system_user team_admin").
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -285,38 +286,38 @@ func (s *MmctlUnitTestSuite) TestUnassignUsersCmd() {
|
||||
for _, user := range []*model.User{mockUser1, mockUser2} {
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(user.Username, "").
|
||||
GetUserByEmail(context.Background(), user.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(user.Username, "").
|
||||
GetUserByUsername(context.Background(), user.Username, "").
|
||||
Return(user, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateUserRoles(user.Id, strings.TrimSpace(strings.ReplaceAll(user.Roles, roleName, ""))).
|
||||
UpdateUserRoles(context.Background(), user.Id, strings.TrimSpace(strings.ReplaceAll(user.Roles, roleName, ""))).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
}
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(notFoundUser.Username, "").
|
||||
GetUserByEmail(context.Background(), notFoundUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(notFoundUser.Username, "").
|
||||
GetUserByUsername(context.Background(), notFoundUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(notFoundUser.Username, "").
|
||||
GetUser(context.Background(), notFoundUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -336,13 +337,13 @@ func (s *MmctlUnitTestSuite) TestUnassignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Username, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Username, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Username, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Username, "").
|
||||
Return(mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -356,19 +357,19 @@ func (s *MmctlUnitTestSuite) TestUnassignUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(requestedUser, "").
|
||||
GetUserByEmail(context.Background(), requestedUser, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(requestedUser, "").
|
||||
GetUserByUsername(context.Background(), requestedUser, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(requestedUser, "").
|
||||
GetUser(context.Background(), requestedUser, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -392,7 +393,7 @@ func (s *MmctlUnitTestSuite) TestShowRoleCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -424,7 +425,7 @@ SchemeManaged false
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -454,7 +455,7 @@ Permissions edit_brand
|
||||
// showRoleCmdF will look up role by name
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(commandArgBogus).
|
||||
GetRoleByName(context.Background(), commandArgBogus).
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, expectedError).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
@@ -71,7 +72,7 @@ func init() {
|
||||
}
|
||||
|
||||
func addPermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
role, _, err := c.GetRoleByName(args[0])
|
||||
role, _, err := c.GetRoleByName(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -92,7 +93,7 @@ func addPermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) erro
|
||||
Permissions: &newPermissions,
|
||||
}
|
||||
|
||||
if _, _, err = c.PatchRole(role.Id, &patchRole); err != nil {
|
||||
if _, _, err = c.PatchRole(context.TODO(), role.Id, &patchRole); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ func addPermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) erro
|
||||
}
|
||||
|
||||
func removePermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
role, _, err := c.GetRoleByName(args[0])
|
||||
role, _, err := c.GetRoleByName(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -131,7 +132,7 @@ func removePermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) e
|
||||
Permissions: &newPermissionSet,
|
||||
}
|
||||
|
||||
if _, _, err = c.PatchRole(role.Id, &patchRole); err != nil {
|
||||
if _, _, err = c.PatchRole(context.TODO(), role.Id, &patchRole); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ func removePermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) e
|
||||
}
|
||||
|
||||
func resetPermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
role, _, err := c.GetRoleByName(args[0])
|
||||
role, _, err := c.GetRoleByName(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -153,7 +154,7 @@ func resetPermissionsCmdF(c client.Client, cmd *cobra.Command, args []string) er
|
||||
Permissions: &defaultRole.Permissions,
|
||||
}
|
||||
|
||||
role, _, err = c.PatchRole(role.Id, &patchRole)
|
||||
role, _, err = c.PatchRole(context.TODO(), role.Id, &patchRole)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -146,7 +147,7 @@ func prettyRole(role *model.Role) string {
|
||||
}
|
||||
|
||||
func showRoleCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
role, _, err := c.GetRoleByName(args[0])
|
||||
role, _, err := c.GetRoleByName(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -157,7 +158,7 @@ func showRoleCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func assignUsersCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
role, _, err := c.GetRoleByName(args[0])
|
||||
role, _, err := c.GetRoleByName(context.TODO(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -186,7 +187,7 @@ func assignUsersCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
|
||||
userRoles := startingRoles
|
||||
userRoles = append(userRoles, role.Name)
|
||||
_, err = c.UpdateUserRoles(user.Id, strings.Join(userRoles, " "))
|
||||
_, err = c.UpdateUserRoles(context.TODO(), user.Id, strings.Join(userRoles, " "))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -215,7 +216,7 @@ func unassignUsersCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
if originalCount > len(userRoles) {
|
||||
_, err := c.UpdateUserRoles(user.Id, strings.Join(userRoles, " "))
|
||||
_, err := c.UpdateUserRoles(context.TODO(), user.Id, strings.Join(userRoles, " "))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
@@ -31,13 +32,13 @@ func (s *MmctlUnitTestSuite) TestAddPermissionsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchRole(mockRole.Id, expectedPatch).
|
||||
PatchRole(context.Background(), mockRole.Id, expectedPatch).
|
||||
Return(&model.Role{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -51,7 +52,7 @@ func (s *MmctlUnitTestSuite) TestAddPermissionsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(gomock.Any()).
|
||||
GetRoleByName(context.Background(), gomock.Any()).
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, expectedError).
|
||||
Times(1)
|
||||
|
||||
@@ -70,7 +71,7 @@ func (s *MmctlUnitTestSuite) TestAddPermissionsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -82,7 +83,7 @@ func (s *MmctlUnitTestSuite) TestAddPermissionsCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchRole(mockRole.Id, expectedPatch).
|
||||
PatchRole(context.Background(), mockRole.Id, expectedPatch).
|
||||
Return(&model.Role{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
args := []string{mockRole.Name, newPermission}
|
||||
@@ -106,12 +107,12 @@ func (s *MmctlUnitTestSuite) TestRemovePermissionsCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchRole(mockRole.Id, expectedPatch).
|
||||
PatchRole(context.Background(), mockRole.Id, expectedPatch).
|
||||
Return(&model.Role{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -132,12 +133,12 @@ func (s *MmctlUnitTestSuite) TestRemovePermissionsCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchRole(mockRole.Id, expectedPatch).
|
||||
PatchRole(context.Background(), mockRole.Id, expectedPatch).
|
||||
Return(&model.Role{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -158,12 +159,12 @@ func (s *MmctlUnitTestSuite) TestRemovePermissionsCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchRole(mockRole.Id, expectedPatch).
|
||||
PatchRole(context.Background(), mockRole.Id, expectedPatch).
|
||||
Return(&model.Role{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -180,7 +181,7 @@ func (s *MmctlUnitTestSuite) TestRemovePermissionsCmd() {
|
||||
mockError := errors.New("role_not_found")
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -200,7 +201,7 @@ func (s *MmctlUnitTestSuite) TestResetPermissionsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -218,7 +219,7 @@ func (s *MmctlUnitTestSuite) TestResetPermissionsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(&mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -241,13 +242,13 @@ func (s *MmctlUnitTestSuite) TestResetPermissionsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetRoleByName(mockRole.Name).
|
||||
GetRoleByName(context.Background(), mockRole.Name).
|
||||
Return(&mockRole, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PatchRole(mockRole.Id, expectedPatch).
|
||||
PatchRole(context.Background(), mockRole.Id, expectedPatch).
|
||||
Return(&model.Role{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/client"
|
||||
@@ -101,9 +102,9 @@ func pluginAddCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if force {
|
||||
_, _, err = c.UploadPluginForced(fileReader)
|
||||
_, _, err = c.UploadPluginForced(context.TODO(), fileReader)
|
||||
} else {
|
||||
_, _, err = c.UploadPlugin(fileReader)
|
||||
_, _, err = c.UploadPlugin(context.TODO(), fileReader)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -122,7 +123,7 @@ func pluginInstallURLCmdF(c client.Client, cmd *cobra.Command, args []string) er
|
||||
var multiErr *multierror.Error
|
||||
|
||||
for _, plugin := range args {
|
||||
manifest, _, err := c.InstallPluginFromURL(plugin, force)
|
||||
manifest, _, err := c.InstallPluginFromURL(context.TODO(), plugin, force)
|
||||
if err != nil {
|
||||
printer.PrintError("Unable to install plugin from URL \"" + plugin + "\". Error: " + err.Error())
|
||||
multiErr = multierror.Append(multiErr, err)
|
||||
@@ -136,7 +137,7 @@ func pluginInstallURLCmdF(c client.Client, cmd *cobra.Command, args []string) er
|
||||
|
||||
func pluginDeleteCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
for _, plugin := range args {
|
||||
if _, err := c.RemovePlugin(plugin); err != nil {
|
||||
if _, err := c.RemovePlugin(context.TODO(), plugin); err != nil {
|
||||
printer.PrintError("Unable to delete plugin: " + plugin + ". Error: " + err.Error())
|
||||
} else {
|
||||
printer.Print("Deleted plugin: " + plugin)
|
||||
@@ -148,7 +149,7 @@ func pluginDeleteCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
|
||||
func pluginEnableCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
for _, plugin := range args {
|
||||
if _, err := c.EnablePlugin(plugin); err != nil {
|
||||
if _, err := c.EnablePlugin(context.TODO(), plugin); err != nil {
|
||||
printer.PrintError("Unable to enable plugin: " + plugin + ". Error: " + err.Error())
|
||||
} else {
|
||||
printer.Print("Enabled plugin: " + plugin)
|
||||
@@ -160,7 +161,7 @@ func pluginEnableCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
|
||||
func pluginDisableCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
for _, plugin := range args {
|
||||
if _, err := c.DisablePlugin(plugin); err != nil {
|
||||
if _, err := c.DisablePlugin(context.TODO(), plugin); err != nil {
|
||||
printer.PrintError("Unable to disable plugin: " + plugin + ". Error: " + err.Error())
|
||||
} else {
|
||||
printer.Print("Disabled plugin: " + plugin)
|
||||
@@ -171,7 +172,7 @@ func pluginDisableCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
func pluginListCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
pluginsResp, _, err := c.GetPlugins()
|
||||
pluginsResp, _, err := c.GetPlugins(context.TODO())
|
||||
if err != nil {
|
||||
return errors.New("Unable to list plugins. Error: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/client"
|
||||
@@ -67,7 +69,7 @@ func pluginMarketplaceInstallCmdF(c client.Client, _ *cobra.Command, args []stri
|
||||
id := args[0]
|
||||
|
||||
pluginRequest := &model.InstallMarketplacePluginRequest{Id: id}
|
||||
manifest, _, err := c.InstallMarketplacePlugin(pluginRequest)
|
||||
manifest, _, err := c.InstallMarketplacePlugin(context.TODO(), pluginRequest)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "couldn't install plugin from marketplace")
|
||||
}
|
||||
@@ -96,7 +98,7 @@ func pluginMarketplaceListCmdF(c client.Client, cmd *cobra.Command, _ []string)
|
||||
LocalOnly: localOnly,
|
||||
}
|
||||
|
||||
plugins, _, err := c.GetMarketplacePlugins(pluginFilter)
|
||||
plugins, _, err := c.GetMarketplacePlugins(context.TODO(), pluginFilter)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to fetch plugins")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -31,7 +33,7 @@ func (s *MmctlUnitTestSuite) TestPluginMarketplaceInstallCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
InstallMarketplacePlugin(pluginRequest).
|
||||
InstallMarketplacePlugin(context.Background(), pluginRequest).
|
||||
Return(manifest, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -51,7 +53,7 @@ func (s *MmctlUnitTestSuite) TestPluginMarketplaceInstallCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
InstallMarketplacePlugin(pluginRequest).
|
||||
InstallMarketplacePlugin(context.Background(), pluginRequest).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -75,7 +77,7 @@ func (s *MmctlUnitTestSuite) TestPluginMarketplaceListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetMarketplacePlugins(pluginFilter).
|
||||
GetMarketplacePlugins(context.Background(), pluginFilter).
|
||||
Return(plugins, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -97,19 +99,19 @@ func (s *MmctlUnitTestSuite) TestPluginMarketplaceListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetMarketplacePlugins(&model.MarketplacePluginFilter{Page: 0, PerPage: 1}).
|
||||
GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Page: 0, PerPage: 1}).
|
||||
Return([]*model.MarketplacePlugin{mockPlugin1}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetMarketplacePlugins(&model.MarketplacePluginFilter{Page: 1, PerPage: 1}).
|
||||
GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Page: 1, PerPage: 1}).
|
||||
Return([]*model.MarketplacePlugin{mockPlugin2}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetMarketplacePlugins(&model.MarketplacePluginFilter{Page: 2, PerPage: 1}).
|
||||
GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Page: 2, PerPage: 1}).
|
||||
Return([]*model.MarketplacePlugin{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -129,7 +131,7 @@ func (s *MmctlUnitTestSuite) TestPluginMarketplaceListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetMarketplacePlugins(&model.MarketplacePluginFilter{Page: 0, PerPage: 200}).
|
||||
GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Page: 0, PerPage: 200}).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -153,7 +155,7 @@ func (s *MmctlUnitTestSuite) TestPluginMarketplaceListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetMarketplacePlugins(pluginFilter).
|
||||
GetMarketplacePlugins(context.Background(), pluginFilter).
|
||||
Return(plugins, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -30,7 +31,7 @@ func (s *MmctlUnitTestSuite) TestPluginAddCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadPlugin(gomock.AssignableToTypeOf(tmpFile)).
|
||||
UploadPlugin(context.Background(), gomock.AssignableToTypeOf(tmpFile)).
|
||||
Return(&model.Manifest{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -50,7 +51,7 @@ func (s *MmctlUnitTestSuite) TestPluginAddCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadPluginForced(gomock.AssignableToTypeOf(tmpFile)).
|
||||
UploadPluginForced(context.Background(), gomock.AssignableToTypeOf(tmpFile)).
|
||||
Return(&model.Manifest{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -81,7 +82,7 @@ func (s *MmctlUnitTestSuite) TestPluginAddCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadPlugin(gomock.AssignableToTypeOf(tmpFile)).
|
||||
UploadPlugin(context.Background(), gomock.AssignableToTypeOf(tmpFile)).
|
||||
Return(&model.Manifest{}, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -103,13 +104,13 @@ func (s *MmctlUnitTestSuite) TestPluginAddCmd() {
|
||||
if arg == "fail" {
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadPlugin(gomock.AssignableToTypeOf(tmpFile)).
|
||||
UploadPlugin(context.Background(), gomock.AssignableToTypeOf(tmpFile)).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
} else {
|
||||
s.client.
|
||||
EXPECT().
|
||||
UploadPlugin(gomock.AssignableToTypeOf(tmpFile)).
|
||||
UploadPlugin(context.Background(), gomock.AssignableToTypeOf(tmpFile)).
|
||||
Return(&model.Manifest{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
}
|
||||
@@ -138,13 +139,13 @@ func (s *MmctlUnitTestSuite) TestPluginInstallUrlCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
InstallPluginFromURL(pluginURL1, false).
|
||||
InstallPluginFromURL(context.Background(), pluginURL1, false).
|
||||
Return(manifest1, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
InstallPluginFromURL(pluginURL2, false).
|
||||
InstallPluginFromURL(context.Background(), pluginURL2, false).
|
||||
Return(manifest2, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -164,7 +165,7 @@ func (s *MmctlUnitTestSuite) TestPluginInstallUrlCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
InstallPluginFromURL(pluginURL, true).
|
||||
InstallPluginFromURL(context.Background(), pluginURL, true).
|
||||
Return(manifest, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -188,13 +189,13 @@ func (s *MmctlUnitTestSuite) TestPluginInstallUrlCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
InstallPluginFromURL(pluginURL1, false).
|
||||
InstallPluginFromURL(context.Background(), pluginURL1, false).
|
||||
Return(manifest1, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
InstallPluginFromURL(pluginURL2, false).
|
||||
InstallPluginFromURL(context.Background(), pluginURL2, false).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -217,7 +218,7 @@ func (s *MmctlUnitTestSuite) TestPluginDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DisablePlugin(arg).
|
||||
DisablePlugin(context.Background(), arg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -235,7 +236,7 @@ func (s *MmctlUnitTestSuite) TestPluginDisableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DisablePlugin(arg).
|
||||
DisablePlugin(context.Background(), arg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -255,13 +256,13 @@ func (s *MmctlUnitTestSuite) TestPluginDisableCmd() {
|
||||
if strings.HasPrefix(arg, "fail") {
|
||||
s.client.
|
||||
EXPECT().
|
||||
DisablePlugin(arg).
|
||||
DisablePlugin(context.Background(), arg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
} else {
|
||||
s.client.
|
||||
EXPECT().
|
||||
DisablePlugin(arg).
|
||||
DisablePlugin(context.Background(), arg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
}
|
||||
@@ -285,7 +286,7 @@ func (s *MmctlUnitTestSuite) TestPluginEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
EnablePlugin(pluginArg).
|
||||
EnablePlugin(context.Background(), pluginArg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -303,7 +304,7 @@ func (s *MmctlUnitTestSuite) TestPluginEnableCmd() {
|
||||
for _, plugin := range plugins {
|
||||
s.client.
|
||||
EXPECT().
|
||||
EnablePlugin(plugin).
|
||||
EnablePlugin(context.Background(), plugin).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
}
|
||||
@@ -324,7 +325,7 @@ func (s *MmctlUnitTestSuite) TestPluginEnableCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
EnablePlugin(pluginArg).
|
||||
EnablePlugin(context.Background(), pluginArg).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockErr).
|
||||
Times(1)
|
||||
|
||||
@@ -347,7 +348,7 @@ func (s *MmctlUnitTestSuite) TestPluginEnableCmd() {
|
||||
for _, plugin := range okPlugins {
|
||||
s.client.
|
||||
EXPECT().
|
||||
EnablePlugin(plugin).
|
||||
EnablePlugin(context.Background(), plugin).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
}
|
||||
@@ -355,7 +356,7 @@ func (s *MmctlUnitTestSuite) TestPluginEnableCmd() {
|
||||
for _, plugin := range failPlugins {
|
||||
s.client.
|
||||
EXPECT().
|
||||
EnablePlugin(plugin).
|
||||
EnablePlugin(context.Background(), plugin).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockErr).
|
||||
Times(1)
|
||||
}
|
||||
@@ -424,7 +425,7 @@ func (s *MmctlUnitTestSuite) TestPluginListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPlugins().
|
||||
GetPlugins(context.Background()).
|
||||
Return(mockList, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -499,7 +500,7 @@ func (s *MmctlUnitTestSuite) TestPluginListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPlugins().
|
||||
GetPlugins(context.Background()).
|
||||
Return(mockList, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -525,7 +526,7 @@ func (s *MmctlUnitTestSuite) TestPluginListCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPlugins().
|
||||
GetPlugins(context.Background()).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -543,7 +544,7 @@ func (s *MmctlUnitTestSuite) TestPluginDeleteCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemovePlugin(args).
|
||||
RemovePlugin(context.Background(), args).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -560,7 +561,7 @@ func (s *MmctlUnitTestSuite) TestPluginDeleteCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemovePlugin(args).
|
||||
RemovePlugin(context.Background(), args).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -586,25 +587,25 @@ func (s *MmctlUnitTestSuite) TestPluginDeleteCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemovePlugin(args[0]).
|
||||
RemovePlugin(context.Background(), args[0]).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemovePlugin(args[1]).
|
||||
RemovePlugin(context.Background(), args[1]).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockErrors[0]).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemovePlugin(args[2]).
|
||||
RemovePlugin(context.Background(), args[2]).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockErrors[1]).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemovePlugin(args[3]).
|
||||
RemovePlugin(context.Background(), args[3]).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -70,7 +71,7 @@ func postCreateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
|
||||
replyTo, _ := cmd.Flags().GetString("reply-to")
|
||||
if replyTo != "" {
|
||||
replyToPost, _, err := c.GetPost(replyTo, "")
|
||||
replyToPost, _, err := c.GetPost(context.TODO(), replyTo, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -96,7 +97,7 @@ func postCreateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("could not decode post: %w", err)
|
||||
}
|
||||
|
||||
if _, err := c.DoAPIPost(url, data); err != nil {
|
||||
if _, err := c.DoAPIPost(context.TODO(), url, data); err != nil {
|
||||
return fmt.Errorf("could not create post: %s", err.Error())
|
||||
}
|
||||
return nil
|
||||
@@ -124,7 +125,7 @@ func printPost(c client.Client, post *model.Post, usernames map[string]string, s
|
||||
if usernames[post.UserId] != "" {
|
||||
username = usernames[post.UserId]
|
||||
} else {
|
||||
user, _, err := c.GetUser(post.UserId, "")
|
||||
user, _, err := c.GetUser(context.TODO(), post.UserId, "")
|
||||
if err != nil {
|
||||
username = post.UserId
|
||||
} else {
|
||||
@@ -149,7 +150,7 @@ func printPost(c client.Client, post *model.Post, usernames map[string]string, s
|
||||
|
||||
func getPostList(client client.Client, channelID, since string, perPage int) (*model.PostList, *model.Response, error) {
|
||||
if since == "" {
|
||||
return client.GetPostsForChannel(channelID, 0, perPage, "", false, false)
|
||||
return client.GetPostsForChannel(context.TODO(), channelID, 0, perPage, "", false, false)
|
||||
}
|
||||
|
||||
sinceTime, err := time.Parse(ISO8601Layout, since)
|
||||
@@ -158,7 +159,7 @@ func getPostList(client client.Client, channelID, since string, perPage int) (*m
|
||||
}
|
||||
|
||||
sinceTimeMillis := model.GetMillisForTime(sinceTime)
|
||||
return client.GetPostsSince(channelID, sinceTimeMillis, false)
|
||||
return client.GetPostsSince(context.TODO(), channelID, sinceTimeMillis, false)
|
||||
}
|
||||
|
||||
func postListCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
@@ -41,7 +42,7 @@ func (s *MmctlUnitTestSuite) TestPostCreateCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPost(replyToArg, "").
|
||||
GetPost(context.Background(), replyToArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("some-error")).
|
||||
Times(1)
|
||||
|
||||
@@ -62,13 +63,13 @@ func (s *MmctlUnitTestSuite) TestPostCreateCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelArg, "").
|
||||
GetChannel(context.Background(), channelArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DoAPIPost("/posts?set_online=false", data).
|
||||
DoAPIPost(context.Background(), "/posts?set_online=false", data).
|
||||
Return(nil, errors.New("some-error")).
|
||||
Times(1)
|
||||
|
||||
@@ -89,13 +90,13 @@ func (s *MmctlUnitTestSuite) TestPostCreateCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelArg, "").
|
||||
GetChannel(context.Background(), channelArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DoAPIPost("/posts?set_online=false", data).
|
||||
DoAPIPost(context.Background(), "/posts?set_online=false", data).
|
||||
Return(nil, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -121,19 +122,19 @@ func (s *MmctlUnitTestSuite) TestPostCreateCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelArg, "").
|
||||
GetChannel(context.Background(), channelArg, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPost(replyToArg, "").
|
||||
GetPost(context.Background(), replyToArg, "").
|
||||
Return(&mockReplyTo, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DoAPIPost("/posts?set_online=false", data).
|
||||
DoAPIPost(context.Background(), "/posts?set_online=false", data).
|
||||
Return(nil, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -160,7 +161,7 @@ func (s *MmctlUnitTestSuite) TestPostListCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelName, "").
|
||||
GetChannel(context.Background(), channelName, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -185,19 +186,19 @@ func (s *MmctlUnitTestSuite) TestPostListCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelName, "").
|
||||
GetChannel(context.Background(), channelName, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPostsForChannel(channelID, 0, 1, "", false, false).
|
||||
GetPostsForChannel(context.Background(), channelID, 0, 1, "", false, false).
|
||||
Return(mockPostList, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(userID, "").
|
||||
GetUser(context.Background(), userID, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -233,19 +234,19 @@ func (s *MmctlUnitTestSuite) TestPostListCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelName, "").
|
||||
GetChannel(context.Background(), channelName, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPostsSince(channelID, sinceTimeMillis, false).
|
||||
GetPostsSince(context.Background(), channelID, sinceTimeMillis, false).
|
||||
Return(mockPostList, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(userID, "").
|
||||
GetUser(context.Background(), userID, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -78,7 +79,7 @@ func rolesSystemAdminCmdF(c client.Client, _ *cobra.Command, args []string) erro
|
||||
|
||||
if !systemAdmin {
|
||||
roles = append(roles, model.SystemAdminRoleId)
|
||||
if _, err := c.UpdateUserRoles(user.Id, strings.Join(roles, " ")); err != nil {
|
||||
if _, err := c.UpdateUserRoles(context.TODO(), user.Id, strings.Join(roles, " ")); err != nil {
|
||||
updateErr := fmt.Errorf("can't update roles for user %q: %w", args[i], err)
|
||||
errs = multierror.Append(errs, updateErr)
|
||||
printer.PrintError(updateErr.Error())
|
||||
@@ -117,7 +118,7 @@ func rolesMemberCmdF(c client.Client, _ *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if shouldRemoveSysadmin {
|
||||
if _, err := c.UpdateUserRoles(user.Id, strings.Join(newRoles, " ")); err != nil {
|
||||
if _, err := c.UpdateUserRoles(context.TODO(), user.Id, strings.Join(newRoles, " ")); err != nil {
|
||||
updateErr := fmt.Errorf("can't update roles for user %q: %w", args[i], err)
|
||||
errs = multierror.Append(errs, updateErr)
|
||||
printer.PrintError(updateErr.Error())
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/client"
|
||||
@@ -59,7 +60,7 @@ func samlAuthDataResetCmdF(c client.Client, cmd *cobra.Command, args []string) e
|
||||
}
|
||||
}
|
||||
|
||||
numAffected, _, err := c.ResetSamlAuthDataToEmail(includeDeleted, dryRun, userIDs)
|
||||
numAffected, _, err := c.ResetSamlAuthDataToEmail(context.TODO(), includeDeleted, dryRun, userIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/printer"
|
||||
@@ -27,7 +29,7 @@ func (s *MmctlUnitTestSuite) TestSamlAuthDataReset() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ResetSamlAuthDataToEmail(false, false, []string{}).
|
||||
ResetSamlAuthDataToEmail(context.Background(), false, false, []string{}).
|
||||
Return(int64(1), &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -47,7 +49,7 @@ func (s *MmctlUnitTestSuite) TestSamlAuthDataReset() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
ResetSamlAuthDataToEmail(false, true, []string{}).
|
||||
ResetSamlAuthDataToEmail(context.Background(), false, true, []string{}).
|
||||
Return(int64(1), &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -63,7 +65,7 @@ func (s *MmctlUnitTestSuite) TestSamlAuthDataReset() {
|
||||
users := []string{"user1"}
|
||||
s.client.
|
||||
EXPECT().
|
||||
ResetSamlAuthDataToEmail(false, false, users).
|
||||
ResetSamlAuthDataToEmail(context.Background(), false, false, users).
|
||||
Return(int64(1), &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -93,7 +94,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
|
||||
}
|
||||
|
||||
// create session
|
||||
us, _, err := c.CreateUpload(&model.UploadSession{
|
||||
us, _, err := c.CreateUpload(context.TODO(), &model.UploadSession{
|
||||
Filename: info.Name(),
|
||||
FileSize: info.Size(),
|
||||
Type: model.UploadTypeImport,
|
||||
@@ -106,7 +107,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
|
||||
printer.PrintT("Upload session successfully created, ID: {{.Id}} ", us)
|
||||
|
||||
// upload file
|
||||
finfo, _, err := c.UploadData(us.Id, zipFile)
|
||||
finfo, _, err := c.UploadData(context.TODO(), us.Id, zipFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to upload data: %w", err)
|
||||
}
|
||||
@@ -114,7 +115,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
|
||||
printer.PrintT("Import file successfully uploaded, name: {{.Name}}", finfo)
|
||||
|
||||
// process
|
||||
job, _, err := c.CreateJob(&model.Job{
|
||||
job, _, err := c.CreateJob(context.TODO(), &model.Job{
|
||||
Type: model.JobTypeImportProcess,
|
||||
Data: map[string]string{
|
||||
"import_file": us.Id + "_" + finfo.Name,
|
||||
@@ -127,7 +128,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
|
||||
printer.PrintT("Import process job successfully created, ID: {{.Id}}", job)
|
||||
|
||||
for {
|
||||
job, _, err = c.GetJob(job.Id)
|
||||
job, _, err = c.GetJob(context.TODO(), job.Id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get import job status: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -80,7 +81,7 @@ func init() {
|
||||
func getBusyCmdF(c client.Client, cmd *cobra.Command, _ []string) error {
|
||||
printer.SetSingle(true)
|
||||
|
||||
sbs, _, err := c.GetServerBusy()
|
||||
sbs, _, err := c.GetServerBusy(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get busy state: %w", err)
|
||||
}
|
||||
@@ -96,7 +97,7 @@ func setBusyCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
return errors.New("seconds must be a number > 0")
|
||||
}
|
||||
|
||||
_, err = c.SetServerBusy(int(seconds))
|
||||
_, err = c.SetServerBusy(context.TODO(), int(seconds))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to set busy state: %w", err)
|
||||
}
|
||||
@@ -108,7 +109,7 @@ func setBusyCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
func clearBusyCmdF(c client.Client, cmd *cobra.Command, _ []string) error {
|
||||
printer.SetSingle(true)
|
||||
|
||||
_, err := c.ClearServerBusy()
|
||||
_, err := c.ClearServerBusy(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to clear busy state: %w", err)
|
||||
}
|
||||
@@ -122,7 +123,7 @@ func systemVersionCmdF(c client.Client, cmd *cobra.Command, _ []string) error {
|
||||
// use the initial "withClient" connection information as local
|
||||
// mode doesn't need to log in, so we use an endpoint that will
|
||||
// always return a valid response
|
||||
_, resp, err := c.GetPing()
|
||||
_, resp, err := c.GetPing(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to fetch server version: %w", err)
|
||||
}
|
||||
@@ -134,7 +135,7 @@ func systemVersionCmdF(c client.Client, cmd *cobra.Command, _ []string) error {
|
||||
func systemStatusCmdF(c client.Client, cmd *cobra.Command, _ []string) error {
|
||||
printer.SetSingle(true)
|
||||
|
||||
status, _, err := c.GetPingWithFullServerStatus()
|
||||
status, _, err := c.GetPingWithFullServerStatus(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to fetch server status: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -23,7 +24,7 @@ func (s *MmctlUnitTestSuite) TestGetBusyCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetServerBusy().
|
||||
GetServerBusy(context.Background()).
|
||||
Return(sbs, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -42,7 +43,7 @@ func (s *MmctlUnitTestSuite) TestGetBusyCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetServerBusy().
|
||||
GetServerBusy(context.Background()).
|
||||
Return(sbs, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -57,7 +58,7 @@ func (s *MmctlUnitTestSuite) TestGetBusyCmd() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetServerBusy().
|
||||
GetServerBusy(context.Background()).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -78,7 +79,7 @@ func (s *MmctlUnitTestSuite) TestSetBusyCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SetServerBusy(minutes*60).
|
||||
SetServerBusy(context.Background(), minutes*60).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -116,7 +117,7 @@ func (s *MmctlUnitTestSuite) TestClearBusyCmd() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
ClearServerBusy().
|
||||
ClearServerBusy(context.Background()).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -131,7 +132,7 @@ func (s *MmctlUnitTestSuite) TestClearBusyCmd() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
ClearServerBusy().
|
||||
ClearServerBusy(context.Background()).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -149,7 +150,7 @@ func (s *MmctlUnitTestSuite) TestServerVersionCmd() {
|
||||
expectedVersion := "1.23.4.dev"
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPing().
|
||||
GetPing(context.Background()).
|
||||
Return("", &model.Response{ServerVersion: expectedVersion}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -165,7 +166,7 @@ func (s *MmctlUnitTestSuite) TestServerVersionCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPing().
|
||||
GetPing(context.Background()).
|
||||
Return("", &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
@@ -183,7 +184,7 @@ func (s *MmctlUnitTestSuite) TestServerStatusCmd() {
|
||||
expectedStatus := map[string]string{"status": "OK"}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPingWithFullServerStatus().
|
||||
GetPingWithFullServerStatus(context.Background()).
|
||||
Return(expectedStatus, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -199,7 +200,7 @@ func (s *MmctlUnitTestSuite) TestServerStatusCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetPingWithFullServerStatus().
|
||||
GetPingWithFullServerStatus(context.Background()).
|
||||
Return(nil, &model.Response{}, errors.New("mock error")).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
@@ -164,7 +165,7 @@ func createTeamCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
AllowOpenInvite: allowOpenInvite,
|
||||
}
|
||||
|
||||
newTeam, _, err := c.CreateTeam(team)
|
||||
newTeam, _, err := c.CreateTeam(context.TODO(), team)
|
||||
if err != nil {
|
||||
return errors.New("Team creation failed: " + err.Error())
|
||||
}
|
||||
@@ -175,7 +176,7 @@ func createTeamCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteTeam(c client.Client, team *model.Team) (*model.Response, error) {
|
||||
return c.PermanentDeleteTeam(team.Id)
|
||||
return c.PermanentDeleteTeam(context.TODO(), team.Id)
|
||||
}
|
||||
|
||||
func archiveTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
@@ -192,7 +193,7 @@ func archiveTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
printer.PrintError("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if _, err := c.SoftDeleteTeam(team.Id); err != nil {
|
||||
if _, err := c.SoftDeleteTeam(context.TODO(), team.Id); err != nil {
|
||||
printer.PrintError("Unable to archive team '" + team.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
printer.PrintT("Archived team '{{.Name}}'", team)
|
||||
@@ -205,7 +206,7 @@ func archiveTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
func listTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
page := 0
|
||||
for {
|
||||
teams, _, err := c.GetAllTeams("", page, APILimitMaximum)
|
||||
teams, _, err := c.GetAllTeams(context.TODO(), "", page, APILimitMaximum)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -232,7 +233,7 @@ func searchTeamCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
var teams []*model.Team
|
||||
|
||||
for _, searchTerm := range args {
|
||||
foundTeams, _, err := c.SearchTeams(&model.TeamSearch{Term: searchTerm})
|
||||
foundTeams, _, err := c.SearchTeams(context.TODO(), &model.TeamSearch{Term: searchTerm})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -290,7 +291,7 @@ func renameTeamCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
team.DisplayName = newDisplayName
|
||||
|
||||
// Using UpdateTeam API Method to rename team
|
||||
_, _, err := c.UpdateTeam(team)
|
||||
_, _, err := c.UpdateTeam(context.TODO(), team)
|
||||
if err != nil {
|
||||
return errors.New("Cannot rename team '" + oldTeamName + "', error : " + err.Error())
|
||||
}
|
||||
@@ -348,7 +349,7 @@ func modifyTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
printer.PrintError("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if updatedTeam, _, err := c.UpdateTeamPrivacy(team.Id, privacy); err != nil {
|
||||
if updatedTeam, _, err := c.UpdateTeamPrivacy(context.TODO(), team.Id, privacy); err != nil {
|
||||
printer.PrintError("Unable to modify team '" + team.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
printer.PrintT("Modified team '{{.Name}}'", updatedTeam)
|
||||
@@ -367,7 +368,7 @@ func restoreTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
printer.PrintError("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if rteam, _, err := c.RestoreTeam(team.Id); err != nil {
|
||||
if rteam, _, err := c.RestoreTeam(context.TODO(), team.Id); err != nil {
|
||||
result = multierror.Append(result, fmt.Errorf("unable to restore team '%s' error: %w", team.Name, err))
|
||||
printer.PrintError("Unable to restore team '" + team.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
@@ -108,9 +109,9 @@ func (s *MmctlE2ETestSuite) TestDeleteTeamsCmdF() {
|
||||
|
||||
// Set EnableAPITeamDeletion
|
||||
enableConfig := true
|
||||
config, _, _ := c.GetConfig()
|
||||
config, _, _ := c.GetConfig(context.TODO())
|
||||
config.ServiceSettings.EnableAPITeamDeletion = &enableConfig
|
||||
_, _, _ = c.UpdateConfig(config)
|
||||
_, _, _ = c.UpdateConfig(context.TODO(), config)
|
||||
|
||||
// Deletion should succeed for both local and SystemAdmin client now
|
||||
err = deleteTeamsCmdF(c, cmd, args)
|
||||
@@ -121,9 +122,9 @@ func (s *MmctlE2ETestSuite) TestDeleteTeamsCmdF() {
|
||||
|
||||
// Reset config
|
||||
enableConfig = false
|
||||
config, _, _ = c.GetConfig()
|
||||
config, _, _ = c.GetConfig(context.TODO())
|
||||
config.ServiceSettings.EnableAPITeamDeletion = &enableConfig
|
||||
_, _, _ = c.UpdateConfig(config)
|
||||
_, _, _ = c.UpdateConfig(context.TODO(), config)
|
||||
})
|
||||
|
||||
s.Run("Permission denied error for system admin when deleting a valid team", func() {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -55,7 +56,7 @@ func (s *MmctlUnitTestSuite) TestCreateTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateTeam(mockTeam).
|
||||
CreateTeam(context.Background(), mockTeam).
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -83,7 +84,7 @@ func (s *MmctlUnitTestSuite) TestCreateTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateTeam(mockTeam).
|
||||
CreateTeam(context.Background(), mockTeam).
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -109,7 +110,7 @@ func (s *MmctlUnitTestSuite) TestCreateTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateTeam(mockTeam).
|
||||
CreateTeam(context.Background(), mockTeam).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -131,14 +132,14 @@ func (s *MmctlUnitTestSuite) TestRenameTeamCmdF() {
|
||||
// Mocking : GetTeam searches with team id, if team not found proceeds with team name search
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("existingName", "").
|
||||
GetTeam(context.Background(), "existingName", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
// Mocking : GetTeamByname is called, if GetTeam fails to return any team, as team name was passed instead of team id
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName("existingName", "").
|
||||
GetTeamByName(context.Background(), "existingName", "").
|
||||
Return(nil, &model.Response{}, nil). // Error is nil as team not found will not return error from API
|
||||
Times(1)
|
||||
|
||||
@@ -169,13 +170,13 @@ func (s *MmctlUnitTestSuite) TestRenameTeamCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(args[0], "").
|
||||
GetTeam(context.Background(), args[0], "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(args[0], "").
|
||||
GetTeamByName(context.Background(), args[0], "").
|
||||
Return(foundTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -185,7 +186,7 @@ func (s *MmctlUnitTestSuite) TestRenameTeamCmdF() {
|
||||
// Mock out UpdateTeam which calls the api to rename team
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateTeam(renamedTeam).
|
||||
UpdateTeam(context.Background(), renamedTeam).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -215,19 +216,19 @@ func (s *MmctlUnitTestSuite) TestRenameTeamCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(args[0], "").
|
||||
GetTeam(context.Background(), args[0], "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(args[0], "").
|
||||
GetTeamByName(context.Background(), args[0], "").
|
||||
Return(foundTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateTeam(updatedTeam).
|
||||
UpdateTeam(context.Background(), updatedTeam).
|
||||
Return(updatedTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -247,7 +248,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 0, APILimitMaximum).
|
||||
GetAllTeams(context.Background(), "", 0, APILimitMaximum).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -265,7 +266,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 0, APILimitMaximum).
|
||||
GetAllTeams(context.Background(), "", 0, APILimitMaximum).
|
||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||
Times(2)
|
||||
|
||||
@@ -299,7 +300,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 0, APILimitMaximum).
|
||||
GetAllTeams(context.Background(), "", 0, APILimitMaximum).
|
||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||
Times(2)
|
||||
|
||||
@@ -346,7 +347,7 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 0, APILimitMaximum).
|
||||
GetAllTeams(context.Background(), "", 0, APILimitMaximum).
|
||||
Return(mockTeams, &model.Response{}, nil).
|
||||
Times(2)
|
||||
|
||||
@@ -390,13 +391,13 @@ func (s *MmctlUnitTestSuite) TestListTeamsCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 0, APILimitMaximum).
|
||||
GetAllTeams(context.Background(), "", 0, APILimitMaximum).
|
||||
Return(mockTeamsPage1, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 1, APILimitMaximum).
|
||||
GetAllTeams(context.Background(), "", 1, APILimitMaximum).
|
||||
Return(mockTeamsPage2, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -427,13 +428,13 @@ func (s *MmctlUnitTestSuite) TestDeleteTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamName, "").
|
||||
GetTeamByName(context.Background(), teamName, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -454,13 +455,13 @@ func (s *MmctlUnitTestSuite) TestDeleteTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PermanentDeleteTeam(teamID).
|
||||
PermanentDeleteTeam(context.Background(), teamID).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -483,13 +484,13 @@ func (s *MmctlUnitTestSuite) TestDeleteTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
PermanentDeleteTeam(teamID).
|
||||
PermanentDeleteTeam(context.Background(), teamID).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -511,7 +512,7 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: teamName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: teamName}).
|
||||
Return([]*model.Team{mockTeam}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -529,7 +530,7 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: displayName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: displayName}).
|
||||
Return([]*model.Team{mockTeam}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -546,7 +547,7 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: teamName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: teamName}).
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -563,7 +564,7 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: displayName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: displayName}).
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -584,13 +585,13 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: mockTeam1Name}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: mockTeam1Name}).
|
||||
Return([]*model.Team{mockTeam1}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: mockTeam2DisplayName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: mockTeam2DisplayName}).
|
||||
Return([]*model.Team{mockTeam2}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -611,7 +612,7 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: teamVariableName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: teamVariableName}).
|
||||
Return([]*model.Team{mockTeam1, mockTeam2}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -634,13 +635,13 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: "team"}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: "team"}).
|
||||
Return([]*model.Team{mockTeam1, mockTeam2, mockTeam3, mockTeam4}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: teamVariableName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: teamVariableName}).
|
||||
Return([]*model.Team{mockTeam1, mockTeam2, mockTeam3, mockTeam4}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -662,7 +663,7 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: teamVariableName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: teamVariableName}).
|
||||
Return([]*model.Team{mockTeam1, mockTeam2, mockTeam3, mockTeam4, mockTeam5}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -682,7 +683,7 @@ func (s *MmctlUnitTestSuite) TestSearchTeamCmd() {
|
||||
mockError := errors.New("remote error")
|
||||
teamName := "teamName"
|
||||
s.client.EXPECT().
|
||||
SearchTeams(&model.TeamSearch{Term: teamName}).
|
||||
SearchTeams(context.Background(), &model.TeamSearch{Term: teamName}).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -719,13 +720,13 @@ func (s *MmctlUnitTestSuite) TestModifyTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamName, "").
|
||||
GetTeamByName(context.Background(), teamName, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -748,13 +749,13 @@ func (s *MmctlUnitTestSuite) TestModifyTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateTeamPrivacy(teamID, model.TeamInvite).
|
||||
UpdateTeamPrivacy(context.Background(), teamID, model.TeamInvite).
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -777,13 +778,13 @@ func (s *MmctlUnitTestSuite) TestModifyTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateTeamPrivacy(teamID, model.TeamOpen).
|
||||
UpdateTeamPrivacy(context.Background(), teamID, model.TeamOpen).
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -808,13 +809,13 @@ func (s *MmctlUnitTestSuite) TestModifyTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateTeamPrivacy(teamID, model.TeamOpen).
|
||||
UpdateTeamPrivacy(context.Background(), teamID, model.TeamOpen).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -838,13 +839,13 @@ func (s *MmctlUnitTestSuite) TestRestoreTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamName, "").
|
||||
GetTeamByName(context.Background(), teamName, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -864,13 +865,13 @@ func (s *MmctlUnitTestSuite) TestRestoreTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RestoreTeam(teamID).
|
||||
RestoreTeam(context.Background(), teamID).
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -890,13 +891,13 @@ func (s *MmctlUnitTestSuite) TestRestoreTeamsCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamName, "").
|
||||
GetTeam(context.Background(), teamName, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RestoreTeam(teamID).
|
||||
RestoreTeam(context.Background(), teamID).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
@@ -72,7 +73,7 @@ func removeUserFromTeam(c client.Client, team *model.Team, user *model.User, use
|
||||
}
|
||||
|
||||
var err error
|
||||
if _, err = c.RemoveTeamMember(team.Id, user.Id); err != nil {
|
||||
if _, err = c.RemoveTeamMember(context.TODO(), team.Id, user.Id); err != nil {
|
||||
err = fmt.Errorf("unable to remove '%s' from %s. Error: %w", userArg, team.Name, err)
|
||||
printer.PrintError(err.Error())
|
||||
}
|
||||
@@ -102,7 +103,7 @@ func teamUsersAddCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
func addUserToTeam(c client.Client, team *model.Team, user *model.User, userArg string) {
|
||||
if _, _, err := c.AddTeamMember(team.Id, user.Id); err != nil {
|
||||
if _, _, err := c.AddTeamMember(context.TODO(), team.Id, user.Id); err != nil {
|
||||
printer.PrintError("Unable to add '" + userArg + "' to " + team.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
@@ -21,13 +22,13 @@ func (s *MmctlUnitTestSuite) TestTeamUsersArchiveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -43,25 +44,25 @@ func (s *MmctlUnitTestSuite) TestTeamUsersArchiveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Id, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Id, "").
|
||||
Return(nil, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Id, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Id, "").
|
||||
Return(nil, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(mockUser.Id, "").
|
||||
GetUser(context.Background(), mockUser.Id, "").
|
||||
Return(nil, nil, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -79,25 +80,25 @@ func (s *MmctlUnitTestSuite) TestTeamUsersArchiveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(nil, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(teamArg, "").
|
||||
GetTeamByName(context.Background(), teamArg, "").
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Id, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Id, "").
|
||||
Return(mockUser, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveTeamMember(mockTeam.Id, mockUser.Id).
|
||||
RemoveTeamMember(context.Background(), mockTeam.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -114,19 +115,19 @@ func (s *MmctlUnitTestSuite) TestTeamUsersArchiveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Id, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Id, "").
|
||||
Return(mockUser, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveTeamMember(mockTeam.Id, mockUser.Id).
|
||||
RemoveTeamMember(context.Background(), mockTeam.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -143,25 +144,25 @@ func (s *MmctlUnitTestSuite) TestTeamUsersArchiveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Id, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Id, "").
|
||||
Return(nil, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Id, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Id, "").
|
||||
Return(mockUser, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveTeamMember(mockTeam.Id, mockUser.Id).
|
||||
RemoveTeamMember(context.Background(), mockTeam.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -177,31 +178,31 @@ func (s *MmctlUnitTestSuite) TestTeamUsersArchiveCmd() {
|
||||
mockUser := &model.User{Id: userArg}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Id, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Id, "").
|
||||
Return(nil, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Id, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Id, "").
|
||||
Return(nil, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(mockUser.Id, "").
|
||||
GetUser(context.Background(), mockUser.Id, "").
|
||||
Return(mockUser, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveTeamMember(mockTeam.Id, mockUser.Id).
|
||||
RemoveTeamMember(context.Background(), mockTeam.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -219,19 +220,19 @@ func (s *MmctlUnitTestSuite) TestTeamUsersArchiveCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamArg, "").
|
||||
GetTeam(context.Background(), teamArg, "").
|
||||
Return(mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Id, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Id, "").
|
||||
Return(mockUser, nil, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RemoveTeamMember(mockTeam.Id, mockUser.Id).
|
||||
RemoveTeamMember(context.Background(), mockTeam.Id, mockUser.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -260,13 +261,13 @@ func (s *MmctlUnitTestSuite) TestAddUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("team1", "").
|
||||
GetTeam(context.Background(), "team1", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName("team1", "").
|
||||
GetTeamByName(context.Background(), "team1", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -281,25 +282,25 @@ func (s *MmctlUnitTestSuite) TestAddUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("team1", "").
|
||||
GetTeam(context.Background(), "team1", "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail("user1", "").
|
||||
GetUserByEmail(context.Background(), "user1", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername("user1", "").
|
||||
GetUserByUsername(context.Background(), "user1", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser("user1", "").
|
||||
GetUser(context.Background(), "user1", "").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -315,13 +316,13 @@ func (s *MmctlUnitTestSuite) TestAddUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("team1", "").
|
||||
GetTeam(context.Background(), "team1", "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail("user1", "").
|
||||
GetUserByEmail(context.Background(), "user1", "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -329,7 +330,7 @@ func (s *MmctlUnitTestSuite) TestAddUsersCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
AddTeamMember("TeamId", "UserID").
|
||||
AddTeamMember(context.Background(), "TeamId", "UserID").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -346,19 +347,19 @@ func (s *MmctlUnitTestSuite) TestAddUsersCmd() {
|
||||
cmd := &cobra.Command{}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam("team1", "").
|
||||
GetTeam(context.Background(), "team1", "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail("user1", "").
|
||||
GetUserByEmail(context.Background(), "user1", "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
AddTeamMember("TeamId", "UserID").
|
||||
AddTeamMember(context.Background(), "TeamId", "UserID").
|
||||
Return(nil, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
@@ -28,10 +29,10 @@ func getTeamFromTeamArg(c client.Client, teamArg string) *model.Team {
|
||||
}
|
||||
|
||||
var team *model.Team
|
||||
team, _, _ = c.GetTeam(teamArg, "")
|
||||
team, _, _ = c.GetTeam(context.TODO(), teamArg, "")
|
||||
|
||||
if team == nil {
|
||||
team, _, _ = c.GetTeamByName(teamArg, "")
|
||||
team, _, _ = c.GetTeamByName(context.TODO(), teamArg, "")
|
||||
}
|
||||
return team
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func getTeamFromArg(c client.Client, teamArg string) (*model.Team, error) {
|
||||
var team *model.Team
|
||||
var response *model.Response
|
||||
var err error
|
||||
team, response, err = c.GetTeam(teamArg, "")
|
||||
team, response, err = c.GetTeam(context.TODO(), teamArg, "")
|
||||
if err != nil {
|
||||
nErr := ExtractErrorFromResponse(response, err)
|
||||
var nfErr *NotFoundError
|
||||
@@ -74,7 +75,7 @@ func getTeamFromArg(c client.Client, teamArg string) (*model.Team, error) {
|
||||
if team != nil {
|
||||
return team, nil
|
||||
}
|
||||
team, response, err = c.GetTeamByName(teamArg, "")
|
||||
team, response, err = c.GetTeamByName(context.TODO(), teamArg, "")
|
||||
if err != nil {
|
||||
nErr := ExtractErrorFromResponse(response, err)
|
||||
var nfErr *NotFoundError
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -18,12 +19,12 @@ func (s *MmctlUnitTestSuite) TestGetTeamArgs() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(notFoundTeam, "").
|
||||
GetTeam(context.Background(), notFoundTeam, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(notFoundTeam, "").
|
||||
GetTeamByName(context.Background(), notFoundTeam, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
|
||||
Times(1)
|
||||
|
||||
@@ -38,12 +39,12 @@ func (s *MmctlUnitTestSuite) TestGetTeamArgs() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(badRequestTeam, "").
|
||||
GetTeam(context.Background(), badRequestTeam, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeamByName(badRequestTeam, "").
|
||||
GetTeamByName(context.Background(), badRequestTeam, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
|
||||
Times(1)
|
||||
|
||||
@@ -58,7 +59,7 @@ func (s *MmctlUnitTestSuite) TestGetTeamArgs() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(forbidden, "").
|
||||
GetTeam(context.Background(), forbidden, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusForbidden}, forbiddenErr).
|
||||
Times(1)
|
||||
|
||||
@@ -73,7 +74,7 @@ func (s *MmctlUnitTestSuite) TestGetTeamArgs() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(errTeam, "").
|
||||
GetTeam(context.Background(), errTeam, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusInternalServerError}, internalServerErrorErr).
|
||||
Times(1)
|
||||
|
||||
@@ -88,7 +89,7 @@ func (s *MmctlUnitTestSuite) TestGetTeamArgs() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(successID, "").
|
||||
GetTeam(context.Background(), successID, "").
|
||||
Return(successTeam, nil, nil).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/client"
|
||||
@@ -70,7 +71,7 @@ func generateTokenForAUserCmdF(c client.Client, command *cobra.Command, args []s
|
||||
return errors.Errorf("could not retrieve user information of %q", userArg)
|
||||
}
|
||||
|
||||
token, _, err := c.CreateUserAccessToken(user.Id, args[1])
|
||||
token, _, err := c.CreateUserAccessToken(context.TODO(), user.Id, args[1])
|
||||
if err != nil {
|
||||
return errors.Errorf("could not create token for %q: %s", userArg, err.Error())
|
||||
}
|
||||
@@ -98,7 +99,7 @@ func listTokensOfAUserCmdF(c client.Client, command *cobra.Command, args []strin
|
||||
return errors.Errorf("could not retrieve user information of %q", userArg)
|
||||
}
|
||||
|
||||
tokens, _, err := c.GetUserAccessTokensForUser(user.Id, page, perPage)
|
||||
tokens, _, err := c.GetUserAccessTokensForUser(context.TODO(), user.Id, page, perPage)
|
||||
if err != nil {
|
||||
return errors.Errorf("could not retrieve tokens for user %q: %s", userArg, err.Error())
|
||||
}
|
||||
@@ -120,7 +121,7 @@ func listTokensOfAUserCmdF(c client.Client, command *cobra.Command, args []strin
|
||||
|
||||
func revokeTokenForAUserCmdF(c client.Client, command *cobra.Command, args []string) error {
|
||||
for _, id := range args {
|
||||
res, err := c.RevokeUserAccessToken(id)
|
||||
res, err := c.RevokeUserAccessToken(context.TODO(), id)
|
||||
if err != nil {
|
||||
return errors.Errorf("could not revoke token %q: %s", id, err.Error())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -25,25 +26,25 @@ func (s *MmctlUnitTestSuite) TestGenerateTokenForAUserCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userArg, "").
|
||||
GetUserByEmail(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(userArg, "").
|
||||
GetUserByUsername(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given username")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(userArg, "").
|
||||
GetUser(context.Background(), userArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateUserAccessToken(mockUser.Id, mockToken.Description).
|
||||
CreateUserAccessToken(context.Background(), mockUser.Id, mockToken.Description).
|
||||
Return(&mockToken, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -59,19 +60,19 @@ func (s *MmctlUnitTestSuite) TestGenerateTokenForAUserCmd() {
|
||||
userArg := "some-text"
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userArg, "").
|
||||
GetUserByEmail(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(userArg, "").
|
||||
GetUserByUsername(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given username")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(userArg, "").
|
||||
GetUser(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given ID")).
|
||||
Times(1)
|
||||
|
||||
@@ -88,19 +89,19 @@ func (s *MmctlUnitTestSuite) TestGenerateTokenForAUserCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userArg, "").
|
||||
GetUserByEmail(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(userArg, "").
|
||||
GetUserByUsername(context.Background(), userArg, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateUserAccessToken(mockUser.Id, "description").
|
||||
CreateUserAccessToken(context.Background(), mockUser.Id, "description").
|
||||
Return(nil, &model.Response{}, errors.New("error-message")).
|
||||
Times(1)
|
||||
|
||||
@@ -127,25 +128,25 @@ func (s *MmctlUnitTestSuite) TestListTokensOfAUserCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Id, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Id, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(mockUser.Id, "").
|
||||
GetUserByUsername(context.Background(), mockUser.Id, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given username")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(mockUser.Id, "").
|
||||
GetUser(context.Background(), mockUser.Id, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserAccessTokensForUser(mockUser.Id, 0, 9999).
|
||||
GetUserAccessTokensForUser(context.Background(), mockUser.Id, 0, 9999).
|
||||
Return(
|
||||
[]*model.UserAccessToken{&mockToken1, &mockToken2},
|
||||
&model.Response{}, nil,
|
||||
@@ -174,13 +175,13 @@ func (s *MmctlUnitTestSuite) TestListTokensOfAUserCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(&mockUser, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserAccessTokensForUser(mockUser.Id, 0, 2).
|
||||
GetUserAccessTokensForUser(context.Background(), mockUser.Id, 0, 2).
|
||||
Return(
|
||||
[]*model.UserAccessToken{&mockToken1, &mockToken2},
|
||||
&model.Response{}, nil,
|
||||
@@ -205,19 +206,19 @@ func (s *MmctlUnitTestSuite) TestListTokensOfAUserCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(userArg, "").
|
||||
GetUserByEmail(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(userArg, "").
|
||||
GetUserByUsername(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given username")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(userArg, "").
|
||||
GetUser(context.Background(), userArg, "").
|
||||
Return(nil, &model.Response{}, errors.New("no user found with the given user ID")).
|
||||
Times(1)
|
||||
|
||||
@@ -240,13 +241,13 @@ func (s *MmctlUnitTestSuite) TestListTokensOfAUserCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(mockUser.Email, "").
|
||||
GetUserByEmail(context.Background(), mockUser.Email, "").
|
||||
Return(&mockUser, &model.Response{}, errors.New("no user found with the given email")).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserAccessTokensForUser(mockUser.Id, 0, 2).
|
||||
GetUserAccessTokensForUser(context.Background(), mockUser.Id, 0, 2).
|
||||
Return(
|
||||
[]*model.UserAccessToken{},
|
||||
&model.Response{}, nil,
|
||||
@@ -267,13 +268,13 @@ func (s *MmctlUnitTestSuite) TestRevokeTokenForAUserCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RevokeUserAccessToken(mockToken1.Id).
|
||||
RevokeUserAccessToken(context.Background(), mockToken1.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
RevokeUserAccessToken(mockToken2.Id).
|
||||
RevokeUserAccessToken(context.Background(), mockToken2.Id).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -285,7 +286,7 @@ func (s *MmctlUnitTestSuite) TestRevokeTokenForAUserCmdF() {
|
||||
s.Run("Should fail if can't revoke user access token", func() {
|
||||
s.client.
|
||||
EXPECT().
|
||||
RevokeUserAccessToken("token-id").
|
||||
RevokeUserAccessToken(context.Background(), "token-id").
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, errors.New("some-error")).
|
||||
Times(1)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -383,7 +384,7 @@ func changeUserActiveStatus(c client.Client, user *model.User, activate bool) er
|
||||
if !activate && user.IsSSOUser() {
|
||||
printer.Print("You must also deactivate user " + user.Id + " in the SSO provider or they will be reactivated on next login or sync.")
|
||||
}
|
||||
if _, err := c.UpdateUserActive(user.Id, activate); err != nil {
|
||||
if _, err := c.UpdateUserActive(context.TODO(), user.Id, activate); err != nil {
|
||||
return fmt.Errorf("unable to change activation status of user: %v", user.Id)
|
||||
}
|
||||
|
||||
@@ -436,18 +437,18 @@ func userCreateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
DisableWelcomeEmail: disableWelcomeEmail,
|
||||
}
|
||||
|
||||
ruser, _, err := c.CreateUser(user)
|
||||
ruser, _, err := c.CreateUser(context.TODO(), user)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("Unable to create user. Error: " + err.Error())
|
||||
}
|
||||
|
||||
if systemAdmin {
|
||||
if _, err := c.UpdateUserRoles(ruser.Id, "system_user system_admin"); err != nil {
|
||||
if _, err := c.UpdateUserRoles(context.TODO(), ruser.Id, "system_user system_admin"); err != nil {
|
||||
return errors.New("Unable to update user roles. Error: " + err.Error())
|
||||
}
|
||||
} else if guest {
|
||||
if _, err := c.DemoteUserToGuest(ruser.Id); err != nil {
|
||||
if _, err := c.DemoteUserToGuest(context.TODO(), ruser.Id); err != nil {
|
||||
return errors.Wrapf(err, "Unable to demote use to guest")
|
||||
}
|
||||
}
|
||||
@@ -486,7 +487,7 @@ func inviteUser(c client.Client, email string, team *model.Team, teamArg string)
|
||||
return fmt.Errorf("can't find team '%v'", teamArg)
|
||||
}
|
||||
|
||||
if _, err := c.InviteUsersToTeam(team.Id, invites); err != nil {
|
||||
if _, err := c.InviteUsersToTeam(context.TODO(), team.Id, invites); err != nil {
|
||||
return errors.New("Unable to invite user with email " + email + " to team " + team.Name + ". Error: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -508,7 +509,7 @@ func sendPasswordResetEmailCmdF(c client.Client, cmd *cobra.Command, args []stri
|
||||
printer.PrintError("Invalid email '" + email + "'")
|
||||
continue
|
||||
}
|
||||
if _, err := c.SendPasswordResetEmail(email); err != nil {
|
||||
if _, err := c.SendPasswordResetEmail(context.TODO(), email); err != nil {
|
||||
result = multierror.Append(result, fmt.Errorf("unable send reset password email to email %s: %w", email, err))
|
||||
printer.PrintError("Unable send reset password email to email " + email + ". Error: " + err.Error())
|
||||
}
|
||||
@@ -537,7 +538,7 @@ func updateUserEmailCmdF(c client.Client, cmd *cobra.Command, args []string) err
|
||||
|
||||
user.Email = newEmail
|
||||
|
||||
ruser, _, err := c.UpdateUser(user)
|
||||
ruser, _, err := c.UpdateUser(context.TODO(), user)
|
||||
if err != nil {
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
@@ -563,7 +564,7 @@ func updateUsernameCmdF(c client.Client, cmd *cobra.Command, args []string) erro
|
||||
|
||||
user.Username = newUsername
|
||||
|
||||
ruser, _, err := c.UpdateUser(user)
|
||||
ruser, _, err := c.UpdateUser(context.TODO(), user)
|
||||
if err != nil {
|
||||
return errors.New(err.Error())
|
||||
}
|
||||
@@ -602,11 +603,11 @@ func changePasswordUserCmdF(c client.Client, cmd *cobra.Command, args []string)
|
||||
}
|
||||
|
||||
if hashed {
|
||||
if _, err := c.UpdateUserHashedPassword(user.Id, password); err != nil {
|
||||
if _, err := c.UpdateUserHashedPassword(context.TODO(), user.Id, password); err != nil {
|
||||
return errors.Wrap(err, "changing user hashed password failed")
|
||||
}
|
||||
} else {
|
||||
if _, err := c.UpdateUserPassword(user.Id, current, password); err != nil {
|
||||
if _, err := c.UpdateUserPassword(context.TODO(), user.Id, current, password); err != nil {
|
||||
return errors.Wrap(err, "changing user password failed")
|
||||
}
|
||||
}
|
||||
@@ -627,7 +628,7 @@ func resetUserMfaCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
if _, err := c.UpdateUserMfa(user.Id, "", false); err != nil {
|
||||
if _, err := c.UpdateUserMfa(context.TODO(), user.Id, "", false); err != nil {
|
||||
result = multierror.Append(result, fmt.Errorf("unable to reset user %q MFA. Error: %w", user.Id, err))
|
||||
}
|
||||
}
|
||||
@@ -652,7 +653,7 @@ func deleteUsersCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
printer.PrintError("Unable to find user '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if res, err := c.PermanentDeleteUser(user.Id); err != nil {
|
||||
if res, err := c.PermanentDeleteUser(context.TODO(), user.Id); err != nil {
|
||||
printer.PrintError("Unable to delete user '" + user.Username + "' error: " + err.Error())
|
||||
} else {
|
||||
// res.StatusCode is checked for 202 to identify issues with file deletion.
|
||||
@@ -673,7 +674,7 @@ func deleteAllUsersCmdF(c client.Client, cmd *cobra.Command, args []string) erro
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := c.PermanentDeleteAllUsers(); err != nil {
|
||||
if _, err := c.PermanentDeleteAllUsers(context.TODO()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -738,7 +739,7 @@ func listUsersCmdF(c client.Client, command *cobra.Command, args []string) error
|
||||
var team *model.Team
|
||||
if teamName != "" {
|
||||
var err error
|
||||
team, _, err = c.GetTeamByName(teamName, "")
|
||||
team, _, err = c.GetTeamByName(context.TODO(), teamName, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("Failed to get team %s", teamName))
|
||||
}
|
||||
@@ -749,12 +750,12 @@ func listUsersCmdF(c client.Client, command *cobra.Command, args []string) error
|
||||
var users []*model.User
|
||||
var err error
|
||||
if team != nil {
|
||||
users, _, err = c.GetUsersInTeam(team.Id, page, perPage, "")
|
||||
users, _, err = c.GetUsersInTeam(context.TODO(), team.Id, page, perPage, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("Failed to fetch users for team %s", teamName))
|
||||
}
|
||||
} else {
|
||||
users, _, err = c.GetUsers(page, perPage, "")
|
||||
users, _, err = c.GetUsers(context.TODO(), page, perPage, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to fetch users")
|
||||
}
|
||||
@@ -784,7 +785,7 @@ func verifyUserEmailWithoutTokenCmdF(c client.Client, cmd *cobra.Command, userAr
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
if newUser, _, err := c.VerifyUserEmailWithoutToken(user.Id); err != nil {
|
||||
if newUser, _, err := c.VerifyUserEmailWithoutToken(context.TODO(), user.Id); err != nil {
|
||||
result = multierror.Append(result, fmt.Errorf("unable to verify user %s email: %w", user.Id, err))
|
||||
} else {
|
||||
printer.PrintT("User {{.Username}} verified", newUser)
|
||||
@@ -814,7 +815,7 @@ func convertUserToBot(c client.Client, _ *cobra.Command, userArgs []string) erro
|
||||
printer.PrintError(err.Error())
|
||||
}
|
||||
for _, user := range users {
|
||||
bot, _, err := c.ConvertUserToBot(user.Id)
|
||||
bot, _, err := c.ConvertUserToBot(context.TODO(), user.Id)
|
||||
if err != nil {
|
||||
printer.PrintError(err.Error())
|
||||
continue
|
||||
@@ -881,7 +882,7 @@ func convertBotToUser(c client.Client, cmd *cobra.Command, userArgs []string) er
|
||||
systemAdmin, _ = cmd.Flags().GetBool("system_admin")
|
||||
}
|
||||
|
||||
user, _, err = c.ConvertBotToUser(user.Id, up, systemAdmin)
|
||||
user, _, err = c.ConvertBotToUser(context.TODO(), user.Id, up, systemAdmin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -925,7 +926,7 @@ func migrateAuthToSamlCmdF(c client.Client, cmd *cobra.Command, userArgs []strin
|
||||
return errors.New("invalid from_auth argument")
|
||||
}
|
||||
|
||||
resp, err := c.MigrateAuthToSaml(fromAuth, matches, auto)
|
||||
resp, err := c.MigrateAuthToSaml(context.TODO(), fromAuth, matches, auto)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if resp.StatusCode == http.StatusOK {
|
||||
@@ -948,7 +949,7 @@ func migrateAuthToLdapCmdF(c client.Client, cmd *cobra.Command, userArgs []strin
|
||||
|
||||
force, _ := cmd.Flags().GetBool("force")
|
||||
|
||||
resp, err := c.MigrateAuthToLdap(fromAuth, matchField, force)
|
||||
resp, err := c.MigrateAuthToLdap(context.TODO(), fromAuth, matchField, force)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if resp.StatusCode == http.StatusOK {
|
||||
@@ -965,7 +966,7 @@ func promoteGuestToUserCmdF(c client.Client, _ *cobra.Command, userArgs []string
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := c.PromoteGuestToUser(user.Id); err != nil {
|
||||
if _, err := c.PromoteGuestToUser(context.TODO(), user.Id); err != nil {
|
||||
printer.PrintError(fmt.Sprintf("unable to promote guest %s: %s", userArgs[i], err))
|
||||
continue
|
||||
}
|
||||
@@ -986,7 +987,7 @@ func demoteUserToGuestCmdF(c client.Client, _ *cobra.Command, userArgs []string)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := c.DemoteUserToGuest(user.Id); err != nil {
|
||||
if _, err := c.DemoteUserToGuest(context.TODO(), user.Id); err != nil {
|
||||
err = fmt.Errorf("unable to demote user %s: %w", userArgs[i], err)
|
||||
errs = multierror.Append(errs, err)
|
||||
printer.PrintError(err.Error())
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
@@ -26,16 +27,16 @@ func getUsersFromUserArgs(c client.Client, userArgs []string) []*model.User {
|
||||
func getUserFromUserArg(c client.Client, userArg string) *model.User {
|
||||
var user *model.User
|
||||
if !checkDots(userArg) {
|
||||
user, _, _ = c.GetUserByEmail(userArg, "")
|
||||
user, _, _ = c.GetUserByEmail(context.TODO(), userArg, "")
|
||||
}
|
||||
|
||||
if !checkSlash(userArg) {
|
||||
if user == nil {
|
||||
user, _, _ = c.GetUserByUsername(userArg, "")
|
||||
user, _, _ = c.GetUserByUsername(context.TODO(), userArg, "")
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
user, _, _ = c.GetUser(userArg, "")
|
||||
user, _, _ = c.GetUser(context.TODO(), userArg, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ func getUserFromArg(c client.Client, userArg string) (*model.User, error) {
|
||||
var response *model.Response
|
||||
var err error
|
||||
if !checkDots(userArg) {
|
||||
user, response, err = c.GetUserByEmail(userArg, "")
|
||||
user, response, err = c.GetUserByEmail(context.TODO(), userArg, "")
|
||||
if err != nil {
|
||||
nErr := ExtractErrorFromResponse(response, err)
|
||||
var nfErr *NotFoundError
|
||||
@@ -88,7 +89,7 @@ func getUserFromArg(c client.Client, userArg string) (*model.User, error) {
|
||||
|
||||
if !checkSlash(userArg) {
|
||||
if user == nil {
|
||||
user, response, err = c.GetUserByUsername(userArg, "")
|
||||
user, response, err = c.GetUserByUsername(context.TODO(), userArg, "")
|
||||
if err != nil {
|
||||
nErr := ExtractErrorFromResponse(response, err)
|
||||
var nfErr *NotFoundError
|
||||
@@ -100,7 +101,7 @@ func getUserFromArg(c client.Client, userArg string) (*model.User, error) {
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
user, response, err = c.GetUser(userArg, "")
|
||||
user, response, err = c.GetUser(context.TODO(), userArg, "")
|
||||
if err != nil {
|
||||
nErr := ExtractErrorFromResponse(response, err)
|
||||
var nfErr *NotFoundError
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -19,17 +20,17 @@ func (s *MmctlUnitTestSuite) TestGetUserFromArgs() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(notFoundEmail, "").
|
||||
GetUserByEmail(context.Background(), notFoundEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(notFoundEmail, "").
|
||||
GetUserByUsername(context.Background(), notFoundEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(notFoundEmail, "").
|
||||
GetUser(context.Background(), notFoundEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
|
||||
Times(1)
|
||||
|
||||
@@ -45,17 +46,17 @@ func (s *MmctlUnitTestSuite) TestGetUserFromArgs() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(badRequestEmail, "").
|
||||
GetUserByEmail(context.Background(), badRequestEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByUsername(badRequestEmail, "").
|
||||
GetUserByUsername(context.Background(), badRequestEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
|
||||
Times(1)
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUser(badRequestEmail, "").
|
||||
GetUser(context.Background(), badRequestEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
|
||||
Times(1)
|
||||
|
||||
@@ -71,7 +72,7 @@ func (s *MmctlUnitTestSuite) TestGetUserFromArgs() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(unexpectedErrEmail, "").
|
||||
GetUserByEmail(context.Background(), unexpectedErrEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusInternalServerError}, unexpectedErr).
|
||||
Times(1)
|
||||
users, err := getUsersFromArgs(s.client, []string{unexpectedErrEmail})
|
||||
@@ -85,7 +86,7 @@ func (s *MmctlUnitTestSuite) TestGetUserFromArgs() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(forbiddenErrEmail, "").
|
||||
GetUserByEmail(context.Background(), forbiddenErrEmail, "").
|
||||
Return(nil, &model.Response{StatusCode: http.StatusForbidden}, forbiddenErr).
|
||||
Times(1)
|
||||
users, err := getUsersFromArgs(s.client, []string{forbiddenErrEmail})
|
||||
@@ -99,7 +100,7 @@ func (s *MmctlUnitTestSuite) TestGetUserFromArgs() {
|
||||
printer.Clean()
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(successEmail, "").
|
||||
GetUserByEmail(context.Background(), successEmail, "").
|
||||
Return(successUser, nil, nil).
|
||||
Times(1)
|
||||
users, err := getUsersFromArgs(s.client, []string{successEmail})
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/cmd/mmctl/client"
|
||||
@@ -90,7 +92,7 @@ func listWebhookCmdF(c client.Client, command *cobra.Command, args []string) err
|
||||
if len(args) < 1 {
|
||||
var err error
|
||||
// If no team is specified, list all teams
|
||||
teams, _, err = c.GetAllTeams("", 0, 100000000)
|
||||
teams, _, err = c.GetAllTeams(context.TODO(), "", 0, 100000000)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -107,13 +109,13 @@ func listWebhookCmdF(c client.Client, command *cobra.Command, args []string) err
|
||||
// Fetch all hooks with a very large limit so we get them all.
|
||||
incomingResult := make(chan StoreResult, 1)
|
||||
go func() {
|
||||
incomingHooks, _, err := c.GetIncomingWebhooksForTeam(team.Id, 0, 100000000, "")
|
||||
incomingHooks, _, err := c.GetIncomingWebhooksForTeam(context.TODO(), team.Id, 0, 100000000, "")
|
||||
incomingResult <- StoreResult{Data: incomingHooks, Err: err}
|
||||
close(incomingResult)
|
||||
}()
|
||||
outgoingResult := make(chan StoreResult, 1)
|
||||
go func() {
|
||||
outgoingHooks, _, err := c.GetOutgoingWebhooksForTeam(team.Id, 0, 100000000, "")
|
||||
outgoingHooks, _, err := c.GetOutgoingWebhooksForTeam(context.TODO(), team.Id, 0, 100000000, "")
|
||||
outgoingResult <- StoreResult{Data: outgoingHooks, Err: err}
|
||||
close(outgoingResult)
|
||||
}()
|
||||
@@ -170,7 +172,7 @@ func createIncomingWebhookCmdF(c client.Client, command *cobra.Command, args []s
|
||||
UserId: user.Id,
|
||||
}
|
||||
|
||||
createdIncoming, _, err := c.CreateIncomingWebhook(incomingWebhook)
|
||||
createdIncoming, _, err := c.CreateIncomingWebhook(context.TODO(), incomingWebhook)
|
||||
if err != nil {
|
||||
printer.PrintError("Unable to create webhook")
|
||||
return err
|
||||
@@ -187,7 +189,7 @@ func modifyIncomingWebhookCmdF(c client.Client, command *cobra.Command, args []s
|
||||
printer.SetSingle(true)
|
||||
|
||||
webhookArg := args[0]
|
||||
oldHook, _, err := c.GetIncomingWebhook(webhookArg, "")
|
||||
oldHook, _, err := c.GetIncomingWebhook(context.TODO(), webhookArg, "")
|
||||
if err != nil {
|
||||
return errors.New("Unable to find webhook '" + webhookArg + "'")
|
||||
}
|
||||
@@ -219,7 +221,7 @@ func modifyIncomingWebhookCmdF(c client.Client, command *cobra.Command, args []s
|
||||
updatedHook.ChannelLocked = channelLocked
|
||||
|
||||
var newHook *model.IncomingWebhook
|
||||
if newHook, _, err = c.UpdateIncomingWebhook(updatedHook); err != nil {
|
||||
if newHook, _, err = c.UpdateIncomingWebhook(context.TODO(), updatedHook); err != nil {
|
||||
printer.PrintError("Unable to modify incoming webhook")
|
||||
return err
|
||||
}
|
||||
@@ -283,7 +285,7 @@ func createOutgoingWebhookCmdF(c client.Client, command *cobra.Command, args []s
|
||||
}
|
||||
}
|
||||
|
||||
createdOutgoing, _, err := c.CreateOutgoingWebhook(outgoingWebhook)
|
||||
createdOutgoing, _, err := c.CreateOutgoingWebhook(context.TODO(), outgoingWebhook)
|
||||
if err != nil {
|
||||
printer.PrintError("Unable to create outgoing webhook")
|
||||
return err
|
||||
@@ -300,7 +302,7 @@ func modifyOutgoingWebhookCmdF(c client.Client, command *cobra.Command, args []s
|
||||
printer.SetSingle(true)
|
||||
|
||||
webhookArg := args[0]
|
||||
oldHook, _, err := c.GetOutgoingWebhook(webhookArg)
|
||||
oldHook, _, err := c.GetOutgoingWebhook(context.TODO(), webhookArg)
|
||||
if err != nil {
|
||||
return errors.New("unable to find webhook '" + webhookArg + "'")
|
||||
}
|
||||
@@ -367,7 +369,7 @@ func modifyOutgoingWebhookCmdF(c client.Client, command *cobra.Command, args []s
|
||||
}
|
||||
|
||||
var newHook *model.OutgoingWebhook
|
||||
if newHook, _, err = c.UpdateOutgoingWebhook(updatedHook); err != nil {
|
||||
if newHook, _, err = c.UpdateOutgoingWebhook(context.TODO(), updatedHook); err != nil {
|
||||
printer.PrintError("Unable to modify outgoing webhook")
|
||||
return err
|
||||
}
|
||||
@@ -380,8 +382,8 @@ func deleteWebhookCmdF(c client.Client, command *cobra.Command, args []string) e
|
||||
printer.SetSingle(true)
|
||||
|
||||
webhookID := args[0]
|
||||
if incomingWebhook, _, err := c.GetIncomingWebhook(webhookID, ""); err == nil {
|
||||
_, err := c.DeleteIncomingWebhook(webhookID)
|
||||
if incomingWebhook, _, err := c.GetIncomingWebhook(context.TODO(), webhookID, ""); err == nil {
|
||||
_, err := c.DeleteIncomingWebhook(context.TODO(), webhookID)
|
||||
if err != nil {
|
||||
printer.PrintError("Unable to delete webhook '" + webhookID + "'")
|
||||
return err
|
||||
@@ -390,8 +392,8 @@ func deleteWebhookCmdF(c client.Client, command *cobra.Command, args []string) e
|
||||
return nil
|
||||
}
|
||||
|
||||
if outgoingWebhook, _, err := c.GetOutgoingWebhook(webhookID); err == nil {
|
||||
_, err := c.DeleteOutgoingWebhook(webhookID)
|
||||
if outgoingWebhook, _, err := c.GetOutgoingWebhook(context.TODO(), webhookID); err == nil {
|
||||
_, err := c.DeleteOutgoingWebhook(context.TODO(), webhookID)
|
||||
if err != nil {
|
||||
printer.PrintError("Unable to delete webhook '" + webhookID + "'")
|
||||
return err
|
||||
@@ -408,12 +410,12 @@ func showWebhookCmdF(c client.Client, command *cobra.Command, args []string) err
|
||||
printer.SetSingle(true)
|
||||
|
||||
webhookID := args[0]
|
||||
if incomingWebhook, _, err := c.GetIncomingWebhook(webhookID, ""); err == nil {
|
||||
if incomingWebhook, _, err := c.GetIncomingWebhook(context.TODO(), webhookID, ""); err == nil {
|
||||
printer.Print(*incomingWebhook)
|
||||
return nil
|
||||
}
|
||||
|
||||
if outgoingWebhook, _, err := c.GetOutgoingWebhook(webhookID); err == nil {
|
||||
if outgoingWebhook, _, err := c.GetOutgoingWebhook(context.TODO(), webhookID); err == nil {
|
||||
printer.Print(*outgoingWebhook)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -39,19 +40,19 @@ func (s *MmctlUnitTestSuite) TestListWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 0, 100000000).
|
||||
GetAllTeams(context.Background(), "", 0, 100000000).
|
||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhooksForTeam(teamID, 0, 100000000, "").
|
||||
GetIncomingWebhooksForTeam(context.Background(), teamID, 0, 100000000, "").
|
||||
Return([]*model.IncomingWebhook{&mockIncomingWebhook}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhooksForTeam(teamID, 0, 100000000, "").
|
||||
GetOutgoingWebhooksForTeam(context.Background(), teamID, 0, 100000000, "").
|
||||
Return([]*model.OutgoingWebhook{&mockOutgoingWebhook}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -79,19 +80,19 @@ func (s *MmctlUnitTestSuite) TestListWebhookCmd() {
|
||||
}
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhooksForTeam(teamID, 0, 100000000, "").
|
||||
GetIncomingWebhooksForTeam(context.Background(), teamID, 0, 100000000, "").
|
||||
Return([]*model.IncomingWebhook{&mockIncomingWebhook}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhooksForTeam(teamID, 0, 100000000, "").
|
||||
GetOutgoingWebhooksForTeam(context.Background(), teamID, 0, 100000000, "").
|
||||
Return([]*model.OutgoingWebhook{&mockOutgoingWebhook}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -113,19 +114,19 @@ func (s *MmctlUnitTestSuite) TestListWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams("", 0, 100000000).
|
||||
GetAllTeams(context.Background(), "", 0, 100000000).
|
||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhooksForTeam(teamID, 0, 100000000, "").
|
||||
GetIncomingWebhooksForTeam(context.Background(), teamID, 0, 100000000, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhooksForTeam(teamID, 0, 100000000, "").
|
||||
GetOutgoingWebhooksForTeam(context.Background(), teamID, 0, 100000000, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -173,19 +174,19 @@ func (s *MmctlUnitTestSuite) TestCreateIncomingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelID, "").
|
||||
GetChannel(context.Background(), channelID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(emailID, "").
|
||||
GetUserByEmail(context.Background(), emailID, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateIncomingWebhook(&mockIncomingWebhook).
|
||||
CreateIncomingWebhook(context.Background(), &mockIncomingWebhook).
|
||||
Return(&returnedIncomingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -217,19 +218,19 @@ func (s *MmctlUnitTestSuite) TestCreateIncomingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetChannel(channelID, "").
|
||||
GetChannel(context.Background(), channelID, "").
|
||||
Return(&mockChannel, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(emailID, "").
|
||||
GetUserByEmail(context.Background(), emailID, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateIncomingWebhook(&mockIncomingWebhook).
|
||||
CreateIncomingWebhook(context.Background(), &mockIncomingWebhook).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -268,13 +269,13 @@ func (s *MmctlUnitTestSuite) TestModifyIncomingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(incomingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), incomingWebhookID, "").
|
||||
Return(&mockIncomingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateIncomingWebhook(&mockIncomingWebhook).
|
||||
UpdateIncomingWebhook(context.Background(), &mockIncomingWebhook).
|
||||
Return(&updatedIncomingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -306,13 +307,13 @@ func (s *MmctlUnitTestSuite) TestModifyIncomingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(incomingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), incomingWebhookID, "").
|
||||
Return(&mockIncomingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateIncomingWebhook(&mockIncomingWebhook).
|
||||
UpdateIncomingWebhook(context.Background(), &mockIncomingWebhook).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -362,19 +363,19 @@ func (s *MmctlUnitTestSuite) TestCreateOutgoingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(emailID, "").
|
||||
GetUserByEmail(context.Background(), emailID, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateOutgoingWebhook(&mockOutgoingWebhook).
|
||||
CreateOutgoingWebhook(context.Background(), &mockOutgoingWebhook).
|
||||
Return(&createdOutgoingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -408,19 +409,19 @@ func (s *MmctlUnitTestSuite) TestCreateOutgoingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetTeam(teamID, "").
|
||||
GetTeam(context.Background(), teamID, "").
|
||||
Return(&mockTeam, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetUserByEmail(emailID, "").
|
||||
GetUserByEmail(context.Background(), emailID, "").
|
||||
Return(&mockUser, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
CreateOutgoingWebhook(&mockOutgoingWebhook).
|
||||
CreateOutgoingWebhook(context.Background(), &mockOutgoingWebhook).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -455,13 +456,13 @@ func (s *MmctlUnitTestSuite) TestModifyOutgoingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhook(outgoingWebhookID).
|
||||
GetOutgoingWebhook(context.Background(), outgoingWebhookID).
|
||||
Return(&mockOutgoingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateOutgoingWebhook(&mockOutgoingWebhook).
|
||||
UpdateOutgoingWebhook(context.Background(), &mockOutgoingWebhook).
|
||||
Return(&updatedOutgoingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -490,13 +491,13 @@ func (s *MmctlUnitTestSuite) TestModifyOutgoingWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhook(outgoingWebhookID).
|
||||
GetOutgoingWebhook(context.Background(), outgoingWebhookID).
|
||||
Return(&mockOutgoingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
UpdateOutgoingWebhook(&mockOutgoingWebhook).
|
||||
UpdateOutgoingWebhook(context.Background(), &mockOutgoingWebhook).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -519,13 +520,13 @@ func (s *MmctlUnitTestSuite) TestDeleteWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(incomingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), incomingWebhookID, "").
|
||||
Return(&mockIncomingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteIncomingWebhook(incomingWebhookID).
|
||||
DeleteIncomingWebhook(context.Background(), incomingWebhookID).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -544,19 +545,19 @@ func (s *MmctlUnitTestSuite) TestDeleteWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(outgoingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), outgoingWebhookID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhook(outgoingWebhookID).
|
||||
GetOutgoingWebhook(context.Background(), outgoingWebhookID).
|
||||
Return(&mockOutgoingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteOutgoingWebhook(outgoingWebhookID).
|
||||
DeleteOutgoingWebhook(context.Background(), outgoingWebhookID).
|
||||
Return(&model.Response{StatusCode: http.StatusOK}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -575,13 +576,13 @@ func (s *MmctlUnitTestSuite) TestDeleteWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(incomingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), incomingWebhookID, "").
|
||||
Return(&mockIncomingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteIncomingWebhook(incomingWebhookID).
|
||||
DeleteIncomingWebhook(context.Background(), incomingWebhookID).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -600,19 +601,19 @@ func (s *MmctlUnitTestSuite) TestDeleteWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(outgoingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), outgoingWebhookID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhook(outgoingWebhookID).
|
||||
GetOutgoingWebhook(context.Background(), outgoingWebhookID).
|
||||
Return(&mockOutgoingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
DeleteOutgoingWebhook(outgoingWebhookID).
|
||||
DeleteOutgoingWebhook(context.Background(), outgoingWebhookID).
|
||||
Return(&model.Response{StatusCode: http.StatusBadRequest}, mockError).
|
||||
Times(1)
|
||||
|
||||
@@ -636,7 +637,7 @@ func (s *MmctlUnitTestSuite) TestShowWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(incomingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), incomingWebhookID, "").
|
||||
Return(&mockIncomingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -655,13 +656,13 @@ func (s *MmctlUnitTestSuite) TestShowWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(outgoingWebhookID, "").
|
||||
GetIncomingWebhook(context.Background(), outgoingWebhookID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhook(outgoingWebhookID).
|
||||
GetOutgoingWebhook(context.Background(), outgoingWebhookID).
|
||||
Return(&mockOutgoingWebhook, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
@@ -679,13 +680,13 @@ func (s *MmctlUnitTestSuite) TestShowWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhook(nonExistentID, "").
|
||||
GetIncomingWebhook(context.Background(), nonExistentID, "").
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetOutgoingWebhook(nonExistentID).
|
||||
GetOutgoingWebhook(context.Background(), nonExistentID).
|
||||
Return(nil, &model.Response{}, mockError).
|
||||
Times(1)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user