[MM-54593] HA aware Support Packet (#27598)

Этот коммит содержится в:
Ben Schumacher
2024-08-03 16:11:13 +02:00
коммит произвёл GitHub
родитель 3f4b8e8137
Коммит 1158e6358c
24 изменённых файлов: 377 добавлений и 300 удалений

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

@@ -40,7 +40,7 @@ func TestCreatePluginsFile(t *testing.T) {
// Plugins off in settings so no fileData and we get a warning instead
fileData, err = th.App.createPluginsFile(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "failed to get plugin list for support package")
assert.ErrorContains(t, err, "failed to get plugin list for Support Packet")
}
func TestGenerateSupportPacketYaml(t *testing.T) {
@@ -68,7 +68,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
// Happy path where we have a Support Packet yaml file without any warnings
packet := generateSupportPacket(t)
/* Build information */
@@ -207,7 +207,7 @@ func TestGenerateSupportPacket(t *testing.T) {
}
genMockLogFiles()
t.Run("generate support packet with logs", func(t *testing.T) {
t.Run("generate Support Packet with logs", func(t *testing.T) {
fileDatas := th.App.GenerateSupportPacket(th.Context, &model.SupportPacketOptions{
IncludeLogs: true,
})
@@ -232,7 +232,7 @@ func TestGenerateSupportPacket(t *testing.T) {
assert.ElementsMatch(t, testFiles, rFileNames)
})
t.Run("generate support packet without logs", func(t *testing.T) {
t.Run("generate Support Packet without logs", func(t *testing.T) {
fileDatas := th.App.GenerateSupportPacket(th.Context, &model.SupportPacketOptions{
IncludeLogs: false,
})
@@ -326,96 +326,6 @@ func TestGenerateSupportPacket(t *testing.T) {
})
}
func TestGetNotificationsLog(t *testing.T) {
th := Setup(t)
defer th.TearDown()
// Disable notifications file setting in config so we should get an warning
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.NotificationLogSettings.EnableFile = false
})
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")
dir, err := os.MkdirTemp("", "")
require.NoError(t, err)
t.Cleanup(func() {
err = os.RemoveAll(dir)
assert.NoError(t, err)
})
// Enable notifications file but point to an empty directory to get an error trying to read the file
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.NotificationLogSettings.EnableFile = true
*cfg.LogSettings.FileLocation = dir
})
logLocation := config.GetNotificationsLogFileLocation(dir)
// There is no notifications.log file yet, so this fails
fileData, err = th.App.getNotificationsLog(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "failed read notifcation log file at path "+logLocation)
// Happy path where we have file and no error
d1 := []byte("hello\ngo\n")
err = os.WriteFile(logLocation, d1, 0777)
require.NoError(t, err)
fileData, err = th.App.getNotificationsLog(th.Context)
assert.NoError(t, err)
require.NotNil(t, fileData)
assert.Equal(t, "notifications.log", fileData.Filename)
assert.Positive(t, len(fileData.Body))
}
func TestGetMattermostLog(t *testing.T) {
th := Setup(t)
defer th.TearDown()
// 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(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "Unable to retrieve mattermost.log because LogSettings: EnableFile is set to false")
dir, err := os.MkdirTemp("", "")
require.NoError(t, err)
t.Cleanup(func() {
err = os.RemoveAll(dir)
assert.NoError(t, err)
})
// Enable log file but point to an empty directory to get an error trying to read the file
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.LogSettings.EnableFile = true
*cfg.LogSettings.FileLocation = dir
})
logLocation := config.GetLogFileLocation(dir)
// There is no mattermost.log file yet, so this fails
fileData, err = th.App.GetMattermostLog(th.Context)
assert.Nil(t, fileData)
assert.ErrorContains(t, err, "failed read mattermost log file at path "+logLocation)
// Happy path where we get a log file and no warning
d1 := []byte("hello\ngo\n")
err = os.WriteFile(logLocation, d1, 0777)
require.NoError(t, err)
fileData, err = th.App.GetMattermostLog(th.Context)
require.NoError(t, err)
require.NotNil(t, fileData)
assert.Equal(t, "mattermost.log", fileData.Filename)
assert.Positive(t, len(fileData.Body))
}
func TestCreateSanitizedConfigFile(t *testing.T) {
th := Setup(t)
defer th.TearDown()