forked from taiyoh/sqsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
38 lines (33 loc) · 869 Bytes
/
logger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package sqsd
import (
"os"
"testing"
"github.com/AsynkronIT/protoactor-go/log"
"github.com/caarlos0/env/v6"
"github.com/stretchr/testify/assert"
)
func TestLogLevel(t *testing.T) {
t.Cleanup(func() {
os.Unsetenv("LOG_LEVEL")
})
type testcfg struct {
LogLevel LogLevel `env:"LOG_LEVEL" envDefault:"info"`
}
t.Run("default assigned", func(t *testing.T) {
c := testcfg{}
assert.NoError(t, env.Parse(&c))
assert.Equal(t, log.InfoLevel, c.LogLevel.Level)
})
t.Run("`DEBUG` is assigned", func(t *testing.T) {
os.Setenv("LOG_LEVEL", "DEBUG")
c := testcfg{}
assert.NoError(t, env.Parse(&c))
assert.Equal(t, log.DebugLevel, c.LogLevel.Level)
})
t.Run("`SQSDTEST` is assigned", func(t *testing.T) {
os.Setenv("LOG_LEVEL", "SQSDTEST")
c := testcfg{}
assert.Error(t, env.Parse(&c))
assert.Equal(t, log.MinLevel, c.LogLevel.Level)
})
}