MCPcopy
hub / github.com/keploy/keploy / TestAddDebugFileSink_AfterAttach_DebugLandsInFile

Function TestAddDebugFileSink_AfterAttach_DebugLandsInFile

utils/log/logger_test.go:71–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestAddDebugFileSink_AfterAttach_DebugLandsInFile(t *testing.T) {
72 SetRedactor(nil)
73 console := &syncBuffer{}
74 logger := newConsoleLogger(console, zap.InfoLevel) // console suppresses debug
75
76 tmp, err := os.CreateTemp(t.TempDir(), "after-*.log")
77 if err != nil {
78 t.Fatalf("create temp: %v", err)
79 }
80 defer tmp.Close()
81 wrapped, sink := AddDebugFileSink(logger, tmp, 0)
82
83 wrapped.Debug("debug-line")
84 wrapped.Info("info-line")
85
86 if err := sink.Flush(); err != nil {
87 t.Fatalf("flush: %v", err)
88 }
89 contents, err := os.ReadFile(tmp.Name())
90 if err != nil {
91 t.Fatalf("read: %v", err)
92 }
93 got := string(contents)
94 if !strings.Contains(got, "debug-line") {
95 t.Errorf("expected debug line in file, got: %s", got)
96 }
97 if !strings.Contains(got, "info-line") {
98 t.Errorf("expected info line in file, got: %s", got)
99 }
100
101 // console is at Info level — debug must NOT have reached it.
102 con := console.String()
103 if strings.Contains(con, "debug-line") {
104 t.Errorf("debug line leaked to console at Info level: %s", con)
105 }
106 if !strings.Contains(con, "info-line") {
107 t.Errorf("info line missing from console: %s", con)
108 }
109}
110
111func TestAddDebugFileSink_Buffered_FlushRequired(t *testing.T) {
112 SetRedactor(nil)

Callers

nothing calls this directly

Calls 8

StringMethod · 0.95
SetRedactorFunction · 0.85
newConsoleLoggerFunction · 0.85
AddDebugFileSinkFunction · 0.85
FlushMethod · 0.80
NameMethod · 0.80
CloseMethod · 0.65
DebugMethod · 0.65

Tested by

no test coverage detected