-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathlogging_test.go
More file actions
33 lines (28 loc) · 973 Bytes
/
logging_test.go
File metadata and controls
33 lines (28 loc) · 973 Bytes
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
package util
import (
"log/slog"
"strings"
"testing"
)
func assertLogLevel(t *testing.T, value string, level slog.Level) {
actual := parseLogLevel(value)
if actual != level {
t.Errorf("Expected %s to parse as %s, but got %s", value, level, actual)
}
}
func TestParseLogLevel(t *testing.T) {
// Known verbosity levels.
assertLogLevel(t, string(Errors), slog.LevelError)
assertLogLevel(t, string(Warnings), slog.LevelWarn)
assertLogLevel(t, string(Progress), slog.LevelInfo)
assertLogLevel(t, string(Details), slog.LevelDebug)
assertLogLevel(t, string(Spammy), slog.LevelDebug)
assertLogLevel(t, string(Spammier), slog.LevelDebug)
// Ignore case
assertLogLevel(t, strings.ToUpper(string(Spammier)), slog.LevelDebug)
assertLogLevel(t, strings.ToUpper(string(Errors)), slog.LevelError)
// Other values default to LevelInfo
assertLogLevel(t, "", slog.LevelInfo)
assertLogLevel(t, "unknown", slog.LevelInfo)
assertLogLevel(t, "none", slog.LevelInfo)
}