snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
90
server/channels/testlib/assertions.go
Normal file
90
server/channels/testlib/assertions.go
Normal file
@@ -0,0 +1,90 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// AssertLog asserts that a JSON-encoded buffer of logs contains one with the given level and message.
|
||||
func AssertLog(t *testing.T, logs io.Reader, level, message string) {
|
||||
t.Helper()
|
||||
if !hasMsg(t, logs, level, message) {
|
||||
assert.Failf(t, "failed to find", "Expected log_level: %s, log_message: %s", level, message)
|
||||
}
|
||||
}
|
||||
|
||||
// AssertNoLog asserts that a JSON-encoded buffer of logs does not contains one with the given level and message.
|
||||
func AssertNoLog(t *testing.T, logs io.Reader, level, message string) {
|
||||
t.Helper()
|
||||
if hasMsg(t, logs, level, message) {
|
||||
assert.Failf(t, "found", "Not expected log_level: %s log_message: %s", level, message)
|
||||
}
|
||||
}
|
||||
|
||||
// CheckLog checks whether a JSON-encoded buffer of logs contain the given
|
||||
// message at the level or not.
|
||||
func CheckLog(t *testing.T, logs io.Reader, level, message string) bool {
|
||||
return hasMsg(t, logs, level, message)
|
||||
}
|
||||
|
||||
func hasMsg(t *testing.T, logs io.Reader, level, message string) bool {
|
||||
dec := json.NewDecoder(logs)
|
||||
for {
|
||||
var entry struct {
|
||||
Level string
|
||||
Msg string
|
||||
}
|
||||
err := dec.Decode(&entry)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
require.NoError(t, err, "Error decoding log entry")
|
||||
|
||||
if entry.Level == "" || entry.Msg == "" {
|
||||
t.Logf("Invalid log entry: %s", entry)
|
||||
continue
|
||||
}
|
||||
|
||||
if entry.Level == level && entry.Msg == message {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type LogEntry struct {
|
||||
Level string `json:"level"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
// ParseLogEntries parses a JSON-encoded buffer of logs and returns a list of log entries.
|
||||
func ParseLogEntries(t *testing.T, logs io.Reader) []LogEntry {
|
||||
t.Helper()
|
||||
var entries []LogEntry
|
||||
|
||||
dec := json.NewDecoder(logs)
|
||||
for {
|
||||
var entry LogEntry
|
||||
err := dec.Decode(&entry)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
require.NoError(t, err, "Error decoding log entry")
|
||||
|
||||
if entry.Level == "" || entry.Msg == "" {
|
||||
t.Logf("Invalid log entry: %s", entry)
|
||||
continue
|
||||
}
|
||||
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
|
||||
return entries
|
||||
}
|
||||
120
server/channels/testlib/cluster.go
Normal file
120
server/channels/testlib/cluster.go
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces"
|
||||
)
|
||||
|
||||
type FakeClusterInterface struct {
|
||||
clusterMessageHandler einterfaces.ClusterMessageHandler
|
||||
mut sync.RWMutex
|
||||
messages []*model.ClusterMessage
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) StartInterNodeCommunication() {}
|
||||
|
||||
func (c *FakeClusterInterface) StopInterNodeCommunication() {}
|
||||
|
||||
func (c *FakeClusterInterface) RegisterClusterMessageHandler(event model.ClusterEvent, crm einterfaces.ClusterMessageHandler) {
|
||||
c.clusterMessageHandler = crm
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) HealthScore() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) GetClusterId() string { return "" }
|
||||
|
||||
func (c *FakeClusterInterface) IsLeader() bool { return false }
|
||||
|
||||
func (c *FakeClusterInterface) GetMyClusterInfo() *model.ClusterInfo { return nil }
|
||||
|
||||
func (c *FakeClusterInterface) GetClusterInfos() ([]*model.ClusterInfo, error) { return nil, nil }
|
||||
|
||||
func (c *FakeClusterInterface) SendClusterMessage(message *model.ClusterMessage) {
|
||||
c.mut.Lock()
|
||||
defer c.mut.Unlock()
|
||||
c.messages = append(c.messages, message)
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) SendClusterMessageToNode(nodeID string, message *model.ClusterMessage) error {
|
||||
c.mut.Lock()
|
||||
defer c.mut.Unlock()
|
||||
c.messages = append(c.messages, message)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) NotifyMsg(buf []byte) {}
|
||||
|
||||
func (c *FakeClusterInterface) GetClusterStats(rctx request.CTX) ([]*model.ClusterStats, *model.AppError) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) GetLogs(rctx request.CTX, page, perPage int) ([]string, *model.AppError) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) QueryLogs(rctx request.CTX, page, perPage int) (map[string][]string, *model.AppError) {
|
||||
return make(map[string][]string), nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) GenerateSupportPacket(rctx request.CTX, options *model.SupportPacketOptions) (map[string][]model.FileData, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) ConfigChanged(previousConfig *model.Config, newConfig *model.Config, sendToOtherServer bool) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) SendClearRoleCacheMessage() {
|
||||
if c.clusterMessageHandler != nil {
|
||||
c.clusterMessageHandler(&model.ClusterMessage{
|
||||
Event: model.ClusterEventInvalidateCacheForRoles,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) GetPluginStatuses() (model.PluginStatuses, *model.AppError) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) GetMessages() []*model.ClusterMessage {
|
||||
c.mut.RLock()
|
||||
defer c.mut.RUnlock()
|
||||
return c.messages
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) SelectMessages(filterCond func(message *model.ClusterMessage) bool) []*model.ClusterMessage {
|
||||
c.mut.RLock()
|
||||
defer c.mut.RUnlock()
|
||||
|
||||
filteredMessages := []*model.ClusterMessage{}
|
||||
for _, msg := range c.messages {
|
||||
if filterCond(msg) {
|
||||
filteredMessages = append(filteredMessages, msg)
|
||||
}
|
||||
}
|
||||
return filteredMessages
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) ClearMessages() {
|
||||
c.mut.Lock()
|
||||
defer c.mut.Unlock()
|
||||
c.messages = nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) WebConnCountForUser(userID string) (int, *model.AppError) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) GetWSQueues(userID, connectionID string, seqNum int64) (map[string]*model.WSQueues, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *FakeClusterInterface) Shutdown() {}
|
||||
5
server/channels/testlib/doc.go
Normal file
5
server/channels/testlib/doc.go
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// Package testlib exposes helper methods for running unit tests against a containerized test store.
|
||||
package testlib
|
||||
12
server/channels/testlib/hashers_dev.go
Normal file
12
server/channels/testlib/hashers_dev.go
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
//go:build !production
|
||||
|
||||
package testlib
|
||||
|
||||
import "github.com/mattermost/mattermost/server/v8/channels/app/password/hashers"
|
||||
|
||||
func setupFastTestHasher() {
|
||||
hashers.SetTestHasher(hashers.FastTestHasher())
|
||||
}
|
||||
8
server/channels/testlib/hashers_production.go
Normal file
8
server/channels/testlib/hashers_production.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
//go:build production
|
||||
|
||||
package testlib
|
||||
|
||||
func setupFastTestHasher() {}
|
||||
364
server/channels/testlib/helper.go
Normal file
364
server/channels/testlib/helper.go
Normal file
@@ -0,0 +1,364 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/searchlayer"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
|
||||
)
|
||||
|
||||
type MainHelper struct {
|
||||
Settings *model.SqlSettings
|
||||
Store store.Store
|
||||
SearchEngine *searchengine.Broker
|
||||
SQLStore *sqlstore.SqlStore
|
||||
ClusterInterface *FakeClusterInterface
|
||||
Logger *mlog.Logger
|
||||
Options HelperOptions
|
||||
|
||||
status int
|
||||
testResourcePath string
|
||||
testLogsPath string
|
||||
replicas []string
|
||||
storePool *sqlstore.TestPool
|
||||
}
|
||||
|
||||
type HelperOptions struct {
|
||||
EnableStore bool
|
||||
EnableResources bool
|
||||
RunParallel bool
|
||||
Parallelism int
|
||||
}
|
||||
|
||||
func NewMainHelper() *MainHelper {
|
||||
// Ignore any globally defined datasource if a test dsn defined
|
||||
if os.Getenv("TEST_DATABASE_POSTGRESQL_DSN") != "" {
|
||||
os.Unsetenv("MM_SQLSETTINGS_DATASOURCE")
|
||||
}
|
||||
|
||||
return NewMainHelperWithOptions(&HelperOptions{
|
||||
EnableStore: true,
|
||||
EnableResources: true,
|
||||
})
|
||||
}
|
||||
|
||||
func NewMainHelperWithOptions(options *HelperOptions) *MainHelper {
|
||||
flag.Parse()
|
||||
|
||||
h := &MainHelper{
|
||||
Logger: mlog.CreateConsoleLogger(),
|
||||
}
|
||||
if options != nil {
|
||||
h.Options = *options
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *MainHelper) Main(m *testing.M) {
|
||||
if f := flag.Lookup("test.list"); f != nil && f.Value.String() != "" {
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := h.Logger.Shutdown()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Ignore any globally defined datasource if a test dsn defined
|
||||
if os.Getenv("TEST_DATABASE_POSTGRESQL_DSN") != "" {
|
||||
os.Unsetenv("MM_SQLSETTINGS_DATASOURCE")
|
||||
}
|
||||
|
||||
// Unset environment variables commonly set for development that interfere with tests.
|
||||
os.Unsetenv("MM_SERVICESETTINGS_SITEURL")
|
||||
os.Unsetenv("MM_SERVICESETTINGS_LISTENADDRESS")
|
||||
os.Unsetenv("MM_SERVICESETTINGS_CONNECTIONSECURITY")
|
||||
os.Unsetenv("MM_SERVICESETTINGS_ENABLEDEVELOPER")
|
||||
|
||||
if _, err := mlog.NewLogger(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := utils.TranslationsPreInit(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Use a fast password hasher during tests to speed up user creation.
|
||||
setupFastTestHasher()
|
||||
|
||||
// Create a logs directory and set MM_LOG_PATH for tests that validate log file paths.
|
||||
// This is done unconditionally so tests don't need to enable full resources just for logging.
|
||||
logsDir, err := os.MkdirTemp("", "testlogs")
|
||||
if err != nil {
|
||||
log.Fatal("Failed to create test logs directory: " + err.Error())
|
||||
}
|
||||
os.Setenv("MM_LOG_PATH", logsDir)
|
||||
h.testLogsPath = logsDir
|
||||
|
||||
if h.Options.EnableStore && !testing.Short() {
|
||||
h.setupStore()
|
||||
}
|
||||
|
||||
if h.Options.EnableResources {
|
||||
h.setupResources()
|
||||
}
|
||||
|
||||
if h.Options.RunParallel && h.Options.EnableStore {
|
||||
driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME")
|
||||
if driverName == "" {
|
||||
driverName = model.DatabaseDriverPostgres
|
||||
}
|
||||
// NOTE: we use a poolSize higher than the parallelism value (coming from -test.parallel flag) as we need a bit of extra buffer to cover
|
||||
// for subtests that might also run in parallel and initialize a new store.
|
||||
storePool, err := sqlstore.NewTestPool(h.Logger, driverName, h.Options.Parallelism*2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
h.storePool = storePool
|
||||
}
|
||||
|
||||
if h.testResourcePath != "" {
|
||||
prevDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic("Failed to get current working directory: " + err.Error())
|
||||
}
|
||||
|
||||
err = os.Chdir(h.testResourcePath)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to set current working directory to %s: %s", h.testResourcePath, err.Error()))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := os.Chdir(prevDir)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to restore current working directory to %s: %s", prevDir, err.Error()))
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
h.status = m.Run()
|
||||
}
|
||||
|
||||
func (h *MainHelper) GetNewStores(tb testing.TB) (store.Store, *sqlstore.SqlStore, *model.SqlSettings, *searchengine.Broker) {
|
||||
driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME")
|
||||
if driverName == "" {
|
||||
driverName = model.DatabaseDriverPostgres
|
||||
}
|
||||
|
||||
config := &model.Config{}
|
||||
config.SetDefaults()
|
||||
|
||||
searchEngine := searchengine.NewBroker(config)
|
||||
|
||||
storePoolEntry := h.storePool.Get(tb)
|
||||
if storePoolEntry == nil {
|
||||
panic("no store available in the pool")
|
||||
}
|
||||
settings := storePoolEntry.Settings
|
||||
sqlStore := storePoolEntry.Store
|
||||
sqlStore.DropAllTables()
|
||||
|
||||
store := searchlayer.NewSearchLayer(&TestStore{
|
||||
sqlStore,
|
||||
}, searchEngine, config)
|
||||
|
||||
store.MarkSystemRanUnitTests()
|
||||
|
||||
preloadMigrations(driverName, sqlStore)
|
||||
|
||||
return store, sqlStore, settings, searchEngine
|
||||
}
|
||||
|
||||
func (h *MainHelper) setupStore() {
|
||||
driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME")
|
||||
if driverName == "" {
|
||||
driverName = model.DatabaseDriverPostgres
|
||||
}
|
||||
|
||||
h.Settings = storetest.MakeSqlSettings(driverName)
|
||||
h.replicas = h.Settings.DataSourceReplicas
|
||||
|
||||
config := &model.Config{}
|
||||
config.SetDefaults()
|
||||
|
||||
h.SearchEngine = searchengine.NewBroker(config)
|
||||
h.ClusterInterface = &FakeClusterInterface{}
|
||||
|
||||
var err error
|
||||
h.SQLStore, err = sqlstore.New(*h.Settings, h.Logger, nil, sqlstore.DisableMorphLogging())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
h.Store = searchlayer.NewSearchLayer(&TestStore{
|
||||
h.SQLStore,
|
||||
}, h.SearchEngine, config)
|
||||
}
|
||||
|
||||
func (h *MainHelper) ToggleReplicasOff() {
|
||||
if h.SQLStore.GetLicense() == nil {
|
||||
panic("expecting a license to use this")
|
||||
}
|
||||
h.Settings.DataSourceReplicas = []string{}
|
||||
lic := h.SQLStore.GetLicense()
|
||||
|
||||
var err error
|
||||
h.SQLStore, err = sqlstore.New(*h.Settings, h.Logger, nil, sqlstore.DisableMorphLogging())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
h.SQLStore.UpdateLicense(lic)
|
||||
}
|
||||
|
||||
func (h *MainHelper) ToggleReplicasOn() {
|
||||
if h.SQLStore.GetLicense() == nil {
|
||||
panic("expecting a license to use this")
|
||||
}
|
||||
h.Settings.DataSourceReplicas = h.replicas
|
||||
lic := h.SQLStore.GetLicense()
|
||||
|
||||
var err error
|
||||
h.SQLStore, err = sqlstore.New(*h.Settings, h.Logger, nil, sqlstore.DisableMorphLogging())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
h.SQLStore.UpdateLicense(lic)
|
||||
}
|
||||
|
||||
func (h *MainHelper) setupResources() {
|
||||
var err error
|
||||
h.testResourcePath, err = SetupTestResources()
|
||||
if err != nil {
|
||||
panic("failed to setup test resources: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// PreloadMigrations preloads the migrations and roles into the database
|
||||
// so that they are not run again when the migrations happen every time
|
||||
// the server is started.
|
||||
// This change is forward-compatible with new migrations and only new migrations
|
||||
// will get executed.
|
||||
// Only if the schema of either roles or systems table changes, this will break.
|
||||
// In that case, just update the migrations or comment this out for the time being.
|
||||
// In the worst case, only an optimization is lost.
|
||||
//
|
||||
// Re-generate the files with:
|
||||
// pg_dump -a -h localhost -U mmuser -d <> --no-comments --inserts -t roles -t systems
|
||||
// And keep only the permission related rows in the systems table output.
|
||||
func preloadMigrations(driverName string, sqlStore *sqlstore.SqlStore) {
|
||||
var buf []byte
|
||||
var err error
|
||||
|
||||
switch driverName {
|
||||
case model.DatabaseDriverPostgres:
|
||||
finalPath := filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "postgres_migration_warmup.sql")
|
||||
buf, err = os.ReadFile(finalPath)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot read file: %v", err))
|
||||
}
|
||||
default:
|
||||
panic(fmt.Errorf("unsupported database driver: %s", driverName))
|
||||
}
|
||||
handle := sqlStore.GetMaster()
|
||||
_, err = handle.Exec(string(buf))
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error preloading migrations. Perhaps the schema changed? If yes, then update the warmup files accordingly"))
|
||||
}
|
||||
}
|
||||
|
||||
func (h *MainHelper) PreloadMigrations() {
|
||||
preloadMigrations(*h.Settings.DriverName, h.SQLStore)
|
||||
}
|
||||
|
||||
func (h *MainHelper) Close() error {
|
||||
if h.SQLStore != nil {
|
||||
h.SQLStore.Close()
|
||||
}
|
||||
if h.Settings != nil {
|
||||
storetest.CleanupSqlSettings(h.Settings)
|
||||
}
|
||||
if h.testResourcePath != "" {
|
||||
os.RemoveAll(h.testResourcePath)
|
||||
}
|
||||
if h.testLogsPath != "" {
|
||||
os.RemoveAll(h.testLogsPath)
|
||||
os.Unsetenv("MM_LOG_PATH")
|
||||
}
|
||||
|
||||
if h.storePool != nil {
|
||||
h.storePool.Close()
|
||||
}
|
||||
|
||||
if r := recover(); r != nil {
|
||||
log.Fatalln(r)
|
||||
}
|
||||
|
||||
os.Exit(h.status)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MainHelper) GetSQLSettings() *model.SqlSettings {
|
||||
if h.Settings == nil {
|
||||
panic("MainHelper not initialized with database access.")
|
||||
}
|
||||
|
||||
return h.Settings
|
||||
}
|
||||
|
||||
func (h *MainHelper) GetStore() store.Store {
|
||||
if h.Store == nil {
|
||||
panic("MainHelper not initialized with store.")
|
||||
}
|
||||
|
||||
return h.Store
|
||||
}
|
||||
|
||||
func (h *MainHelper) GetSQLStore() *sqlstore.SqlStore {
|
||||
if h.SQLStore == nil {
|
||||
panic("MainHelper not initialized with sql store.")
|
||||
}
|
||||
|
||||
return h.SQLStore
|
||||
}
|
||||
|
||||
func (h *MainHelper) GetClusterInterface() *FakeClusterInterface {
|
||||
if h.ClusterInterface == nil {
|
||||
panic("MainHelper not initialized with cluster interface.")
|
||||
}
|
||||
|
||||
return h.ClusterInterface
|
||||
}
|
||||
|
||||
func (h *MainHelper) GetSearchEngine() *searchengine.Broker {
|
||||
if h.SearchEngine == nil {
|
||||
panic("MainHelper not initialized with search engine")
|
||||
}
|
||||
|
||||
return h.SearchEngine
|
||||
}
|
||||
|
||||
func (h *MainHelper) Parallel(t *testing.T) {
|
||||
if h.Options.RunParallel {
|
||||
t.Parallel()
|
||||
}
|
||||
}
|
||||
218
server/channels/testlib/resources.go
Normal file
218
server/channels/testlib/resources.go
Normal file
@@ -0,0 +1,218 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/utils"
|
||||
"github.com/mattermost/mattermost/server/v8"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/shared/filestore"
|
||||
)
|
||||
|
||||
const (
|
||||
resourceTypeFile = iota
|
||||
resourceTypeFolder
|
||||
)
|
||||
|
||||
const (
|
||||
actionCopy = iota
|
||||
actionSymlink
|
||||
)
|
||||
|
||||
const root = "___mattermost-server"
|
||||
|
||||
type testResourceDetails struct {
|
||||
src string
|
||||
dest string
|
||||
resType int8
|
||||
action int8
|
||||
}
|
||||
|
||||
func findFile(path string) string {
|
||||
// Use the testdata path to search from the root of the monorepo.
|
||||
searchPaths := fileutils.CommonBaseSearchPaths()
|
||||
searchPaths = append(searchPaths, filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "../../../"))
|
||||
|
||||
return fileutils.FindPath(path, searchPaths, func(fileInfo os.FileInfo) bool {
|
||||
return !fileInfo.IsDir()
|
||||
})
|
||||
}
|
||||
|
||||
func findDir(dir string) (string, bool) {
|
||||
if dir == root {
|
||||
srcPath := findFile("go.mod")
|
||||
if srcPath == "" {
|
||||
return "./", false
|
||||
}
|
||||
|
||||
return path.Dir(srcPath), true
|
||||
}
|
||||
|
||||
// Use the testdata path to search from the root of the monorepo.
|
||||
searchPaths := fileutils.CommonBaseSearchPaths()
|
||||
searchPaths = append(searchPaths, filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "../../../"))
|
||||
|
||||
found := fileutils.FindPath(dir, searchPaths, func(fileInfo os.FileInfo) bool {
|
||||
return fileInfo.IsDir()
|
||||
})
|
||||
if found == "" {
|
||||
return "./", false
|
||||
}
|
||||
|
||||
return found, true
|
||||
}
|
||||
|
||||
func getTestResourcesToSetup() []testResourceDetails {
|
||||
var srcPath string
|
||||
var found bool
|
||||
|
||||
var testResourcesToSetup = []testResourceDetails{
|
||||
{root, "mattermost-server", resourceTypeFolder, actionSymlink},
|
||||
{"go.mod", "go.mod", resourceTypeFile, actionSymlink},
|
||||
{"i18n", "i18n", resourceTypeFolder, actionSymlink},
|
||||
{"templates", "templates", resourceTypeFolder, actionSymlink},
|
||||
{"tests", "tests", resourceTypeFolder, actionSymlink},
|
||||
{"fonts", "fonts", resourceTypeFolder, actionSymlink},
|
||||
{"channels/app/plugin_api_tests", "channels/app/plugin_api_tests", resourceTypeFolder, actionSymlink},
|
||||
{"channels/utils/policies-roles-mapping.json", "channels/utils/policies-roles-mapping.json", resourceTypeFile, actionSymlink},
|
||||
}
|
||||
|
||||
// Finding resources and setting full path to source to be used for further processing
|
||||
for i, testResource := range testResourcesToSetup {
|
||||
if testResource.resType == resourceTypeFile {
|
||||
srcPath = findFile(testResource.src)
|
||||
if srcPath == "" {
|
||||
panic(fmt.Sprintf("Failed to find file %s", testResource.src))
|
||||
}
|
||||
|
||||
testResourcesToSetup[i].src = srcPath
|
||||
} else if testResource.resType == resourceTypeFolder {
|
||||
srcPath, found = findDir(testResource.src)
|
||||
if !found {
|
||||
panic(fmt.Sprintf("Failed to find folder %s", testResource.src))
|
||||
}
|
||||
|
||||
testResourcesToSetup[i].src = srcPath
|
||||
} else {
|
||||
panic(fmt.Sprintf("Invalid resource type: %d", testResource.resType))
|
||||
}
|
||||
}
|
||||
|
||||
return testResourcesToSetup
|
||||
}
|
||||
|
||||
func CopyFile(src, dst string) error {
|
||||
fileBackend, err := filestore.NewFileBackend(filestore.FileBackendSettings{DriverName: "local", Directory: ""})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to copy file %s to %s", src, dst)
|
||||
}
|
||||
if err = fileBackend.CopyFile(src, dst); err != nil {
|
||||
return errors.Wrapf(err, "failed to copy file %s to %s", src, dst)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetupTestResources() (string, error) {
|
||||
testResourcesToSetup := getTestResourcesToSetup()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "testlib")
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to create temporary directory")
|
||||
}
|
||||
|
||||
pluginsDir := path.Join(tempDir, "plugins")
|
||||
err = os.Mkdir(pluginsDir, 0700)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to create plugins directory %s", pluginsDir)
|
||||
}
|
||||
|
||||
clientDir := path.Join(tempDir, "client")
|
||||
err = os.Mkdir(clientDir, 0700)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to create client directory %s", clientDir)
|
||||
}
|
||||
|
||||
logsDir := path.Join(tempDir, "logs")
|
||||
err = os.Mkdir(logsDir, 0700)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to create logs directory %s", logsDir)
|
||||
}
|
||||
|
||||
err = setupConfig(path.Join(tempDir, "config"))
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to setup config")
|
||||
}
|
||||
|
||||
var resourceDestInTemp string
|
||||
|
||||
// Setting up test resources in temp.
|
||||
// Action in each resource tells whether it needs to be copied or just symlinked
|
||||
for _, testResource := range testResourcesToSetup {
|
||||
resourceDestInTemp = filepath.Join(tempDir, testResource.dest)
|
||||
|
||||
if testResource.action == actionCopy {
|
||||
if testResource.resType == resourceTypeFile {
|
||||
if err = CopyFile(testResource.src, resourceDestInTemp); err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else if testResource.resType == resourceTypeFolder {
|
||||
err = utils.CopyDir(testResource.src, resourceDestInTemp)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to copy folder %s to %s", testResource.src, resourceDestInTemp)
|
||||
}
|
||||
}
|
||||
} else if testResource.action == actionSymlink {
|
||||
destDir := path.Dir(resourceDestInTemp)
|
||||
if destDir != "." {
|
||||
err = os.MkdirAll(destDir, os.ModePerm)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to make dir %s", destDir)
|
||||
}
|
||||
}
|
||||
|
||||
err = os.Symlink(testResource.src, resourceDestInTemp)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to symlink %s to %s", testResource.src, resourceDestInTemp)
|
||||
}
|
||||
} else {
|
||||
return "", errors.Wrapf(err, "Invalid action: %d", testResource.action)
|
||||
}
|
||||
}
|
||||
|
||||
return tempDir, nil
|
||||
}
|
||||
|
||||
func setupConfig(configDir string) error {
|
||||
var err error
|
||||
var config model.Config
|
||||
|
||||
config.SetDefaults()
|
||||
|
||||
err = os.Mkdir(configDir, 0700)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create config directory %s", configDir)
|
||||
}
|
||||
|
||||
buf, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal config: %v", err)
|
||||
}
|
||||
|
||||
configJSON := path.Join(configDir, "config.json")
|
||||
err = os.WriteFile(configJSON, buf, 0644)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to write config to %s", configJSON)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
18
server/channels/testlib/resources_test.go
Normal file
18
server/channels/testlib/resources_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFindDir(t *testing.T) {
|
||||
t.Run("find root", func(t *testing.T) {
|
||||
path, found := findDir(root)
|
||||
assert.True(t, found, "failed to find root")
|
||||
assert.NotEmpty(t, path)
|
||||
})
|
||||
}
|
||||
239
server/channels/testlib/store.go
Normal file
239
server/channels/testlib/store.go
Normal file
@@ -0,0 +1,239 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin/plugintest/mock"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
|
||||
)
|
||||
|
||||
type TestStore struct {
|
||||
store.Store
|
||||
}
|
||||
|
||||
func (s *TestStore) Close() {
|
||||
// Don't propagate to the underlying store, since this instance is persistent.
|
||||
}
|
||||
|
||||
func GetMockStoreForSetupFunctions() *mocks.Store {
|
||||
mockStore := mocks.Store{}
|
||||
systemStore := mocks.SystemStore{}
|
||||
systemStore.On("GetByName", "FirstAdminSetupComplete").Return(&model.System{Name: "FirstAdminSetupComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "RemainingSchemaMigrations").Return(&model.System{Name: "RemainingSchemaMigrations", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "ContentExtractionConfigDefaultTrueMigrationComplete").Return(&model.System{Name: "ContentExtractionConfigDefaultTrueMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "UpgradedFromTE").Return(nil, model.NewAppError("FakeError", "app.system.get_by_name.app_error", nil, "", http.StatusInternalServerError))
|
||||
systemStore.On("GetByName", "ContentExtractionConfigMigrationComplete").Return(&model.System{Name: "ContentExtractionConfigMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "AsymmetricSigningKey").Return(nil, model.NewAppError("FakeError", "app.system.get_by_name.app_error", nil, "", http.StatusInternalServerError))
|
||||
systemStore.On("GetByName", "PostActionCookieSecret").Return(nil, model.NewAppError("FakeError", "app.system.get_by_name.app_error", nil, "", http.StatusInternalServerError))
|
||||
systemStore.On("GetByName", "SamlRelayStateSigningKey").Return(nil, model.NewAppError("FakeError", "app.system.get_by_name.app_error", nil, "", http.StatusInternalServerError))
|
||||
systemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: strconv.FormatInt(model.GetMillis(), 10)}, nil)
|
||||
systemStore.On("GetByName", "FirstServerRunTimestamp").Return(&model.System{Name: "FirstServerRunTimestamp", Value: "10"}, nil)
|
||||
systemStore.On("GetByName", "AdvancedPermissionsMigrationComplete").Return(&model.System{Name: "AdvancedPermissionsMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "EmojisPermissionsMigrationComplete").Return(&model.System{Name: "EmojisPermissionsMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "GuestRolesCreationMigrationComplete").Return(&model.System{Name: "GuestRolesCreationMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "SystemConsoleRolesCreationMigrationComplete").Return(&model.System{Name: "SystemConsoleRolesCreationMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "PlaybookRolesCreationMigrationComplete").Return(&model.System{Name: "PlaybookRolesCreationMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "PostPriorityConfigDefaultTrueMigrationComplete").Return(&model.System{Name: "PostPriorityConfigDefaultTrueMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "content_flagging_setup_done").Return(&model.System{Name: "content_flagging_setup_done", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "boards_property_setup_done").Return(&model.System{Name: "boards_property_setup_done", Value: "v1"}, nil)
|
||||
systemStore.On("GetByName", "managed_category_setup_done").Return(&model.System{Name: "managed_category_setup_done", Value: "v2"}, nil)
|
||||
systemStore.On("GetByName", "managed_category_setup_done").Return(&model.System{Name: "managed_category_setup_done", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "session_attributes_setup_done").Return(&model.System{Name: "session_attributes_setup_done", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "cpa_display_name_backfill_done").Return(&model.System{Name: "cpa_display_name_backfill_done", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyEmojiPermissionsSplit).Return(&model.System{Name: model.MigrationKeyEmojiPermissionsSplit, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyWebhookPermissionsSplit).Return(&model.System{Name: model.MigrationKeyWebhookPermissionsSplit, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyIntegrationsOwnPermissions).Return(&model.System{Name: model.MigrationKeyIntegrationsOwnPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyListJoinPublicPrivateTeams).Return(&model.System{Name: model.MigrationKeyListJoinPublicPrivateTeams, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyRemovePermanentDeleteUser).Return(&model.System{Name: model.MigrationKeyRemovePermanentDeleteUser, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddBotPermissions).Return(&model.System{Name: model.MigrationKeyAddBotPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyApplyChannelManageDeleteToChannelUser).Return(&model.System{Name: model.MigrationKeyApplyChannelManageDeleteToChannelUser, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyRemoveChannelManageDeleteFromTeamUser).Return(&model.System{Name: model.MigrationKeyRemoveChannelManageDeleteFromTeamUser, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyViewMembersNewPermission).Return(&model.System{Name: model.MigrationKeyViewMembersNewPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddManageGuestsPermissions).Return(&model.System{Name: model.MigrationKeyAddManageGuestsPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyChannelModerationsPermissions).Return(&model.System{Name: model.MigrationKeyChannelModerationsPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddUseGroupMentionsPermission).Return(&model.System{Name: model.MigrationKeyAddUseGroupMentionsPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddSystemConsolePermissions).Return(&model.System{Name: model.MigrationKeyAddSystemConsolePermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddConvertChannelPermissions).Return(&model.System{Name: model.MigrationKeyAddConvertChannelPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddSystemRolesPermissions).Return(&model.System{Name: model.MigrationKeyAddSystemRolesPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddBillingPermissions).Return(&model.System{Name: model.MigrationKeyAddBillingPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddDownloadComplianceExportResults).Return(&model.System{Name: model.MigrationKeyAddDownloadComplianceExportResults, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddSiteSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddSiteSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddExperimentalSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddExperimentalSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddAuthenticationSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddAuthenticationSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddComplianceSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddExperimentalSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddEnvironmentSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddEnvironmentSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddReportingSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddReportingSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddTestEmailAncillaryPermission).Return(&model.System{Name: model.MigrationKeyAddTestEmailAncillaryPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddAboutSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddAboutSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddIntegrationsSubsectionPermissions).Return(&model.System{Name: model.MigrationKeyAddIntegrationsSubsectionPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddManageSharedChannelPermissions).Return(&model.System{Name: model.MigrationKeyAddManageSharedChannelPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddManageSecureConnectionsPermissions).Return(&model.System{Name: model.MigrationKeyAddManageSecureConnectionsPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddPlaybooksPermissions).Return(&model.System{Name: model.MigrationKeyAddPlaybooksPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddCustomUserGroupsPermissions).Return(&model.System{Name: model.MigrationKeyAddCustomUserGroupsPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddPlayboosksManageRolesPermissions).Return(&model.System{Name: model.MigrationKeyAddPlayboosksManageRolesPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddCustomUserGroupsPermissionRestore).Return(&model.System{Name: model.MigrationKeyAddCustomUserGroupsPermissionRestore, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddReadChannelContentPermissions).Return(&model.System{Name: model.MigrationKeyAddReadChannelContentPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyDeleteEmptyDrafts).Return(&model.System{Name: model.MigrationKeyDeleteEmptyDrafts, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyDeleteOrphanDrafts).Return(&model.System{Name: model.MigrationKeyDeleteOrphanDrafts, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddIPFilteringPermissions).Return(&model.System{Name: model.MigrationKeyAddIPFilteringPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddOutgoingOAuthConnectionsPermissions).Return(&model.System{Name: model.MigrationKeyAddOutgoingOAuthConnectionsPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddChannelBookmarksPermissions).Return(&model.System{Name: model.MigrationKeyAddChannelBookmarksPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyDeleteDmsPreferences).Return(&model.System{Name: model.MigrationKeyDeleteDmsPreferences, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddManageJobAncillaryPermissions).Return(&model.System{Name: model.MigrationKeyAddManageJobAncillaryPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddUploadFilePermission).Return(&model.System{Name: model.MigrationKeyAddUploadFilePermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.RestrictAccessToChannelConversionToPublic).Return(&model.System{Name: model.RestrictAccessToChannelConversionToPublic, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyFixReadAuditsPermission).Return(&model.System{Name: model.MigrationKeyFixReadAuditsPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationRemoveGetAnalyticsPermission).Return(&model.System{Name: model.MigrationRemoveGetAnalyticsPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "CustomGroupAdminRoleCreationMigrationComplete").Return(&model.System{Name: model.MigrationKeyAddPlayboosksManageRolesPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "SystemSharedChannelManagerRoleCreationMigrationComplete").Return(&model.System{Name: "SystemSharedChannelManagerRoleCreationMigrationComplete", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddSharedChannelManagerPermissions).Return(&model.System{Name: model.MigrationKeyAddSharedChannelManagerPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "products_boards").Return(&model.System{Name: "products_boards", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", "elasticsearch_fix_channel_index_migration").Return(&model.System{Name: "elasticsearch_fix_channel_index_migration", Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationAddSysconsoleMobileSecurityPermission).Return(&model.System{Name: model.MigrationAddSysconsoleMobileSecurityPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddChannelBannerPermissions).Return(&model.System{Name: model.MigrationKeyAddChannelBannerPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddChannelAccessRulesPermission).Return(&model.System{Name: model.MigrationKeyAddChannelAccessRulesPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddTeamAccessRulesPermission).Return(&model.System{Name: model.MigrationKeyAddTeamAccessRulesPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddChannelAutoTranslationPermissions).Return(&model.System{Name: model.MigrationKeyAddChannelAutoTranslationPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyRestoreManageOAuthPermission).Return(&model.System{Name: model.MigrationKeyRestoreManageOAuthPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAccessControlPolicyV0_3).Return(&model.System{Name: model.MigrationKeyAccessControlPolicyV0_3, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddManageAgentPermissions).Return(&model.System{Name: model.MigrationKeyAddManageAgentPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddEditFileAttachmentPermission).Return(&model.System{Name: model.MigrationKeyAddEditFileAttachmentPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddDiscoverableChannelPermissions).Return(&model.System{Name: model.MigrationKeyAddDiscoverableChannelPermissions, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationRemoveImportTeamPermission).Return(&model.System{Name: model.MigrationRemoveImportTeamPermission, Value: "true"}, nil)
|
||||
systemStore.On("GetByName", model.MigrationKeyAddAIRecapsPermissions).Return(&model.System{Name: model.MigrationKeyAddAIRecapsPermissions, Value: "true"}, nil)
|
||||
|
||||
systemStore.On("InsertIfExists", mock.AnythingOfType("*model.System")).Return(&model.System{}, nil).Once()
|
||||
systemStore.On("Save", mock.AnythingOfType("*model.System")).Return(nil)
|
||||
systemStore.On("SaveOrUpdate", mock.AnythingOfType("*model.System")).Return(nil)
|
||||
|
||||
diagnosticID := model.NewId()
|
||||
systemStore.On("Get").Return(model.StringMap{model.SystemServerId: diagnosticID}, nil)
|
||||
systemStore.On("GetByNameWithContext", mock.Anything, model.SystemServerId).Return(&model.System{Name: model.SystemServerId, Value: diagnosticID}, nil)
|
||||
|
||||
userStore := mocks.UserStore{}
|
||||
userStore.On("Count", mock.AnythingOfType("model.UserCountOptions")).Return(int64(1), nil)
|
||||
userStore.On("DeactivateGuests").Return(nil, nil)
|
||||
userStore.On("ClearCaches").Return(nil)
|
||||
|
||||
postStore := mocks.PostStore{}
|
||||
postStore.On("GetMaxPostSize").Return(4000)
|
||||
|
||||
statusStore := mocks.StatusStore{}
|
||||
statusStore.On("ResetAll").Return(nil)
|
||||
|
||||
channelStore := mocks.ChannelStore{}
|
||||
channelStore.On("ClearCaches").Return(nil)
|
||||
|
||||
schemeStore := mocks.SchemeStore{}
|
||||
schemeStore.On("GetAllPage", model.SchemeScopeTeam, mock.Anything, 100).Return([]*model.Scheme{}, nil)
|
||||
|
||||
teamStore := mocks.TeamStore{}
|
||||
|
||||
roleStore := mocks.RoleStore{}
|
||||
roleStore.On("GetAll").Return([]*model.Role{}, nil)
|
||||
|
||||
sessionStore := mocks.SessionStore{}
|
||||
oAuthStore := mocks.OAuthStore{}
|
||||
groupStore := mocks.GroupStore{}
|
||||
|
||||
pluginStore := mocks.PluginStore{}
|
||||
pluginStore.On("List", mock.Anything, mock.Anything, mock.Anything).Return([]string{}, nil)
|
||||
|
||||
propertyGroupStore := mocks.PropertyGroupStore{}
|
||||
propertyFieldStore := mocks.PropertyFieldStore{}
|
||||
propertyValueStore := mocks.PropertyValueStore{}
|
||||
|
||||
channelGuardStore := mocks.ChannelGuardStore{}
|
||||
channelGuardStore.On("GetAll", mock.Anything).Return([]*store.ChannelGuard{}, nil)
|
||||
|
||||
groupsByName := map[string]*model.PropertyGroup{}
|
||||
|
||||
accessControlGroup := &model.PropertyGroup{ID: model.NewId(), Name: model.AccessControlPropertyGroupName, Version: model.PropertyGroupVersionV2}
|
||||
contentFlaggingGroup := &model.PropertyGroup{ID: model.NewId(), Name: model.ContentFlaggingGroupName, Version: model.PropertyGroupVersionV1}
|
||||
managedCategoryGroup := &model.PropertyGroup{ID: model.NewId(), Name: model.ManagedCategoryPropertyGroupName, Version: model.PropertyGroupVersionV2}
|
||||
boardsGroup := &model.PropertyGroup{ID: model.NewId(), Name: model.BoardsPropertyGroupName, Version: model.PropertyGroupVersionV2}
|
||||
sessionAttributesGroup := &model.PropertyGroup{ID: model.NewId(), Name: model.SessionAttributesPropertyGroupName, Version: model.PropertyGroupVersionV2}
|
||||
|
||||
groupsByName[accessControlGroup.Name] = accessControlGroup
|
||||
groupsByName[contentFlaggingGroup.Name] = contentFlaggingGroup
|
||||
groupsByName[managedCategoryGroup.Name] = managedCategoryGroup
|
||||
groupsByName[boardsGroup.Name] = boardsGroup
|
||||
groupsByName[sessionAttributesGroup.Name] = sessionAttributesGroup
|
||||
|
||||
propertyGroupStore.On("Register", mock.AnythingOfType("*model.PropertyGroup")).Return(
|
||||
func(group *model.PropertyGroup) *model.PropertyGroup {
|
||||
if existing, ok := groupsByName[group.Name]; ok {
|
||||
return existing
|
||||
}
|
||||
|
||||
version := group.Version
|
||||
if version == 0 {
|
||||
version = model.PropertyGroupVersionV1
|
||||
}
|
||||
|
||||
created := &model.PropertyGroup{
|
||||
ID: model.NewId(),
|
||||
Name: group.Name,
|
||||
Version: version,
|
||||
}
|
||||
groupsByName[group.Name] = created
|
||||
return created
|
||||
},
|
||||
func(group *model.PropertyGroup) error {
|
||||
return nil
|
||||
},
|
||||
)
|
||||
propertyGroupStore.On("Get", model.AccessControlPropertyGroupName).Return(accessControlGroup, nil)
|
||||
propertyGroupStore.On("Get", model.ContentFlaggingGroupName).Return(contentFlaggingGroup, nil)
|
||||
propertyGroupStore.On("Get", model.ManagedCategoryPropertyGroupName).Return(managedCategoryGroup, nil)
|
||||
propertyGroupStore.On("Get", model.BoardsPropertyGroupName).Return(boardsGroup, nil)
|
||||
propertyGroupStore.On("Get", model.SessionAttributesPropertyGroupName).Return(sessionAttributesGroup, nil)
|
||||
|
||||
propertyFieldStore.On("SearchPropertyFields", mock.Anything).Return([]*model.PropertyField{}, nil)
|
||||
propertyFieldStore.On("CreatePropertyField", mock.Anything).Return(&model.PropertyField{}, nil)
|
||||
propertyFieldStore.On("Create", mock.AnythingOfType("*model.PropertyField")).Return(&model.PropertyField{}, nil)
|
||||
propertyFieldStore.On("CheckPropertyNameConflict", mock.AnythingOfType("*model.PropertyField"), mock.Anything).Return(model.PropertyFieldTargetLevel(""), nil)
|
||||
|
||||
managedCategoryField := &model.PropertyField{ID: model.NewId(), GroupID: managedCategoryGroup.ID, Name: model.ManagedCategoryPropertyFieldName}
|
||||
propertyFieldStore.On("GetFieldByName", mock.Anything, managedCategoryGroup.ID, "", model.ManagedCategoryPropertyFieldName).Return(managedCategoryField, nil)
|
||||
propertyFieldStore.On("GetFieldByNameForObjectType", mock.Anything, managedCategoryGroup.ID, "", model.PropertyValueTargetTypeChannel, model.ManagedCategoryPropertyFieldName).Return(managedCategoryField, nil)
|
||||
|
||||
boardField := &model.PropertyField{ID: model.NewId(), GroupID: boardsGroup.ID, Name: model.BoardsPropertyFieldNameBoard}
|
||||
propertyFieldStore.On("GetFieldByName", mock.Anything, boardsGroup.ID, "", model.BoardsPropertyFieldNameBoard).Return(boardField, nil)
|
||||
propertyFieldStore.On("GetFieldByName", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, store.NewErrNotFound("PropertyField", ""))
|
||||
propertyFieldStore.On("GetFieldByNameForObjectType", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, store.NewErrNotFound("PropertyField", ""))
|
||||
|
||||
viewStore := mocks.ViewStore{}
|
||||
mockStore.On("View").Return(&viewStore)
|
||||
|
||||
mockStore.On("System").Return(&systemStore)
|
||||
mockStore.On("User").Return(&userStore)
|
||||
mockStore.On("Post").Return(&postStore)
|
||||
mockStore.On("Status").Return(&statusStore)
|
||||
mockStore.On("Channel").Return(&channelStore)
|
||||
mockStore.On("Team").Return(&teamStore)
|
||||
mockStore.On("Role").Return(&roleStore)
|
||||
mockStore.On("Scheme").Return(&schemeStore)
|
||||
mockStore.On("Close").Return(nil)
|
||||
mockStore.On("DropAllTables").Return(nil)
|
||||
mockStore.On("MarkSystemRanUnitTests").Return(nil)
|
||||
mockStore.On("Session").Return(&sessionStore)
|
||||
mockStore.On("OAuth").Return(&oAuthStore)
|
||||
mockStore.On("Group").Return(&groupStore)
|
||||
mockStore.On("GetDBSchemaVersion").Return(1, nil)
|
||||
mockStore.On("Plugin").Return(&pluginStore)
|
||||
mockStore.On("PropertyGroup").Return(&propertyGroupStore)
|
||||
mockStore.On("PropertyField").Return(&propertyFieldStore)
|
||||
mockStore.On("PropertyValue").Return(&propertyValueStore)
|
||||
mockStore.On("ChannelGuard").Return(&channelGuardStore)
|
||||
mockStore.On("LockToMaster").Return()
|
||||
mockStore.On("UnlockFromMaster").Return()
|
||||
|
||||
return &mockStore
|
||||
}
|
||||
26
server/channels/testlib/testdata/boards_postgres_migration_warmup.sql
vendored
Normal file
26
server/channels/testlib/testdata/boards_postgres_migration_warmup.sql
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 10.20 (Debian 10.20-1.pgdg90+1)
|
||||
-- Dumped by pg_dump version 14.7
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
|
||||
--
|
||||
-- Data for Name: focalboard_system_settings; Type: TABLE DATA; Schema: public; Owner: mmuser
|
||||
--
|
||||
|
||||
INSERT INTO public.focalboard_system_settings VALUES ('UniqueIDsMigrationComplete', 'true');
|
||||
INSERT INTO public.focalboard_system_settings VALUES ('TeamLessBoardsMigrationComplete', 'true');
|
||||
INSERT INTO public.focalboard_system_settings VALUES ('DeletedMembershipBoardsMigrationComplete', 'true');
|
||||
INSERT INTO public.focalboard_system_settings VALUES ('CategoryUuidIdMigrationComplete', 'true');
|
||||
INSERT INTO public.focalboard_system_settings VALUES ('DeDuplicateCategoryBoardTableComplete', 'true');
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
88
server/channels/testlib/testdata/postgres_migration_warmup.sql
vendored
Normal file
88
server/channels/testlib/testdata/postgres_migration_warmup.sql
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user