1
0

rebuild_simple_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package indexer
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. )
  7. // TestBasicOptimizationLogic tests the core optimization logic without complex mocks
  8. func TestBasicOptimizationLogic(t *testing.T) {
  9. // Create temporary directory
  10. tmpDir := t.TempDir()
  11. // Create test files
  12. activeLogPath := filepath.Join(tmpDir, "access.log")
  13. compressedLogPath := filepath.Join(tmpDir, "access.log.1.gz")
  14. if err := os.WriteFile(activeLogPath, []byte("test log content\n"), 0644); err != nil {
  15. t.Fatalf("Failed to create active log file: %v", err)
  16. }
  17. if err := os.WriteFile(compressedLogPath, []byte("compressed content"), 0644); err != nil {
  18. t.Fatalf("Failed to create compressed log file: %v", err)
  19. }
  20. // Create rebuild manager with no persistence (should always process)
  21. config := DefaultRebuildConfig()
  22. rm := &RebuildManager{
  23. persistence: nil,
  24. config: config,
  25. }
  26. // Test active file without persistence
  27. activeFile := &LogGroupFile{
  28. Path: activeLogPath,
  29. IsCompressed: false,
  30. }
  31. shouldProcess, reason := rm.shouldProcessFile(activeFile)
  32. if !shouldProcess {
  33. t.Errorf("Expected to process active file without persistence, got false: %s", reason)
  34. }
  35. t.Logf("✅ Active file without persistence: shouldProcess=%v, reason=%s", shouldProcess, reason)
  36. // Test compressed file without persistence
  37. compressedFile := &LogGroupFile{
  38. Path: compressedLogPath,
  39. IsCompressed: true,
  40. }
  41. shouldProcess, reason = rm.shouldProcessFile(compressedFile)
  42. if !shouldProcess {
  43. t.Errorf("Expected to process compressed file without persistence, got false: %s", reason)
  44. }
  45. t.Logf("✅ Compressed file without persistence: shouldProcess=%v, reason=%s", shouldProcess, reason)
  46. }