MCPcopy
hub / github.com/keploy/keploy / TestAddDebugFileSink_Buffered_FlushRequired

Function TestAddDebugFileSink_Buffered_FlushRequired

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

Source from the content-addressed store, hash-verified

109}
110
111func TestAddDebugFileSink_Buffered_FlushRequired(t *testing.T) {
112 SetRedactor(nil)
113 console := &syncBuffer{}
114 logger := newConsoleLogger(console, zap.InfoLevel)
115
116 tmp, err := os.CreateTemp(t.TempDir(), "buf-*.log")
117 if err != nil {
118 t.Fatalf("create temp: %v", err)
119 }
120 defer tmp.Close()
121 wrapped, sink := AddDebugFileSink(logger, tmp, 0)
122
123 // One small entry — won't fill the 256 KiB buffer.
124 wrapped.Debug("buffered-line")
125
126 // Read before Flush — file should still be empty (or smaller than what's in flight).
127 pre, _ := os.ReadFile(tmp.Name())
128 if strings.Contains(string(pre), "buffered-line") {
129 t.Logf("note: BufferedWriteSyncer flushed proactively; harmless")
130 }
131
132 if err := sink.Flush(); err != nil {
133 t.Fatalf("flush: %v", err)
134 }
135 post, err := os.ReadFile(tmp.Name())
136 if err != nil {
137 t.Fatalf("read: %v", err)
138 }
139 if !strings.Contains(string(post), "buffered-line") {
140 t.Errorf("expected line in file after flush, got: %s", post)
141 }
142}
143
144func TestAddDebugFileSink_SoftCap(t *testing.T) {
145 SetRedactor(nil)

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected