MM-25075: local mode for getLogs (#14760)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c58c0ba3dc
Коммит
8de5dd9022
@@ -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
Обычный файл
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,33 +240,34 @@ 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) {
|
||||||
CheckNoError(t, resp)
|
logs, resp := c.GetLogs(0, 10)
|
||||||
require.Len(t, logs, 10)
|
CheckNoError(t, resp)
|
||||||
|
require.Len(t, logs, 10)
|
||||||
|
|
||||||
for i := 10; i < 20; i++ {
|
for i := 10; i < 20; i++ {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user