-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
75 lines (72 loc) · 1.64 KB
/
config_test.go
File metadata and controls
75 lines (72 loc) · 1.64 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package logging
import (
"github.com/icinga/icinga-go-library/config"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"testing"
"time"
)
func TestConfig(t *testing.T) {
subtests := []struct {
name string
opts config.EnvOptions
expected Config
error bool
}{
{
name: "empty",
opts: config.EnvOptions{},
expected: Config{
Output: "console",
Interval: 20 * time.Second,
},
},
{
name: "invalid-output",
opts: config.EnvOptions{Environment: map[string]string{"OUTPUT": "☃"}},
error: true,
},
{
name: "customized",
opts: config.EnvOptions{Environment: map[string]string{
"LEVEL": zapcore.DebugLevel.String(),
"OUTPUT": JOURNAL,
"INTERVAL": "3m14s",
}},
expected: Config{
Level: zapcore.DebugLevel,
Output: JOURNAL,
Interval: 3*time.Minute + 14*time.Second,
},
},
{
name: "options",
opts: config.EnvOptions{Environment: map[string]string{"OPTIONS": "foo:debug,bar:info,buz:panic"}},
expected: Config{
Output: "console",
Interval: 20 * time.Second,
Options: map[string]zapcore.Level{
"foo": zapcore.DebugLevel,
"bar": zapcore.InfoLevel,
"buz": zapcore.PanicLevel,
},
},
},
{
name: "options-invalid-levels",
opts: config.EnvOptions{Environment: map[string]string{"OPTIONS": "foo:foo,bar:0"}},
error: true,
},
}
for _, test := range subtests {
t.Run(test.name, func(t *testing.T) {
var out Config
if err := config.FromEnv(&out, test.opts); test.error {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, test.expected, out)
}
})
}
}