status-go/logutils/override_test.go
Igor Sirotin e477269983
feat_: init logs in InitializeApplication (#6117)
* feat_: functional tests for logs

* feat_: init logs in `InitializeApplication`

* chore_: completely remove `MobileSystem` log setting

migrate

* chore_: condition for call startTime

* fix_: rebase issues, linter

* fix_: sql query

* test_: mark rpc TestInitializeLogging

* test_: skip TestInitializeLogging
2024-11-29 11:43:07 +00:00

77 lines
1.3 KiB
Go

package logutils
import (
"io"
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func TestOverrideCoreWithConfig(t *testing.T) {
tests := []struct {
name string
settings LogSettings
expectError bool
}{
{
name: "disabled logging",
settings: LogSettings{
Enabled: false,
},
expectError: false,
},
{
name: "invalid log level",
settings: LogSettings{
Enabled: true,
Level: "invalid",
},
expectError: true,
},
{
name: "valid log level",
settings: LogSettings{
Enabled: true,
Level: "info",
},
expectError: false,
},
{
name: "mobile system logging",
settings: LogSettings{
Enabled: true,
},
expectError: false,
},
{
name: "file logging with rotation",
settings: LogSettings{
Enabled: true,
File: "test.log",
MaxSize: 10,
MaxBackups: 0,
CompressRotated: true,
},
expectError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
core := NewCore(
defaultEncoder(),
zapcore.AddSync(io.Discard),
zap.NewAtomicLevelAt(zap.InfoLevel),
)
err := overrideCoreWithConfig(core, tt.settings)
if tt.expectError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}