Skip to content

Commit

Permalink
Keep setting MM_SQLSETTINGS_DATASOURCE, but unset for tests
Browse files Browse the repository at this point in the history
Boards requires something to connect to when starting up, even for tests that mock the store. So keep setting this, but unset as necessary when pointing at a generated database.
  • Loading branch information
lieut-data committed Mar 15, 2023
1 parent affc64d commit 724ad8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
--ulimit nofile=8096:8096 \
--env-file=dotenv/test.env \
--env MM_SQLSETTINGS_DRIVERNAME="${{ inputs.drivername }}" \
--env MM_SQLSETTINGS_DATASOURCE="${{ inputs.datasource }}" \
--env TEST_DATABASE_MYSQL_DSN="${{ inputs.datasource }}" \
--env TEST_DATABASE_POSTGRESQL_DSN="${{ inputs.datasource }}" \
-v ~/work/mattermost-server:/mattermost-server \
Expand Down
15 changes: 15 additions & 0 deletions server/channels/store/storetest/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ func MySQLSettings(withReplica bool) *model.SqlSettings {
if dsn == "" {
dsn = defaultMysqlDSN
mlog.Info("No TEST_DATABASE_MYSQL_DSN override, using default", mlog.String("default_dsn", dsn))
} else {
mlog.Info("Using TEST_DATABASE_MYSQL_DSN override", mlog.String("dsn", dsn))
}

if os.Getenv("MM_SQLSETTINGS_DATASOURCE") != "" {
os.Unsetenv("MM_SQLSETTINGS_DATASOURCE")
mlog.Info("Clearing MM_SQLSETTINGS_DATASOURCE to use test dsn exclusively")
}

cfg, err := mysql.ParseDSN(dsn)
if err != nil {
panic("failed to parse dsn " + dsn + ": " + err.Error())
Expand All @@ -79,6 +87,13 @@ func PostgreSQLSettings() *model.SqlSettings {
if dsn == "" {
dsn = defaultPostgresqlDSN
mlog.Info("No TEST_DATABASE_POSTGRESQL_DSN override, using default", mlog.String("default_dsn", dsn))
} else {
mlog.Info("Using TEST_DATABASE_POSTGRESQL_DSN override", mlog.String("dsn", dsn))
}

if os.Getenv("MM_SQLSETTINGS_DATASOURCE") != "" {
os.Unsetenv("MM_SQLSETTINGS_DATASOURCE")
mlog.Info("Clearing MM_SQLSETTINGS_DATASOURCE to use test dsn exclusively")
}

dsnURL, err := url.Parse(dsn)
Expand Down

0 comments on commit 724ad8e

Please sign in to comment.