Skip to content

Commit

Permalink
[MM-61071] Fix errcheck issues in channels/app/admin.go (mattermost#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Oct 31, 2024
1 parent 9fee53f commit 2d2c039
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
1 change: 0 additions & 1 deletion server/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ issues:
channels/api4/team_test.go|\
channels/api4/user_test.go|\
channels/api4/webhook_test.go|\
channels/app/admin.go|\
channels/app/app_test.go|\
channels/app/authorization_test.go|\
channels/app/auto_responder_test.go|\
Expand Down
12 changes: 8 additions & 4 deletions server/channels/app/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ func (s *Server) QueryLogs(rctx request.CTX, page, perPage int, logFilter *model
}
}

var appErr *model.AppError
serverNames := logFilter.ServerNames
if len(serverNames) > 0 {
for _, nodeName := range serverNames {
if nodeName == "default" {
AddLocalLogs(rctx, logData, s, page, perPage, nodeName, logFilter)
appErr = AddLocalLogs(rctx, logData, s, page, perPage, nodeName, logFilter)
}
}
} else {
AddLocalLogs(rctx, logData, s, page, perPage, serverName, logFilter)
appErr = AddLocalLogs(rctx, logData, s, page, perPage, serverName, logFilter)
}
if appErr != nil {
return nil, appErr
}

if s.platform.Cluster() != nil && *s.Config().ClusterSettings.Enable {
Expand Down Expand Up @@ -237,6 +241,6 @@ func (a *App) GetLatestVersion(rctx request.CTX, latestVersionUrl string) (*mode
return releaseInfoResponse, nil
}

func (a *App) ClearLatestVersionCache(rctx request.CTX) {
latestVersionCache.Remove("latest_version_cache")
func (a *App) clearLatestVersionCache() error {
return latestVersionCache.Remove("latest_version_cache")
}
15 changes: 9 additions & 6 deletions server/channels/app/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func TestGetLatestVersion(t *testing.T) {
})

t.Run("get latest mm version from cache", func(t *testing.T) {
th.App.ClearLatestVersionCache(th.Context)
originalResult, err := th.App.GetLatestVersion(th.Context, ts.URL)
require.Nil(t, err)
err := th.App.clearLatestVersionCache()
require.NoError(t, err)
originalResult, appErr := th.App.GetLatestVersion(th.Context, ts.URL)
require.Nil(t, appErr)

// Call same function but mock the GET request to return a different result.
// We are hoping the function will use the cache instead of making the GET request
Expand All @@ -68,14 +69,16 @@ func TestGetLatestVersion(t *testing.T) {
}))
defer ts.Close()

cachedResult, err := th.App.GetLatestVersion(th.Context, updatedServer.URL)
require.Nil(t, err)
cachedResult, appErr := th.App.GetLatestVersion(th.Context, updatedServer.URL)
require.Nil(t, appErr)

require.Equal(t, originalResult.TagName, cachedResult.TagName, "did not get cached result")
})

t.Run("get latest mm version error from external", func(t *testing.T) {
th.App.ClearLatestVersionCache(th.Context)
err := th.App.clearLatestVersionCache()
require.NoError(t, err)

errorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
_, err := w.Write([]byte(`
Expand Down
1 change: 0 additions & 1 deletion server/channels/app/app_iface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions server/channels/app/opentracing/opentracing_layer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d2c039

Please sign in to comment.