[MM-61099] Fix errcheck issues in server/channels/app/brand.go (#30679)
* [MM-28779] Fix errcheck issues in server/channels/app/brand.go Remove brand.go from the errcheck exclusion list in .golangci.yml and fixed the error by properly handling the return value from a.MoveFile(). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * [MM-28779] Add test to verify brand image backup functionality Add a new test that verifies backup of the original brand image happens when a new one is uploaded. This helps to ensure the fix for errcheck issues is working as expected. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * use seperate temporary filestore for each test * Use FileSettings.Directory instead of finding the dir programatically * Fix another test * Fix defer * Update server/channels/api4/job_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix bad bot commit * Cleanup logs message * cleanup file path * Fix error variable names * WIP:cleanup panic ussage * Revert "WIP:cleanup panic ussage" This reverts commit c3284e4427a41c818acc161926cd2535dee9a6b9. * cleanup error checks --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1cb244e876
Коммит
6de3379994
@@ -69,6 +69,8 @@ type TestHelper struct {
|
||||
|
||||
LogBuffer *mlog.Buffer
|
||||
TestLogger *mlog.Logger
|
||||
|
||||
workspace string
|
||||
}
|
||||
|
||||
var mainHelper *testlib.MainHelper
|
||||
@@ -77,18 +79,14 @@ func SetMainHelper(mh *testlib.MainHelper) {
|
||||
mainHelper = mh
|
||||
}
|
||||
|
||||
func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, enterprise bool, includeCache bool,
|
||||
func setupTestHelper(tb testing.TB, dbStore store.Store, searchEngine *searchengine.Broker, enterprise bool, includeCache bool,
|
||||
updateConfig func(*model.Config), options []app.Option,
|
||||
) *TestHelper {
|
||||
tempWorkspace, err := os.MkdirTemp("", "apptest")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
require.NoError(tb, err)
|
||||
|
||||
memoryStore, err := config.NewMemoryStoreWithOptions(&config.MemoryStoreOptions{IgnoreEnvironmentOverrides: true})
|
||||
if err != nil {
|
||||
panic("failed to initialize memory store: " + err.Error())
|
||||
}
|
||||
require.NoError(tb, err, "failed to initialize memory store")
|
||||
|
||||
memoryConfig := &model.Config{
|
||||
SqlSettings: *mainHelper.GetSQLSettings(),
|
||||
@@ -96,7 +94,8 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
memoryConfig.SetDefaults()
|
||||
*memoryConfig.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins")
|
||||
*memoryConfig.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp")
|
||||
memoryConfig.ServiceSettings.EnableLocalMode = model.NewPointer(true)
|
||||
*memoryConfig.FileSettings.Directory = filepath.Join(tempWorkspace, "data")
|
||||
*memoryConfig.ServiceSettings.EnableLocalMode = true
|
||||
*memoryConfig.ServiceSettings.LocalModeSocketLocation = filepath.Join(tempWorkspace, "mattermost_local.sock")
|
||||
*memoryConfig.LogSettings.EnableSentry = false // disable error reporting during tests
|
||||
*memoryConfig.LogSettings.ConsoleLevel = mlog.LvlStdLog.Name
|
||||
@@ -122,9 +121,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
memoryStore.Set(memoryConfig)
|
||||
|
||||
configStore, err := config.NewStoreFromBacking(memoryStore, nil, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
require.NoError(tb, err)
|
||||
|
||||
options = append(options, app.ConfigStore(configStore))
|
||||
if includeCache {
|
||||
@@ -136,22 +133,20 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
|
||||
buffer := &mlog.Buffer{}
|
||||
|
||||
testLogger, _ := mlog.NewLogger()
|
||||
logCfg, _ := config.MloggerConfigFromLoggerConfig(&memoryConfig.LogSettings, nil, config.GetLogFileLocation)
|
||||
if errCfg := testLogger.ConfigureTargets(logCfg, nil); errCfg != nil {
|
||||
panic("failed to configure test logger: " + errCfg.Error())
|
||||
}
|
||||
if errW := mlog.AddWriterTarget(testLogger, buffer, true, mlog.StdAll...); errW != nil {
|
||||
panic("failed to add writer target to test logger: " + errW.Error())
|
||||
}
|
||||
testLogger, err := mlog.NewLogger()
|
||||
require.NoError(tb, err)
|
||||
logCfg, err := config.MloggerConfigFromLoggerConfig(&memoryConfig.LogSettings, nil, config.GetLogFileLocation)
|
||||
require.NoError(tb, err)
|
||||
err = testLogger.ConfigureTargets(logCfg, nil)
|
||||
require.NoError(tb, err, "failed to configure test logger")
|
||||
err = mlog.AddWriterTarget(testLogger, buffer, true, mlog.StdAll...)
|
||||
require.NoError(tb, err, "failed to add writer target to test logger")
|
||||
// lock logger config so server init cannot override it during testing.
|
||||
testLogger.LockConfiguration()
|
||||
options = append(options, app.SetLogger(testLogger))
|
||||
|
||||
s, err := app.NewServer(options...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
require.NoError(tb, err)
|
||||
|
||||
th := &TestHelper{
|
||||
App: app.New(app.ServerConnector(s.Channels())),
|
||||
@@ -161,6 +156,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
IncludeCacheLayer: includeCache,
|
||||
TestLogger: testLogger,
|
||||
LogBuffer: buffer,
|
||||
workspace: tempWorkspace,
|
||||
}
|
||||
|
||||
if s.Platform().SearchEngine != nil && s.Platform().SearchEngine.BleveEngine != nil && searchEngine != nil {
|
||||
@@ -194,11 +190,11 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
|
||||
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||
})
|
||||
if err := th.Server.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = th.Server.Start()
|
||||
require.NoError(tb, err)
|
||||
|
||||
Init(th.App.Srv())
|
||||
_, err = Init(th.App.Srv())
|
||||
require.NoError(tb, err)
|
||||
web.New(th.App.Srv())
|
||||
wsapi.Init(th.App.Srv())
|
||||
|
||||
@@ -249,8 +245,8 @@ func SetupEnterprise(tb testing.TB, options ...app.Option) *TestHelper {
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, true, true, nil, options)
|
||||
th.InitLogin()
|
||||
th := setupTestHelper(tb, dbStore, searchEngine, true, true, nil, options)
|
||||
th.InitLogin(tb)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -268,8 +264,8 @@ func Setup(tb testing.TB) *TestHelper {
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, false, true, nil, nil)
|
||||
th.InitLogin()
|
||||
th := setupTestHelper(tb, dbStore, searchEngine, false, true, nil, nil)
|
||||
th.InitLogin(tb)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -287,9 +283,9 @@ func SetupAndApplyConfigBeforeLogin(tb testing.TB, updateConfig func(cfg *model.
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, false, true, nil, nil)
|
||||
th := setupTestHelper(tb, dbStore, searchEngine, false, true, nil, nil)
|
||||
th.App.UpdateConfig(updateConfig)
|
||||
th.InitLogin()
|
||||
th.InitLogin(tb)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -307,13 +303,13 @@ func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelpe
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, false, true, updateConfig, nil)
|
||||
th.InitLogin()
|
||||
th := setupTestHelper(tb, dbStore, searchEngine, false, true, updateConfig, nil)
|
||||
th.InitLogin(tb)
|
||||
return th
|
||||
}
|
||||
|
||||
func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
|
||||
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), nil, false, false, updateConfig, nil)
|
||||
th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, false, false, updateConfig, nil)
|
||||
statusMock := mocks.StatusStore{}
|
||||
statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil)
|
||||
statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil)
|
||||
@@ -327,7 +323,7 @@ func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config
|
||||
}
|
||||
|
||||
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), nil, false, false, nil, nil)
|
||||
th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, false, false, nil, nil)
|
||||
statusMock := mocks.StatusStore{}
|
||||
statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil)
|
||||
statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil)
|
||||
@@ -341,7 +337,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||
}
|
||||
|
||||
func SetupEnterpriseWithStoreMock(tb testing.TB, options ...app.Option) *TestHelper {
|
||||
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), nil, true, false, nil, options)
|
||||
th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, true, false, nil, options)
|
||||
statusMock := mocks.StatusStore{}
|
||||
statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil)
|
||||
statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil)
|
||||
@@ -368,8 +364,8 @@ func SetupWithServerOptions(tb testing.TB, options []app.Option) *TestHelper {
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, false, true, nil, options)
|
||||
th.InitLogin()
|
||||
th := setupTestHelper(tb, dbStore, searchEngine, false, true, nil, options)
|
||||
th.InitLogin(tb)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -387,8 +383,8 @@ func SetupEnterpriseWithServerOptions(tb testing.TB, options []app.Option) *Test
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, true, true, nil, options)
|
||||
th.InitLogin()
|
||||
th := setupTestHelper(tb, dbStore, searchEngine, true, true, nil, options)
|
||||
th.InitLogin(tb)
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -413,7 +409,16 @@ func (th *TestHelper) TearDown() {
|
||||
// Clean all the caches
|
||||
th.App.Srv().InvalidateAllCaches()
|
||||
}
|
||||
|
||||
th.ShutdownApp()
|
||||
|
||||
// Cleanup the workspace
|
||||
if th.workspace != "" {
|
||||
err := os.RemoveAll(th.workspace)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func closeBody(r *http.Response) {
|
||||
@@ -434,8 +439,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func (th *TestHelper) InitLogin() *TestHelper {
|
||||
th.waitForConnectivity()
|
||||
func (th *TestHelper) InitLogin(tb testing.TB) *TestHelper {
|
||||
th.waitForConnectivity(tb)
|
||||
|
||||
// create users once and cache them because password hashing is slow
|
||||
initBasicOnce.Do(func() {
|
||||
@@ -527,7 +532,7 @@ func (th *TestHelper) DeleteBots() *TestHelper {
|
||||
return th
|
||||
}
|
||||
|
||||
func (th *TestHelper) waitForConnectivity() {
|
||||
func (th *TestHelper) waitForConnectivity(tb testing.TB) {
|
||||
for i := 0; i < 1000; i++ {
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", th.App.Srv().ListenAddr.Port))
|
||||
if err == nil {
|
||||
@@ -536,7 +541,7 @@ func (th *TestHelper) waitForConnectivity() {
|
||||
}
|
||||
time.Sleep(time.Millisecond * 20)
|
||||
}
|
||||
panic("unable to connect")
|
||||
tb.Fatal("unable to connect")
|
||||
}
|
||||
|
||||
func (th *TestHelper) CreateClient() *model.Client4 {
|
||||
|
||||
Ссылка в новой задаче
Block a user