Этот коммит содержится в:
Andy Librian
2020-01-20 18:32:20 +07:00
коммит произвёл Ben Schumacher
родитель 2186af4d13
Коммит 3865bc501e
15 изменённых файлов: 57 добавлений и 53 удалений

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

@@ -41,4 +41,4 @@ issues:
- linters:
# ignore golint error for a lot of packages for now
- golint
path: "api4|app|cmd|einterface|enterprise|imports|jobs|manualtesting|migrations|mlog|model|testlib|services|store|utils|web|wsapi|plugin/plugintest/api.go|plugin/api.go|plugin/context.go|plugin/client.go|plugin/client_rpc.go|plugin/client_rpc_generated.go|plugin/environment.go|plugin/health_check.go|plugin/hooks.go|plugin/supervisor.go|plugin/valid.go"
path: "api4|app|cmd|einterface|enterprise|imports|jobs|migrations|mlog|model|testlib|services|store|utils|web|wsapi|plugin/plugintest/api.go|plugin/api.go|plugin/context.go|plugin/client.go|plugin/client_rpc.go|plugin/client_rpc_generated.go|plugin/environment.go|plugin/health_check.go|plugin/hooks.go|plugin/supervisor.go|plugin/valid.go"

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

@@ -466,7 +466,7 @@ func (me *TestHelper) TearDown() {
}
func (me *TestHelper) ResetRoleMigration() {
sqlSupplier := mainHelper.GetSqlSupplier()
sqlSupplier := mainHelper.GetSQLSupplier()
if _, err := sqlSupplier.GetMaster().Exec("DELETE from Roles"); err != nil {
panic(err)
}
@@ -479,7 +479,7 @@ func (me *TestHelper) ResetRoleMigration() {
}
func (me *TestHelper) ResetEmojisMigration() {
sqlSupplier := mainHelper.GetSqlSupplier()
sqlSupplier := mainHelper.GetSQLSupplier()
if _, err := sqlSupplier.GetMaster().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' create_emojis', '') WHERE builtin=True"); err != nil {
panic(err)
}

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

