diff --git a/.golangci.yml b/.golangci.yml index 809c31990d..0c710bdcf3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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" diff --git a/app/helper_test.go b/app/helper_test.go index 53435da6d6..a72627435a 100644 --- a/app/helper_test.go +++ b/app/helper_test.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) } diff --git a/app/user_test.go b/app/user_test.go index fe444ae411..e8a1236315 100644 --- a/app/user_test.go +++ b/app/user_test.go @@ -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)) diff --git a/cmd/mattermost/commands/cmdtestlib.go b/cmd/mattermost/commands/cmdtestlib.go index e1611a10f0..cc2f4f3bbd 100644 --- a/cmd/mattermost/commands/cmdtestlib.go +++ b/cmd/mattermost/commands/cmdtestlib.go @@ -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 diff --git a/cmd/mattermost/commands/config_test.go b/cmd/mattermost/commands/config_test.go index 8260a9c2eb..3806e3251e 100644 --- a/cmd/mattermost/commands/config_test.go +++ b/cmd/mattermost/commands/config_test.go @@ -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" diff --git a/config/database_test.go b/config/database_test.go index bb8e38817b..472efcc394 100644 --- a/config/database_test.go +++ b/config/database_test.go @@ -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) diff --git a/config/main_test.go b/config/main_test.go index 21701ba559..e72bee7f5d 100644 --- a/config/main_test.go +++ b/config/main_test.go @@ -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: diff --git a/config/migrate_test.go b/config/migrate_test.go index 2a934ec280..6568b0d7c5 100644 --- a/config/migrate_test.go +++ b/config/migrate_test.go @@ -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" diff --git a/config/store_test.go b/config/store_test.go index b806826f33..0e5531b425 100644 --- a/config/store_test.go +++ b/config/store_test.go @@ -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) diff --git a/imports/placeholder.go b/imports/placeholder.go index 1e5dc76c24..f8b860aa19 100644 --- a/imports/placeholder.go +++ b/imports/placeholder.go @@ -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" ) diff --git a/manualtesting/manual_testing.go b/manualtesting/manual_testing.go index f985a6cbac..02d75a840c 100644 --- a/manualtesting/manual_testing.go +++ b/manualtesting/manual_testing.go @@ -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, diff --git a/manualtesting/test_autolink.go b/manualtesting/test_autolink.go index a1d7c30921..df218aa2cc 100644 --- a/manualtesting/test_autolink.go +++ b/manualtesting/test_autolink.go @@ -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 } diff --git a/migrations/helper_test.go b/migrations/helper_test.go index 7740dbbc69..71ed284b88 100644 --- a/migrations/helper_test.go +++ b/migrations/helper_test.go @@ -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) } diff --git a/testlib/doc.go b/testlib/doc.go index f15f018647..177f1ed567 100644 --- a/testlib/doc.go +++ b/testlib/doc.go @@ -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 diff --git a/testlib/helper.go b/testlib/helper.go index bd486b1b9a..b2bbbf4cb0 100644 --- a/testlib/helper.go +++ b/testlib/helper.go @@ -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 {