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

133 lines
3.3 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package teams
import (
"bytes"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"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"
)
type TestHelper struct {
service *TeamService
configStore *config.Store
dbStore store.Store
workspace string
Context *request.Context
LogBuffer *bytes.Buffer
TB testing.TB
}
type mockWebHub struct{}
func (mockWebHub) Publish(*model.WebSocketEvent) {}
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, includeCacheLayer bool, tb testing.TB) *TestHelper {
tempWorkspace, err := os.MkdirTemp("", "teamservicetest")
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: &TeamService{
store: s.Team(),
channelStore: s.Channel(),
groupStore: s.Group(),
config: configStore.Get,
license: func() *model.License {
return model.NewTestLicense()
},
wh: &mockWebHub{},
},
Context: request.EmptyContext(mlog.CreateConsoleTestLogger(tb)),
configStore: configStore,
dbStore: s,
LogBuffer: buffer,
workspace: tempWorkspace,
}
}
func (th *TestHelper) UpdateConfig(f func(*model.Config)) {
if th.configStore.IsReadOnly() {
return
}
old := th.configStore.Get()
updated := old.Clone()
f(updated)
_, _, err := th.configStore.Set(updated)
require.NoError(th.TB, err)
}
func (th *TestHelper) CreateUser(u *model.User) *model.User {
u.EmailVerified = true
user, err := th.dbStore.User().Save(th.Context, u)
require.NoError(th.TB, err)
return user
}
func (th *TestHelper) DeleteUser(u *model.User) {
err := th.dbStore.User().PermanentDelete(th.Context, u.Id)
require.NoError(th.TB, err)
}
func (th *TestHelper) DeleteTeam(t *model.Team) {
err := th.dbStore.Channel().PermanentDeleteByTeam(t.Id)
require.NoError(th.TB, err)
err = th.dbStore.Team().RemoveAllMembersByTeam(t.Id)
require.NoError(th.TB, err)
err = th.dbStore.Team().PermanentDelete(t.Id)
require.NoError(th.TB, err)
}