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:
175
server/channels/store/storetest/settings.go
Normal file
175
server/channels/store/storetest/settings.go
Normal file
@@ -0,0 +1,175 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultPostgresqlDSN = "postgres://mmuser:mostest_password@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10"
|
||||
)
|
||||
|
||||
func getDefaultPostgresqlDSN() string {
|
||||
if os.Getenv("IS_CI") == "true" {
|
||||
return strings.ReplaceAll(defaultPostgresqlDSN, "localhost", "postgres")
|
||||
}
|
||||
return defaultPostgresqlDSN
|
||||
}
|
||||
|
||||
// PostgresSQLSettings returns the database settings to connect to the PostgreSQL unittesting database.
|
||||
// The database name is generated randomly and must be created before use.
|
||||
func PostgreSQLSettings() *model.SqlSettings {
|
||||
dsn := os.Getenv("TEST_DATABASE_POSTGRESQL_DSN")
|
||||
if dsn == "" {
|
||||
dsn = getDefaultPostgresqlDSN()
|
||||
} else {
|
||||
mlog.Info("Using TEST_DATABASE_POSTGRESQL_DSN override", mlog.String("dsn", dsn))
|
||||
}
|
||||
|
||||
dsnURL, err := url.Parse(dsn)
|
||||
if err != nil {
|
||||
panic("failed to parse dsn " + dsn + ": " + err.Error())
|
||||
}
|
||||
|
||||
// Generate a random database name
|
||||
dsnURL.Path = "db" + model.NewId()
|
||||
|
||||
return databaseSettings("postgres", dsnURL.String())
|
||||
}
|
||||
|
||||
func postgreSQLRootDSN(dsn string) string {
|
||||
dsnURL, err := url.Parse(dsn)
|
||||
if err != nil {
|
||||
panic("failed to parse dsn " + dsn + ": " + err.Error())
|
||||
}
|
||||
|
||||
// // Assume the unittesting database has the same password.
|
||||
// password := ""
|
||||
// if dsnUrl.User != nil {
|
||||
// password, _ = dsnUrl.User.Password()
|
||||
// }
|
||||
|
||||
// dsnUrl.User = url.UserPassword("", password)
|
||||
dsnURL.Path = "postgres"
|
||||
|
||||
return dsnURL.String()
|
||||
}
|
||||
|
||||
func postgreSQLDSNDatabase(dsn string) string {
|
||||
dsnURL, err := url.Parse(dsn)
|
||||
if err != nil {
|
||||
panic("failed to parse dsn " + dsn + ": " + err.Error())
|
||||
}
|
||||
|
||||
return path.Base(dsnURL.Path)
|
||||
}
|
||||
|
||||
func databaseSettings(driver, dataSource string) *model.SqlSettings {
|
||||
settings := &model.SqlSettings{
|
||||
DriverName: &driver,
|
||||
DataSource: &dataSource,
|
||||
DataSourceReplicas: []string{},
|
||||
DataSourceSearchReplicas: []string{},
|
||||
MaxIdleConns: new(int),
|
||||
ConnMaxLifetimeMilliseconds: new(int),
|
||||
ConnMaxIdleTimeMilliseconds: new(int),
|
||||
MaxOpenConns: new(int),
|
||||
Trace: new(false),
|
||||
QueryTimeout: new(int),
|
||||
AnalyticsQueryTimeout: new(int),
|
||||
MigrationsStatementTimeoutSeconds: new(int),
|
||||
}
|
||||
*settings.MaxIdleConns = 10
|
||||
*settings.ConnMaxLifetimeMilliseconds = 3600000
|
||||
*settings.ConnMaxIdleTimeMilliseconds = 300000
|
||||
*settings.MaxOpenConns = 100
|
||||
*settings.QueryTimeout = 60
|
||||
*settings.AnalyticsQueryTimeout = 300
|
||||
*settings.MigrationsStatementTimeoutSeconds = 60
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
// execAsRoot executes the given sql as root against the testing database
|
||||
func execAsRoot(settings *model.SqlSettings, sqlCommand string) error {
|
||||
var dsn string
|
||||
driver := *settings.DriverName
|
||||
|
||||
switch driver {
|
||||
case model.DatabaseDriverPostgres:
|
||||
dsn = postgreSQLRootDSN(*settings.DataSource)
|
||||
default:
|
||||
return fmt.Errorf("unsupported driver %s", driver)
|
||||
}
|
||||
|
||||
db, err := sql.Open(driver, dsn)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to connect to %s database as root", driver)
|
||||
}
|
||||
defer db.Close()
|
||||
if _, err = db.Exec(sqlCommand); err != nil {
|
||||
return errors.Wrapf(err, "failed to execute `%s` against %s database as root", sqlCommand, driver)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MakeSqlSettings creates a randomly named database and returns the corresponding sql settings
|
||||
func MakeSqlSettings(driver string) *model.SqlSettings {
|
||||
var settings *model.SqlSettings
|
||||
var dbName string
|
||||
|
||||
switch driver {
|
||||
case model.DatabaseDriverPostgres:
|
||||
settings = PostgreSQLSettings()
|
||||
dbName = postgreSQLDSNDatabase(*settings.DataSource)
|
||||
default:
|
||||
panic("unsupported driver " + driver)
|
||||
}
|
||||
|
||||
if err := execAsRoot(settings, "CREATE DATABASE "+dbName); err != nil {
|
||||
panic("failed to create temporary database " + dbName + ": " + err.Error())
|
||||
}
|
||||
|
||||
switch driver {
|
||||
case model.DatabaseDriverPostgres:
|
||||
if err := execAsRoot(settings, "GRANT ALL PRIVILEGES ON DATABASE \""+dbName+"\" TO mmuser"); err != nil {
|
||||
panic("failed to grant mmuser permission to " + dbName + ":" + err.Error())
|
||||
}
|
||||
default:
|
||||
panic("unsupported driver " + driver)
|
||||
}
|
||||
|
||||
settings.ReplicaMonitorIntervalSeconds = new(5)
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
func CleanupSqlSettings(settings *model.SqlSettings) {
|
||||
driver := *settings.DriverName
|
||||
var dbName string
|
||||
|
||||
switch driver {
|
||||
case model.DatabaseDriverPostgres:
|
||||
dbName = postgreSQLDSNDatabase(*settings.DataSource)
|
||||
default:
|
||||
panic("unsupported driver " + driver)
|
||||
}
|
||||
|
||||
if err := execAsRoot(settings, "DROP DATABASE "+dbName); err != nil {
|
||||
mlog.Warn("failed to drop temporary database", mlog.String("database", dbName), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user