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

141 lines
3.6 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package users
import (
"bytes"
"os"
"path/filepath"
"testing"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/public/shared/mlog"
"github.com/hanzoteam/server/server/public/shared/request"
"github.com/hanzoteam/server/server/v8/channels/store"
"github.com/hanzoteam/server/server/v8/config"
"github.com/stretchr/testify/require"
)
type TestHelper struct {
service *UserService
configStore *config.Store
dbStore store.Store
workspace string
Context *request.Context
BasicUser *model.User
BasicUser2 *model.User
SystemAdminUser *model.User
LogBuffer *bytes.Buffer
}
func Setup(tb testing.TB) *TestHelper {
if testing.Short() {
tb.SkipNow()
}
dbStore := mainHelper.GetStore()
dbStore.DropAllTables()
dbStore.MarkSystemRanUnitTests()
mainHelper.PreloadMigrations()
return setupTestHelper(dbStore, false, tb)
}
func setupTestHelper(s store.Store, _ bool, tb testing.TB) *TestHelper {
tempWorkspace, err := os.MkdirTemp("", "userservicetest")
require.NoError(tb, err)
configStore := config.NewTestMemoryStore()
config := configStore.Get()
*config.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins")
*config.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp")
*config.PluginSettings.AutomaticPrepackagedPlugins = false
*config.LogSettings.EnableSentry = false // disable error reporting during tests
*config.AnnouncementSettings.AdminNoticesEnabled = false
*config.AnnouncementSettings.UserNoticesEnabled = false
*config.TeamSettings.MaxUsersPerTeam = 50
*config.RateLimitSettings.Enable = false
*config.TeamSettings.EnableOpenServer = true
_, _, err = configStore.Set(config)
require.NoError(tb, err)
buffer := &bytes.Buffer{}
tb.Cleanup(func() {
err := configStore.Close()
require.NoError(tb, err)
s.Close()
if tempWorkspace != "" {
os.RemoveAll(tempWorkspace)
}
})
return &TestHelper{
service: &UserService{
store: s.User(),
sessionStore: s.Session(),
oAuthStore: s.OAuth(),
config: configStore.Get,
},
Context: request.EmptyContext(mlog.CreateConsoleTestLogger(tb)),
configStore: configStore,
dbStore: s,
LogBuffer: buffer,
workspace: tempWorkspace,
}
}
func (th *TestHelper) InitBasic(tb testing.TB) *TestHelper {
var err error
th.SystemAdminUser = th.CreateUser(tb)
th.SystemAdminUser, err = th.service.GetUser(th.Context, th.SystemAdminUser.Id)
require.NoError(tb, err)
th.BasicUser = th.CreateUser(tb)
th.BasicUser, err = th.service.GetUser(th.Context, th.BasicUser.Id)
require.NoError(tb, err)
th.BasicUser2 = th.CreateUser(tb)
th.BasicUser2, err = th.service.GetUser(th.Context, th.BasicUser2.Id)
require.NoError(tb, err)
return th
}
func (th *TestHelper) CreateUser(tb testing.TB) *model.User {
return th.CreateUserOrGuest(tb, false)
}
func (th *TestHelper) CreateGuest(tb testing.TB) *model.User {
return th.CreateUserOrGuest(tb, true)
}
func (th *TestHelper) CreateUserOrGuest(tb testing.TB, guest bool) *model.User {
id := model.NewId()
user := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: model.NewTestPassword(),
EmailVerified: true,
}
var err error
if guest {
user, err = th.service.CreateUser(th.Context, user, UserCreateOptions{Guest: true})
require.NoError(tb, err)
} else {
user, err = th.service.CreateUser(th.Context, user, UserCreateOptions{})
require.NoError(tb, err)
}
return user
}