(t *testing.T)
| 332 | } |
| 333 | |
| 334 | func 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 | |
| 375 | func TestRotateDebugFileForTestSet_NilSinkIsSafe(t *testing.T) { |
| 376 | SetDebugFileSink(nil) |
nothing calls this directly
no test coverage detected