MCPcopy
hub / github.com/keploy/keploy / TestDebugFileSink_RotateBackToOrigin

Function TestDebugFileSink_RotateBackToOrigin

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

Source from the content-addressed store, hash-verified

332}
333
334func TestDebugFileSink_RotateBackToOrigin(t *testing.T) {
335 SetRedactor(nil)
336 console := &syncBuffer{}
337 logger := newConsoleLogger(console, zap.InfoLevel)
338
339 dir := t.TempDir()
340 originPath := filepath.Join(dir, "agent-debug.log")
341 originFile, err := os.Create(originPath)
342 if err != nil {
343 t.Fatalf("create origin: %v", err)
344 }
345 defer originFile.Close()
346
347 wrapped, sink := AddDebugFileSink(logger, originFile, 0)
348 defer SetDebugFileSink(nil)
349
350 if err := sink.RotateForScope("ts-a"); err != nil {
351 t.Fatalf("RotateForScope: %v", err)
352 }
353 wrapped.Debug("scoped-record")
354
355 if err := sink.RotateForScope(""); err != nil {
356 t.Fatalf("RotateForScope back to origin: %v", err)
357 }
358 wrapped.Debug("post-rotation-origin-record")
359
360 if err := sink.Flush(); err != nil {
361 t.Fatalf("flush: %v", err)
362 }
363
364 originBytes, _ := os.ReadFile(originPath)
365 if !strings.Contains(string(originBytes), "post-rotation-origin-record") {
366 t.Errorf("post-rotation record missing from origin: %s", originBytes)
367 }
368 scopedPath := filepath.Join(dir, "ts-a", "agent-debug.log")
369 scopedBytes, _ := os.ReadFile(scopedPath)
370 if !strings.Contains(string(scopedBytes), "scoped-record") {
371 t.Errorf("scoped record missing from scoped file: %s", scopedBytes)
372 }
373}
374
375func TestRotateDebugFileForTestSet_NilSinkIsSafe(t *testing.T) {
376 SetDebugFileSink(nil)

Callers

nothing calls this directly

Calls 8

SetRedactorFunction · 0.85
newConsoleLoggerFunction · 0.85
AddDebugFileSinkFunction · 0.85
SetDebugFileSinkFunction · 0.85
RotateForScopeMethod · 0.80
FlushMethod · 0.80
CloseMethod · 0.65
DebugMethod · 0.65

Tested by

no test coverage detected