MM-11262: database config store (#10281)

* vendor github.com/jmoiron/sqlx

* MM-11262: introduce a database store

* revert unnecessary fmt.Errorf

* simplify unit test helper methods

* remote TODO re: retry

* relocate initializeConfigurationsTable for clarity

* factor out a commonStore

* acquire database config lock on close for safety

* add missing header

* fix lock comment
Этот коммит содержится в:
Jesse Hallam
2019-02-15 10:05:29 -04:00
коммит произвёл GitHub
родитель 898a3a289c
Коммит 9bf5687311
33 изменённых файлов: 3872 добавлений и 171 удалений

Просмотреть файл

@@ -1,17 +1,45 @@
package config
package config_test
import (
"io"
"testing"
"github.com/go-sql-driver/mysql"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/testlib"
"github.com/stretchr/testify/require"
)
// MarshalConfig exposes the internal marshalConfig to tests only.
func MarshalConfig(cfg *model.Config) ([]byte, error) {
return marshalConfig(cfg)
var mainHelper *testlib.MainHelper
func TestMain(m *testing.M) {
mainHelper = testlib.NewMainHelper()
defer mainHelper.Close()
mainHelper.Main(m)
}
// UnmarshalConfig exposes the internal unmarshalConfig to tests only.
func UnmarshalConfig(r io.Reader, allowEnvironmentOverrides bool) (*model.Config, map[string]interface{}, error) {
return unmarshalConfig(r, allowEnvironmentOverrides)
// truncateTables clears tables used by the config package for reuse in other tests
func truncateTables(t *testing.T) {
t.Helper()
switch *mainHelper.Settings.DriverName {
case model.DATABASE_DRIVER_MYSQL:
_, err := mainHelper.SqlSupplier.GetMaster().Db.Exec("TRUNCATE TABLE Configurations")
if err != nil {
if driverErr, ok := err.(*mysql.MySQLError); ok {
// Ignore if the Configurations table does not exist.
if driverErr.Number == 1146 {
return
}
}
}
require.NoError(t, err)
case model.DATABASE_DRIVER_POSTGRES:
_, err := mainHelper.SqlSupplier.GetMaster().Db.Exec("TRUNCATE TABLE Configurations")
require.NoError(t, err)
default:
t.Fatalf("unsupported driver name: %s", *mainHelper.Settings.DriverName)
}
}