Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

107 lines
3.5 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"context"
"fmt"
"net/http"
"github.com/hanzoteam/server/server/public/model"
"github.com/pkg/errors"
"github.com/hanzoteam/server/server/v8/cmd/mmctl/printer"
)
func (s *MmctlUnitTestSuite) TestGetUserFromArgs() {
s.Run("user not found", func() {
notFoundEmail := "[email protected]"
notFoundErr := errors.New("user not found")
printer.Clean()
s.client.
EXPECT().
GetUserByUsername(context.TODO(), notFoundEmail, "").
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
Times(1)
s.client.
EXPECT().
GetUser(context.TODO(), notFoundEmail, "").
Return(nil, &model.Response{StatusCode: http.StatusNotFound}, notFoundErr).
Times(1)
users, err := getUsersFromArgs(s.client, []string{notFoundEmail})
s.Require().Empty(users)
s.Require().NotNil(err)
s.Require().EqualError(err, fmt.Sprintf("1 error occurred:\n\t* user %s not found\n\n", notFoundEmail))
})
s.Run("bad request don't throw unexpected error", func() {
badRequestEmail := "[email protected]"
badRequestErr := errors.New("bad request")
printer.Clean()
s.client.
EXPECT().
GetUserByEmail(context.TODO(), badRequestEmail, "").
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
Times(1)
s.client.
EXPECT().
GetUserByUsername(context.TODO(), badRequestEmail, "").
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
Times(1)
s.client.
EXPECT().
GetUser(context.TODO(), badRequestEmail, "").
Return(nil, &model.Response{StatusCode: http.StatusBadRequest}, badRequestErr).
Times(1)
users, err := getUsersFromArgs(s.client, []string{badRequestEmail})
s.Require().Empty(users)
s.Require().NotNil(err)
s.Require().EqualError(err, fmt.Sprintf("1 error occurred:\n\t* user %s not found\n\n", badRequestEmail))
})
s.Run("unexpected error throws according error", func() {
unexpectedErrEmail := "[email protected]"
unexpectedErr := errors.New("internal server error")
printer.Clean()
s.client.
EXPECT().
GetUserByEmail(context.TODO(), unexpectedErrEmail, "").
Return(nil, &model.Response{StatusCode: http.StatusInternalServerError}, unexpectedErr).
Times(1)
users, err := getUsersFromArgs(s.client, []string{unexpectedErrEmail})
s.Require().Empty(users)
s.Require().NotNil(err)
s.Require().EqualError(err, "1 error occurred:\n\t* internal server error\n\n")
})
s.Run("forbidden error stops searching", func() {
forbiddenErrEmail := "[email protected]"
forbiddenErr := errors.New("forbidden")
printer.Clean()
s.client.
EXPECT().
GetUserByEmail(context.TODO(), forbiddenErrEmail, "").
Return(nil, &model.Response{StatusCode: http.StatusForbidden}, forbiddenErr).
Times(1)
users, err := getUsersFromArgs(s.client, []string{forbiddenErrEmail})
s.Require().Empty(users)
s.Require().NotNil(err)
s.Require().EqualError(err, "1 error occurred:\n\t* forbidden\n\n")
})
s.Run("success", func() {
successEmail := "[email protected]"
successUser := &model.User{Email: successEmail}
printer.Clean()
s.client.
EXPECT().
GetUserByEmail(context.TODO(), successEmail, "").
Return(successUser, nil, nil).
Times(1)
users, err := getUsersFromArgs(s.client, []string{successEmail})
s.Require().NoError(err)
s.Require().Len(users, 1)
s.Require().Equal(successUser, users[0])
})
}