MM-25075: local mode for getLogs (#14760)

Этот коммит содержится в:
Ashish Bhate
2020-06-12 15:02:57 +05:30
коммит произвёл GitHub
родитель c58c0ba3dc
Коммит 8de5dd9022
3 изменённых файлов: 26 добавлений и 16 удалений

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

@@ -316,6 +316,7 @@ func InitLocal(configservice configservice.ConfigService, globalOptionsFunc app.
api.InitLicenseLocal() api.InitLicenseLocal()
api.InitBotLocal() api.InitBotLocal()
api.InitGroupLocal() api.InitGroupLocal()
api.InitSystemLocal()
api.InitPostLocal() api.InitPostLocal()
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404)) root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))

8
api4/system_local.go Обычный файл
Просмотреть файл

@@ -0,0 +1,8 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
func (api *API) InitSystemLocal() {
api.BaseRoutes.ApiRoot.Handle("/logs", api.ApiLocal(getLogs)).Methods("GET")
}

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

@@ -240,13 +240,13 @@ func TestInvalidateCaches(t *testing.T) {
func TestGetLogs(t *testing.T) { func TestGetLogs(t *testing.T) {
th := Setup(t).InitBasic() th := Setup(t).InitBasic()
defer th.TearDown() defer th.TearDown()
Client := th.Client
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
mlog.Info(strconv.Itoa(i)) mlog.Info(strconv.Itoa(i))
} }
logs, resp := th.SystemAdminClient.GetLogs(0, 10) th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
logs, resp := c.GetLogs(0, 10)
CheckNoError(t, resp) CheckNoError(t, resp)
require.Len(t, logs, 10) require.Len(t, logs, 10)
@@ -254,19 +254,20 @@ func TestGetLogs(t *testing.T) {
assert.Containsf(t, logs[i-10], fmt.Sprintf(`"msg":"%d"`, i), "Log line doesn't contain correct message") assert.Containsf(t, logs[i-10], fmt.Sprintf(`"msg":"%d"`, i), "Log line doesn't contain correct message")
} }
logs, resp = th.SystemAdminClient.GetLogs(1, 10) logs, resp = c.GetLogs(1, 10)
CheckNoError(t, resp) CheckNoError(t, resp)
require.Len(t, logs, 10) require.Len(t, logs, 10)
logs, resp = th.SystemAdminClient.GetLogs(-1, -1) logs, resp = c.GetLogs(-1, -1)
CheckNoError(t, resp) CheckNoError(t, resp)
require.NotEmpty(t, logs, "should not be empty") require.NotEmpty(t, logs, "should not be empty")
})
_, resp = Client.GetLogs(0, 10) _, resp := th.Client.GetLogs(0, 10)
CheckForbiddenStatus(t, resp) CheckForbiddenStatus(t, resp)
Client.Logout() th.Client.Logout()
_, resp = Client.GetLogs(0, 10) _, resp = th.Client.GetLogs(0, 10)
CheckUnauthorizedStatus(t, resp) CheckUnauthorizedStatus(t, resp)
} }