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)
| 429 | // chain is the same instance, so RotateForScope swaps a file that |
| 430 | // the post-AddMode tee branch is already writing to. |
| 431 | func 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 | |
| 469 | func TestDebugFileSink_SurvivesChangeLogLevel(t *testing.T) { |
| 470 | SetRedactor(nil) |
nothing calls this directly
no test coverage detected