mattermost-community-enterp.../channels/app/plugin_api_tests/test_db_driver/main.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

70 lines
2.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package main_test
import (
"database/sql"
"testing"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin"
"github.com/mattermost/mattermost/server/public/shared/driver"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app/plugin_api_tests"
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
)
type MyPlugin struct {
plugin.MattermostPlugin
config plugin_api_tests.BasicConfig
t *testing.T
}
func (p *MyPlugin) OnConfigurationChange() error {
if err := p.API.LoadPluginConfiguration(&p.config); err != nil {
return err
}
return nil
}
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
rctx := request.TestContext(p.t)
settings := p.API.GetUnsanitizedConfig().SqlSettings
settings.Trace = model.NewPointer(false)
store, err := sqlstore.New(settings, rctx.Logger(), nil, sqlstore.DisableMorphLogging())
if err != nil {
panic(err)
}
store.GetMaster().Close()
for _, isMaster := range []bool{true, false} {
handle := sql.OpenDB(driver.NewConnector(p.Driver, isMaster))
store.SetMasterX(handle)
wrapper := sqlstore.NewStoreTestWrapper(store)
// Testing with a handful of stores
storetest.TestPostStore(p.t, rctx, store, wrapper)
storetest.TestUserStore(p.t, rctx, store, wrapper)
storetest.TestTeamStore(p.t, rctx, store)
storetest.TestChannelStore(p.t, rctx, store, wrapper)
storetest.TestBotStore(p.t, rctx, store, wrapper)
store.GetMaster().Close()
}
// Use the API to instantiate the driver
// And then run the full suite of tests.
return nil, "OK"
}
// TestDBAPI is a test function which actually runs a plugin. The objective
// is to run the storetest suite from inside a plugin.
//
// The test runner compiles the test code to a binary, and runs it as a normal
// binary. But under the hood, a test runs.
func TestDBAPI(t *testing.T) {
plugin.ClientMain(&MyPlugin{t: t})
}