MCPcopy
hub / github.com/tuna/tunasync / TestLoggerMethodsWriteExpectedLevels

Function TestLoggerMethodsWriteExpectedLevels

internal/logger_test.go:72–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func TestLoggerMethodsWriteExpectedLevels(t *testing.T) {
73 var buf bytes.Buffer
74 withDefaultHandler(t, newLineHandler(&buf, slog.LevelDebug, false, false))
75
76 logger := MustGetLogger("unit")
77 if logger.name != "unit" {
78 t.Fatalf("logger name = %q, want %q", logger.name, "unit")
79 }
80
81 debugFormat := "debug %s"
82 logger.Debug(debugFormat, "one")
83 logger.Debugf("debugf %d", 2)
84 logger.Info("info")
85 logger.Infof("infof %d", 3)
86 logger.Notice("notice")
87 logger.Noticef("noticef %d", 4)
88 logger.Warning("warning")
89 logger.Warningf("warningf %d", 5)
90 logger.Error("error")
91 logger.Errorf("errorf %d", 6)
92
93 lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
94 if len(lines) != 10 {
95 t.Fatalf("line count = %d, want 10\n%s", len(lines), buf.String())
96 }
97
98 wants := []string{
99 "[DEBUG] debug one",
100 "[DEBUG] debugf 2",
101 "[INFO] info",
102 "[INFO] infof 3",
103 "[NOTICE] notice",
104 "[NOTICE] noticef 4",
105 "[WARN] warning",
106 "[WARN] warningf 5",
107 "[ERROR] error",
108 "[ERROR] errorf 6",
109 }
110 for i, want := range wants {
111 if !strings.Contains(lines[i], want) {
112 t.Fatalf("line %d = %q, want substring %q", i, lines[i], want)
113 }
114 }
115}
116
117func TestLoggerRespectsLevelFiltering(t *testing.T) {
118 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 14

withDefaultHandlerFunction · 0.85
newLineHandlerFunction · 0.85
MustGetLoggerFunction · 0.85
DebugMethod · 0.80
DebugfMethod · 0.80
InfoMethod · 0.80
InfofMethod · 0.80
NoticeMethod · 0.80
NoticefMethod · 0.80
WarningMethod · 0.80
WarningfMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected