(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestCompactor_Compact(t *testing.T) { |
| 21 | t.Run("L0ToL1", func(t *testing.T) { |
| 22 | client := file.NewReplicaClient(t.TempDir()) |
| 23 | compactor := litestream.NewCompactor(client, slog.Default()) |
| 24 | |
| 25 | // Create test L0 files |
| 26 | createTestLTXFile(t, client, 0, 1, 1) |
| 27 | createTestLTXFile(t, client, 0, 2, 2) |
| 28 | |
| 29 | info, err := compactor.Compact(context.Background(), 1) |
| 30 | if err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | if info.Level != 1 { |
| 34 | t.Errorf("Level=%d, want 1", info.Level) |
| 35 | } |
| 36 | if info.MinTXID != 1 || info.MaxTXID != 2 { |
| 37 | t.Errorf("TXID range=%d-%d, want 1-2", info.MinTXID, info.MaxTXID) |
| 38 | } |
| 39 | }) |
| 40 | |
| 41 | t.Run("NoFiles", func(t *testing.T) { |
| 42 | client := file.NewReplicaClient(t.TempDir()) |
| 43 | compactor := litestream.NewCompactor(client, slog.Default()) |
| 44 | |
| 45 | _, err := compactor.Compact(context.Background(), 1) |
| 46 | if err != litestream.ErrNoCompaction { |
| 47 | t.Errorf("err=%v, want ErrNoCompaction", err) |
| 48 | } |
| 49 | }) |
| 50 | |
| 51 | t.Run("L1ToL2", func(t *testing.T) { |
| 52 | client := file.NewReplicaClient(t.TempDir()) |
| 53 | compactor := litestream.NewCompactor(client, slog.Default()) |
| 54 | |
| 55 | // Create L0 files |
| 56 | createTestLTXFile(t, client, 0, 1, 1) |
| 57 | createTestLTXFile(t, client, 0, 2, 2) |
| 58 | |
| 59 | // Compact to L1 |
| 60 | _, err := compactor.Compact(context.Background(), 1) |
| 61 | if err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | |
| 65 | // Create more L0 files |
| 66 | createTestLTXFile(t, client, 0, 3, 3) |
| 67 | |
| 68 | // Compact to L1 again (should only include TXID 3) |
| 69 | info, err := compactor.Compact(context.Background(), 1) |
| 70 | if err != nil { |
| 71 | t.Fatal(err) |
| 72 | } |
| 73 | if info.MinTXID != 3 || info.MaxTXID != 3 { |
| 74 | t.Errorf("TXID range=%d-%d, want 3-3", info.MinTXID, info.MaxTXID) |
| 75 | } |
| 76 | |
| 77 | // Now compact L1 to L2 (should include all from 1-3) |
nothing calls this directly
no test coverage detected