2021-05-21 13:47:45 +00:00
|
|
|
package loggerconfig_test
|
|
|
|
|
|
|
|
import (
|
2021-05-21 17:51:59 +00:00
|
|
|
"os"
|
2021-05-21 13:47:45 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
2021-05-21 17:51:59 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/internal"
|
2021-05-21 13:47:45 +00:00
|
|
|
loggerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/logger"
|
|
|
|
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoggerSection_Level(t *testing.T) {
|
|
|
|
checkLevel := func(c *loggerconfig.LoggerSection, expected string) {
|
|
|
|
lvl := c.Level()
|
|
|
|
require.Equal(t, expected, lvl)
|
|
|
|
}
|
|
|
|
|
|
|
|
configtest.ForEachFileType("../../../../config/example/node", func(c *config.Config) {
|
|
|
|
cfg := loggerconfig.Init(c)
|
|
|
|
|
|
|
|
checkLevel(cfg, "debug")
|
|
|
|
})
|
|
|
|
|
|
|
|
empty := loggerconfig.Init(configtest.EmptyConfig())
|
|
|
|
|
|
|
|
checkLevel(empty, loggerconfig.LevelDefault)
|
2021-05-21 17:51:59 +00:00
|
|
|
|
|
|
|
t.Run("ENV", func(t *testing.T) {
|
|
|
|
// TODO: read from file
|
|
|
|
err := os.Setenv(
|
|
|
|
internal.Env("logger", "level"),
|
|
|
|
"debug",
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
empty = loggerconfig.Init(configtest.EmptyConfig())
|
|
|
|
|
|
|
|
checkLevel(empty, "debug")
|
|
|
|
})
|
2021-05-21 13:47:45 +00:00
|
|
|
}
|