(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func 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 | |
| 111 | func TestAddDebugFileSink_Buffered_FlushRequired(t *testing.T) { |
| 112 | SetRedactor(nil) |
nothing calls this directly
no test coverage detected