MCPcopy
hub / github.com/keploy/keploy / TestDebugFileSink_RotateAfterAddMode

Function TestDebugFileSink_RotateAfterAddMode

utils/log/logger_test.go:431–467  ·  view source on GitHub ↗

TestDebugFileSink_RotateAfterAddMode confirms that rotation still works after the logger has been rebuilt — the buffered+capped chain is the same instance, so RotateForScope swaps a file that the post-AddMode tee branch is already writing to.

(t *testing.T)

Source from the content-addressed store, hash-verified

429// chain is the same instance, so RotateForScope swaps a file that
430// the post-AddMode tee branch is already writing to.
431func TestDebugFileSink_RotateAfterAddMode(t *testing.T) {
432 SetRedactor(nil)
433 console := &syncBuffer{}
434 logger := newConsoleLogger(console, zap.InfoLevel)
435
436 dir := t.TempDir()
437 originPath := filepath.Join(dir, "agent-debug.log")
438 originFile, err := os.Create(originPath)
439 if err != nil {
440 t.Fatalf("create origin: %v", err)
441 }
442 defer originFile.Close()
443
444 wrapped, sink := AddDebugFileSink(logger, originFile, 0)
445 SetDebugFileSink(sink)
446 defer SetDebugFileSink(nil)
447
448 rebuilt, _ := AddMode("agent")
449 *wrapped = *rebuilt
450
451 if err := sink.RotateForScope("ts-x"); err != nil {
452 t.Fatalf("RotateForScope: %v", err)
453 }
454 wrapped.Debug("post-rebuild-post-rotate")
455
456 if err := sink.Flush(); err != nil {
457 t.Fatalf("flush: %v", err)
458 }
459 scopedPath := filepath.Join(dir, "ts-x", "agent-debug.log")
460 contents, err := os.ReadFile(scopedPath)
461 if err != nil {
462 t.Fatalf("read scoped file: %v", err)
463 }
464 if !strings.Contains(string(contents), "post-rebuild-post-rotate") {
465 t.Errorf("post-rebuild-post-rotate missing from %s: %s", scopedPath, contents)
466 }
467}
468
469func TestDebugFileSink_SurvivesChangeLogLevel(t *testing.T) {
470 SetRedactor(nil)

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected