MCPcopy Index your code
hub / github.com/dnote/dnote / TestShouldLog

Function TestShouldLog

pkg/server/log/log_test.go:37–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestShouldLog(t *testing.T) {
38 // Reset to default after test
39 defer SetLevel(LevelInfo)
40
41 testCases := []struct {
42 currentLevel string
43 logLevel string
44 expected bool
45 description string
46 }{
47 // Debug level shows everything
48 {LevelDebug, LevelDebug, true, "debug level should show debug"},
49 {LevelDebug, LevelInfo, true, "debug level should show info"},
50 {LevelDebug, LevelWarn, true, "debug level should show warn"},
51 {LevelDebug, LevelError, true, "debug level should show error"},
52
53 // Info level shows info + warn + error
54 {LevelInfo, LevelDebug, false, "info level should not show debug"},
55 {LevelInfo, LevelInfo, true, "info level should show info"},
56 {LevelInfo, LevelWarn, true, "info level should show warn"},
57 {LevelInfo, LevelError, true, "info level should show error"},
58
59 // Warn level shows warn + error
60 {LevelWarn, LevelDebug, false, "warn level should not show debug"},
61 {LevelWarn, LevelInfo, false, "warn level should not show info"},
62 {LevelWarn, LevelWarn, true, "warn level should show warn"},
63 {LevelWarn, LevelError, true, "warn level should show error"},
64
65 // Error level shows only error
66 {LevelError, LevelDebug, false, "error level should not show debug"},
67 {LevelError, LevelInfo, false, "error level should not show info"},
68 {LevelError, LevelWarn, false, "error level should not show warn"},
69 {LevelError, LevelError, true, "error level should show error"},
70 }
71
72 for _, tc := range testCases {
73 SetLevel(tc.currentLevel)
74 result := shouldLog(tc.logLevel)
75 if result != tc.expected {
76 t.Errorf("%s: expected %v, got %v", tc.description, tc.expected, result)
77 }
78 }
79}

Callers

nothing calls this directly

Calls 2

SetLevelFunction · 0.85
shouldLogFunction · 0.85

Tested by

no test coverage detected