@@ -675,7 +675,7 @@ func TestPermanentDeleteUser(t *testing.T) {
var bots1 []*model.Bot
var bots2 []*model.Bot
sqlSupplier := mainHelper.GetSqlSupplier()
sqlSupplier := mainHelper.GetSQLSupplier()
_, err1 := sqlSupplier.GetMaster().Select(&bots1, "SELECT * FROM Bots")
assert.Nil(t, err1)
assert.Equal(t, 1, len(bots1))

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

@@ -80,7 +80,7 @@ func (h *testHelper) ConfigPath() string {
// SetConfig replaces the configuration passed to a running command.
func (h *testHelper) SetConfig(config *model.Config) {
config.SqlSettings = *mainHelper.GetSqlSettings()
config.SqlSettings = *mainHelper.GetSQLSettings()
// Disable strict password requirements for test
*config.PasswordSettings.MinimumLength = 5

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

@@ -525,7 +525,7 @@ func TestConfigMigrate(t *testing.T) {
th := Setup()
defer th.TearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
sqlDSN := fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource)
fileDSN := "config.json"

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

@@ -27,7 +27,7 @@ func setupConfigDatabase(t *testing.T, cfg *model.Config, files map[string][]byt
cfgData, err := config.MarshalConfig(cfg)
require.NoError(t, err)
db := sqlx.NewDb(mainHelper.GetSqlSupplier().GetMaster().Db, *mainHelper.GetSqlSettings().DriverName)
db := sqlx.NewDb(mainHelper.GetSQLSupplier().GetMaster().Db, *mainHelper.GetSQLSettings().DriverName)
err = config.InitializeConfigurationsTable(db)
require.NoError(t, err)
@@ -64,7 +64,7 @@ func getActualDatabaseConfig(t *testing.T) (string, *model.Config) {
ID string `db:"Id"`
Value []byte `db:"Value"`
}
db := sqlx.NewDb(mainHelper.GetSqlSupplier().GetMaster().Db, *mainHelper.GetSqlSettings().DriverName)
db := sqlx.NewDb(mainHelper.GetSQLSupplier().GetMaster().Db, *mainHelper.GetSQLSettings().DriverName)
err := db.Get(&actual, "SELECT Id, Value FROM Configurations WHERE Active")
require.NoError(t, err)
@@ -93,7 +93,7 @@ func assertDatabaseNotEqualsConfig(t *testing.T, expectedCfg *model.Config) {
}
func TestDatabaseStoreNew(t *testing.T) {
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
t.Run("no existing configuration - initialization required", func(t *testing.T) {
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
@@ -147,7 +147,7 @@ func TestDatabaseStoreGet(t *testing.T) {
_, tearDown := setupConfigDatabase(t, testConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
defer ds.Close()
@@ -173,7 +173,7 @@ func TestDatabaseStoreGetEnivironmentOverrides(t *testing.T) {
_, tearDown := setupConfigDatabase(t, testConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
defer ds.Close()
@@ -196,7 +196,7 @@ func TestDatabaseStoreGetEnivironmentOverrides(t *testing.T) {
_, tearDown := setupConfigDatabase(t, testConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
defer ds.Close()
@@ -219,7 +219,7 @@ func TestDatabaseStoreGetEnivironmentOverrides(t *testing.T) {
_, tearDown := setupConfigDatabase(t, testConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
defer ds.Close()
@@ -242,7 +242,7 @@ func TestDatabaseStoreGetEnivironmentOverrides(t *testing.T) {
_, tearDown := setupConfigDatabase(t, testConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
defer ds.Close()
@@ -265,7 +265,7 @@ func TestDatabaseStoreGetEnivironmentOverrides(t *testing.T) {
_, tearDown := setupConfigDatabase(t, testConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
defer ds.Close()
@@ -291,7 +291,7 @@ func TestDatabaseStoreGetEnivironmentOverrides(t *testing.T) {
_, tearDown := setupConfigDatabase(t, testConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
defer ds.Close()
@@ -312,7 +312,7 @@ func TestDatabaseStoreGetEnivironmentOverrides(t *testing.T) {
}
func TestDatabaseStoreSet(t *testing.T) {
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
t.Run("set same pointer value", func(t *testing.T) {
t.Skip("not yet implemented")
@@ -458,7 +458,7 @@ func TestDatabaseStoreSet(t *testing.T) {
require.NoError(t, err)
defer ds.Close()
db := sqlx.NewDb(mainHelper.GetSqlSupplier().GetMaster().Db, *sqlSettings.DriverName)
db := sqlx.NewDb(mainHelper.GetSQLSupplier().GetMaster().Db, *sqlSettings.DriverName)
_, err = db.Exec("DROP TABLE Configurations")
require.NoError(t, err)
@@ -518,7 +518,7 @@ func TestDatabaseStoreSet(t *testing.T) {
}
func TestDatabaseStoreLoad(t *testing.T) {
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
t.Run("active configuration no longer exists", func(t *testing.T) {
_, tearDown := setupConfigDatabase(t, emptyConfig, nil)
@@ -703,7 +703,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
cfgData, err := config.MarshalConfig(invalidConfig)
require.NoError(t, err)
db := sqlx.NewDb(mainHelper.GetSqlSupplier().GetMaster().Db, *sqlSettings.DriverName)
db := sqlx.NewDb(mainHelper.GetSQLSupplier().GetMaster().Db, *sqlSettings.DriverName)
truncateTables(t)
id := model.NewId()
_, err = db.NamedExec("INSERT INTO Configurations (Id, Value, CreateAt, Active) VALUES(:Id, :Value, :CreateAt, TRUE)", map[string]interface{}{
@@ -954,7 +954,7 @@ func TestDatabaseStoreString(t *testing.T) {
_, tearDown := setupConfigDatabase(t, emptyConfig, nil)
defer tearDown()
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
require.NoError(t, err)
require.NotNil(t, ds)

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

@@ -29,8 +29,8 @@ func TestMain(m *testing.M) {
// truncateTable clears the given table
func truncateTable(t *testing.T, table string) {
t.Helper()
sqlSetting := mainHelper.GetSqlSettings()
sqlSupplier := mainHelper.GetSqlSupplier()
sqlSetting := mainHelper.GetSQLSettings()
sqlSupplier := mainHelper.GetSQLSupplier()
switch *sqlSetting.DriverName {
case model.DATABASE_DRIVER_MYSQL:

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

@@ -15,7 +15,7 @@ import (
func TestMigrateDatabaseToFile(t *testing.T) {
helper := testlib.NewMainHelper()
sqlSettings := helper.GetSqlSettings()
sqlSettings := helper.GetSQLSettings()
defer storetest.CleanupSqlSettings(sqlSettings)
sqlDSN := fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource)
fileDSN := "config.json"
@@ -54,7 +54,7 @@ func TestMigrateDatabaseToFile(t *testing.T) {
func TestMigrateFileToDatabaseWhenFilePathIsNotSpecified(t *testing.T) {
helper := testlib.NewMainHelper()
sqlSettings := helper.GetSqlSettings()
sqlSettings := helper.GetSQLSettings()
defer storetest.CleanupSqlSettings(sqlSettings)
sqlDSN := fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource)
fileDSN := "config.json"

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

@@ -15,7 +15,7 @@ import (
)
func TestNewStore(t *testing.T) {
sqlSettings := mainHelper.GetSqlSettings()
sqlSettings := mainHelper.GetSQLSettings()
tempDir, err := ioutil.TempDir("", "TestNewStore")
require.NoError(t, err)

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

@@ -3,9 +3,10 @@
package imports
// This is a placeholder so this package can be imported in Team Edition when it will be otherwise empty
import (
// This is a placeholder so this package can be imported in Team Edition when it will be otherwise empty.
_ "github.com/mattermost/mattermost-server/v5/migrations"
// This is a placeholder so this package can be imported in Team Edition when it will be otherwise empty.
_ "github.com/mattermost/mattermost-server/v5/plugin/scheduler"
)

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

@@ -19,16 +19,18 @@ import (
"github.com/mattermost/mattermost-server/v5/web"
)
// TestEnvironment is a helper struct used for tests in manualtesting.
type TestEnvironment struct {
Params map[string][]string
Client *model.Client4
CreatedTeamId string
CreatedUserId string
CreatedTeamID string
CreatedUserID string
Context *web.Context
Writer http.ResponseWriter
Request *http.Request
}
// Init adds manualtest endpoint to the API.
func Init(api4 *api4.API) {
api4.BaseRoutes.Root.Handle("/manualtest", api4.ApiHandler(manualTest)).Methods("GET")
}
@@ -73,19 +75,20 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
Type: model.TEAM_OPEN,
}
if createdTeam, err := c.App.Srv.Store.Team().Save(team); err != nil {
createdTeam, err := c.App.Srv.Store.Team().Save(team)
if err != nil {
c.Err = err
return
} else {
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: createdTeam.Id}
if _, err := c.App.CreateChannel(channel, false); err != nil {
c.Err = err
return
}
teamID = createdTeam.Id
}
channel := &model.Channel{DisplayName: "Town Square", Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: createdTeam.Id}
if _, err := c.App.CreateChannel(channel, false); err != nil {
c.Err = err
return
}
teamID = createdTeam.Id
// Create user for testing
user := &model.User{
Email: "success+" + model.NewId() + "simulator.amazonses.com",
@@ -126,8 +129,8 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
env := TestEnvironment{
Params: params,
Client: client,
CreatedTeamId: teamID,
CreatedUserId: userID,
CreatedTeamID: teamID,
CreatedUserID: userID,
Context: c,
Writer: w,
Request: r,

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

@@ -10,7 +10,7 @@ import (
"github.com/mattermost/mattermost-server/v5/model"
)
const LINK_POST_TEXT = `
const linkPostText = `
Some Links:
https://spinpunch.atlassian.net/issues/?filter=10101&jql=resolution%20in%20(Fixed%2C%20%22Won't%20Fix%22%2C%20Duplicate%2C%20%22Cannot%20Reproduce%22)%20AND%20Resolution%20%3D%20Fixed%20AND%20updated%20%3E%3D%20-7d%20ORDER%20BY%20updatedDate%20DESC
@@ -23,14 +23,14 @@ https://medium.com/@slackhq/11-useful-tips-for-getting-the-most-of-slack-5dfb3d1
func testAutoLink(env TestEnvironment) *model.AppError {
mlog.Info("Manual Auto Link Test")
channelID, err := getChannelID(env.Context.App, model.DEFAULT_CHANNEL, env.CreatedTeamId, env.CreatedUserId)
channelID, err := getChannelID(env.Context.App, model.DEFAULT_CHANNEL, env.CreatedTeamID, env.CreatedUserID)
if !err {
return model.NewAppError("/manualtest", "manaultesting.test_autolink.unable.app_error", nil, "", http.StatusInternalServerError)
}
post := &model.Post{
ChannelId: channelID,
Message: LINK_POST_TEXT}
Message: linkPostText}
_, resp := env.Client.CreatePost(post)
return resp.Error
}

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

@@ -254,7 +254,7 @@ func (me *TestHelper) TearDown() {
}
func (me *TestHelper) ResetRoleMigration() {
sqlSupplier := mainHelper.GetSqlSupplier()
sqlSupplier := mainHelper.GetSQLSupplier()
if _, err := sqlSupplier.GetMaster().Exec("DELETE from Roles"); err != nil {
panic(err)
}

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

@@ -1,5 +1,5 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// testlib exposes helper methods for running unit tests against a containerized test store.
// Package testlib exposes helper methods for running unit tests against a containerized test store.
package testlib

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

@@ -21,7 +21,7 @@ import (
type MainHelper struct {
Settings *model.SqlSettings
Store store.Store
SqlSupplier *sqlstore.SqlSupplier
SQLSupplier *sqlstore.SqlSupplier
ClusterInterface *FakeClusterInterface
status int
@@ -101,9 +101,9 @@ func (h *MainHelper) setupStore() {
h.Settings = storetest.MakeSqlSettings(driverName)
h.ClusterInterface = &FakeClusterInterface{}
h.SqlSupplier = sqlstore.NewSqlSupplier(*h.Settings, nil)
h.SQLSupplier = sqlstore.NewSqlSupplier(*h.Settings, nil)
h.Store = &TestStore{
h.SqlSupplier,
h.SQLSupplier,
}
}
@@ -132,7 +132,7 @@ func (h *MainHelper) Close() error {
return nil
}
func (h *MainHelper) GetSqlSettings() *model.SqlSettings {
func (h *MainHelper) GetSQLSettings() *model.SqlSettings {
if h.Settings == nil {
panic("MainHelper not initialized with database access.")
}
@@ -148,12 +148,12 @@ func (h *MainHelper) GetStore() store.Store {
return h.Store
}
func (h *MainHelper) GetSqlSupplier() *sqlstore.SqlSupplier {
if h.SqlSupplier == nil {
func (h *MainHelper) GetSQLSupplier() *sqlstore.SqlSupplier {
if h.SQLSupplier == nil {
panic("MainHelper not initialized with sql supplier.")
}
return h.SqlSupplier
return h.SQLSupplier
}
func (h *MainHelper) GetClusterInterface() *FakeClusterInterface {