forked from kuskoman/logstash-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslog_config_test.go
59 lines (57 loc) · 1.56 KB
/
slog_config_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package config
import (
"errors"
"testing"
)
func TestSetupSlog(t *testing.T) {
t.Run("Wrong type of log level", func(t *testing.T) {
LogLevel = "infox"
logger, err := SetupSlog()
if logger != nil {
t.Errorf("Expected logger to be nil, got %s\"", logger)
}
if err.Error() != "slog: level string \"infox\": unknown name" {
t.Errorf("Expected error to be '%s', got %s\"", "slog: level string \"infox\": unknown name", err)
}
})
t.Run("Wrong type of log level", func(t *testing.T) {
LogLevel = "warn"
logger, err := SetupSlog()
if err != nil {
t.Errorf("Expected error to be nil, got %s\"", err)
}
if logger == nil {
t.Errorf("Expected logger to be not nil, got %s\"", logger)
}
})
t.Run("Wrong type of log format", func(t *testing.T) {
LogFormat = "test"
logger, err := SetupSlog()
if logger != nil {
t.Errorf("Expected logger to be nil, got %s\"", logger)
}
if !errors.Is(err, ErrUnknownLogFormat) {
t.Errorf("Expected error to be '%s', got %s\"", ErrUnknownLogFormat, err)
}
})
t.Run("Correct type of log format", func(t *testing.T) {
LogFormat = "text"
logger, err := SetupSlog()
if err != nil {
t.Errorf("Expected error to be nil, got %s\"", err)
}
if logger == nil {
t.Errorf("Expected logger to be not nil, got %s\"", logger)
}
})
t.Run("Json type of log format", func(t *testing.T) {
LogFormat = "json"
logger, err := SetupSlog()
if err != nil {
t.Errorf("Expected error to be nil, got %s\"", err)
}
if logger == nil {
t.Errorf("Expected logger to be not nil, got %s\"", logger)
}
})
}