MCPcopy
hub / github.com/gofiber/fiber / Test_WithContextTemplateFailureOmitsPartialContext

Function Test_WithContextTemplateFailureOmitsPartialContext

log/default_test.go:278–304  ·  view source on GitHub ↗

Test_WithContextTemplateFailureOmitsPartialContext locks in the scratch-buffer guarantee from M8: a tag that writes some bytes before erroring must not leak its prefix into the real log line. Instead, the render-error marker stands in for the entire context block.

(t *testing.T)

Source from the content-addressed store, hash-verified

276// leak its prefix into the real log line. Instead, the render-error marker
277// stands in for the entire context block.
278func Test_WithContextTemplateFailureOmitsPartialContext(t *testing.T) {
279 initDefaultLogger()
280
281 templateErr := errors.New("template failure")
282 require.NoError(t, SetContextTemplate(ContextConfig{
283 Format: "[${broken}] ",
284 CustomTags: map[string]ContextTagFunc{
285 "broken": func(output Buffer, _ any, _ *ContextData, _ string) (int, error) {
286 if _, err := output.WriteString("partial"); err != nil {
287 return 0, err
288 }
289 return 0, templateErr
290 },
291 },
292 }))
293 t.Cleanup(func() { MustSetContextTemplate(ContextConfig{}) })
294
295 var w byteSliceWriter
296 SetOutput(&w)
297
298 WithContext(context.Background()).Info("start")
299
300 out := string(w.b)
301 require.NotContains(t, out, "partial", "scratch buffer must isolate partial writes from the live log line")
302 require.Contains(t, out, "ctx-render-error", "render error must be surfaced rather than silently dropped")
303 require.Contains(t, out, "start", "log payload must still reach the writer")
304}
305
306func Test_LogfKeyAndValues(t *testing.T) {
307 tests := []struct {

Callers

nothing calls this directly

Calls 9

initDefaultLoggerFunction · 0.85
SetContextTemplateFunction · 0.85
MustSetContextTemplateFunction · 0.85
SetOutputFunction · 0.85
WithContextFunction · 0.85
ContainsMethod · 0.80
NewMethod · 0.65
WriteStringMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected