Files
mattermost/server/config/logger_test.go
Agniva De Sarker efaa6264cc MM-53032: Fix module path after repo rename (#23689)
It was a good decision in hindsight to keep the public module as 0.x
because this would have been a breaking change again.

https://mattermost.atlassian.net/browse/MM-53032
```release-note
Changed the Go module path from github.com/mattermost/mattermost-server/server/v8 to github.com/mattermost/mattermost/server/v8.

For the public facing module, it's path is also changed from github.com/mattermost/mattermost-server/server/public to github.com/mattermost/mattermost/server/public
```
2023-06-11 10:54:35 +05:30

54 lines
1.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package config
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
func TestMloggerConfigFromAuditConfig(t *testing.T) {
auditSettings := model.ExperimentalAuditSettings{
FileEnabled: model.NewBool(true),
FileName: model.NewString("audit.log"),
FileMaxSizeMB: model.NewInt(20),
FileMaxAgeDays: model.NewInt(1),
FileMaxBackups: model.NewInt(5),
FileCompress: model.NewBool(true),
FileMaxQueueSize: model.NewInt(5000),
}
t.Run("validate default audit settings", func(t *testing.T) {
cfg, err := MloggerConfigFromAuditConfig(auditSettings, nil)
require.NoError(t, err, "audit config should not error")
require.Len(t, cfg, 1, "default audit config should have one target")
targetCfg := cfg["_defAudit"]
// check general
assert.Equal(t, targetCfg.Type, "file")
assert.Equal(t, targetCfg.Format, "json")
assert.ElementsMatch(t, targetCfg.Levels, []mlog.Level{mlog.LvlAuditAPI, mlog.LvlAuditContent, mlog.LvlAuditPerms, mlog.LvlAuditCLI})
// check format options
optionsExpected := map[string]any{
"disable_timestamp": false,
"disable_msg": true,
"disable_stacktrace": true,
"disable_level": true,
}
var optionsReceived map[string]any
err = json.Unmarshal(targetCfg.FormatOptions, &optionsReceived)
require.NoError(t, err, "unmarshal should not fail")
assert.Equal(t, optionsExpected, optionsReceived)
})
}