[MM-54434] Use job.Logger to capture ldap logs (#24493)

Этот коммит содержится в:
Ben Schumacher
2023-10-06 22:43:21 +02:00
коммит произвёл GitHub
родитель afaf41b587
Коммит aad25be4e1
50 изменённых файлов: 385 добавлений и 426 удалений

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

@@ -13,7 +13,6 @@ import (
"gopkg.in/yaml.v2"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
fmocks "github.com/mattermost/mattermost/server/v8/platform/shared/filestore/mocks"
)
@@ -21,10 +20,9 @@ import (
func TestCreatePluginsFile(t *testing.T) {
th := Setup(t)
defer th.TearDown()
ctx := request.EmptyContext(th.TestLogger)
// Happy path where we have a plugins file with no err
fileData, err := th.App.createPluginsFile(ctx)
fileData, err := th.App.createPluginsFile(th.Context)
require.NotNil(t, fileData)
assert.Equal(t, "plugins.json", fileData.Filename)
assert.Positive(t, len(fileData.Body))
@@ -36,7 +34,7 @@ func TestCreatePluginsFile(t *testing.T) {
})
// Plugins off in settings so no fileData and we get a warning instead
fileData, err = th.App.createPluginsFile(ctx)
fileData, err = th.App.createPluginsFile(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "failed to get plugin list for support package")
}
@@ -44,7 +42,6 @@ func TestCreatePluginsFile(t *testing.T) {
func TestGenerateSupportPacketYaml(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
ctx := request.EmptyContext(th.TestLogger)
licenseUsers := 100
license := model.NewTestLicense()
@@ -54,7 +51,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
t.Run("Happy path", func(t *testing.T) {
// Happy path where we have a support packet yaml file without any warnings
fileData, err := th.App.generateSupportPacketYaml(ctx)
fileData, err := th.App.generateSupportPacketYaml(th.Context)
require.NotNil(t, fileData)
assert.Equal(t, "support_packet.yaml", fileData.Filename)
assert.Positive(t, len(fileData.Body))
@@ -75,7 +72,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
fb.On("DriverName").Return("mock")
fb.On("TestConnection").Return(errors.New("all broken"))
fileData, err := th.App.generateSupportPacketYaml(ctx)
fileData, err := th.App.generateSupportPacketYaml(th.Context)
require.NotNil(t, fileData)
assert.Equal(t, "support_packet.yaml", fileData.Filename)
assert.Positive(t, len(fileData.Body))
@@ -92,7 +89,6 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
func TestGenerateSupportPacket(t *testing.T) {
th := Setup(t)
defer th.TearDown()
ctx := request.EmptyContext(th.TestLogger)
d1 := []byte("hello\ngo\n")
err := os.WriteFile("mattermost.log", d1, 0777)
@@ -100,7 +96,7 @@ func TestGenerateSupportPacket(t *testing.T) {
err = os.WriteFile("notifications.log", d1, 0777)
require.NoError(t, err)
fileDatas := th.App.GenerateSupportPacket(ctx)
fileDatas := th.App.GenerateSupportPacket(th.Context)
var rFileNames []string
testFiles := []string{
"support_packet.yaml",
@@ -125,7 +121,7 @@ func TestGenerateSupportPacket(t *testing.T) {
require.NoError(t, err)
err = os.Remove("mattermost.log")
require.NoError(t, err)
fileDatas = th.App.GenerateSupportPacket(ctx)
fileDatas = th.App.GenerateSupportPacket(th.Context)
testFiles = []string{
"support_packet.yaml",
"plugins.json",
@@ -148,14 +144,13 @@ func TestGenerateSupportPacket(t *testing.T) {
func TestGetNotificationsLog(t *testing.T) {
th := Setup(t)
defer th.TearDown()
ctx := request.EmptyContext(th.TestLogger)
// Disable notifications file to get an error
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.NotificationLogSettings.EnableFile = false
})
fileData, err := th.App.getNotificationsLog(ctx)
fileData, err := th.App.getNotificationsLog(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "Unable to retrieve notifications.log because LogSettings: EnableFile is set to false")
@@ -167,7 +162,7 @@ func TestGetNotificationsLog(t *testing.T) {
// If any previous notifications.log file, lets delete it
os.Remove("notifications.log")
fileData, err = th.App.getNotificationsLog(ctx)
fileData, err = th.App.getNotificationsLog(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "failed read notifcation log file at path")
@@ -177,7 +172,7 @@ func TestGetNotificationsLog(t *testing.T) {
defer os.Remove("notifications.log")
require.NoError(t, err)
fileData, err = th.App.getNotificationsLog(ctx)
fileData, err = th.App.getNotificationsLog(th.Context)
require.NotNil(t, fileData)
assert.Equal(t, "notifications.log", fileData.Filename)
assert.Positive(t, len(fileData.Body))
@@ -187,14 +182,13 @@ func TestGetNotificationsLog(t *testing.T) {
func TestGetMattermostLog(t *testing.T) {
th := Setup(t)
defer th.TearDown()
ctx := request.EmptyContext(th.TestLogger)
// disable mattermost log file setting in config so we should get an warning
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.LogSettings.EnableFile = false
})
fileData, err := th.App.getMattermostLog(ctx)
fileData, err := th.App.getMattermostLog(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "Unable to retrieve mattermost.log because LogSettings: EnableFile is set to false")
@@ -206,7 +200,7 @@ func TestGetMattermostLog(t *testing.T) {
// If any previous mattermost.log file, lets delete it
os.Remove("mattermost.log")
fileData, err = th.App.getMattermostLog(ctx)
fileData, err = th.App.getMattermostLog(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "failed read mattermost log file at path mattermost.log")
@@ -216,7 +210,7 @@ func TestGetMattermostLog(t *testing.T) {
defer os.Remove("mattermost.log")
require.NoError(t, err)
fileData, err = th.App.getMattermostLog(ctx)
fileData, err = th.App.getMattermostLog(th.Context)
require.NotNil(t, fileData)
assert.Equal(t, "mattermost.log", fileData.Filename)
assert.Positive(t, len(fileData.Body))
@@ -226,10 +220,9 @@ func TestGetMattermostLog(t *testing.T) {
func TestCreateSanitizedConfigFile(t *testing.T) {
th := Setup(t)
defer th.TearDown()
ctx := request.EmptyContext(th.TestLogger)
// Happy path where we have a sanitized config file with no err
fileData, err := th.App.createSanitizedConfigFile(ctx)
fileData, err := th.App.createSanitizedConfigFile(th.Context)
require.NotNil(t, fileData)
assert.Equal(t, "sanitized_config.json", fileData.Filename)
assert.Positive(t, len(fileData.Body))