(t *testing.T)
| 278 | } |
| 279 | |
| 280 | func TestStore_Validate(t *testing.T) { |
| 281 | t.Run("AllLevelsValid", func(t *testing.T) { |
| 282 | client := file.NewReplicaClient(t.TempDir()) |
| 283 | |
| 284 | db := &litestream.DB{} |
| 285 | db.Replica = litestream.NewReplicaWithClient(db, client) |
| 286 | |
| 287 | levels := litestream.CompactionLevels{ |
| 288 | {Level: 0}, |
| 289 | {Level: 1}, |
| 290 | } |
| 291 | store := litestream.NewStore([]*litestream.DB{db}, levels) |
| 292 | |
| 293 | // Create contiguous files at L0 |
| 294 | createTestLTXFile(t, client, 0, 1, 1) |
| 295 | createTestLTXFile(t, client, 0, 2, 2) |
| 296 | // Create contiguous files at L1 |
| 297 | createTestLTXFile(t, client, 1, 1, 2) |
| 298 | |
| 299 | result, err := store.Validate(t.Context()) |
| 300 | if err != nil { |
| 301 | t.Fatal(err) |
| 302 | } |
| 303 | if !result.Valid { |
| 304 | t.Errorf("expected valid result, got errors: %v", result.Errors) |
| 305 | } |
| 306 | }) |
| 307 | |
| 308 | t.Run("ErrorAtMultipleLevels", func(t *testing.T) { |
| 309 | client := file.NewReplicaClient(t.TempDir()) |
| 310 | |
| 311 | db := &litestream.DB{} |
| 312 | db.Replica = litestream.NewReplicaWithClient(db, client) |
| 313 | |
| 314 | levels := litestream.CompactionLevels{ |
| 315 | {Level: 0}, |
| 316 | {Level: 1}, |
| 317 | } |
| 318 | store := litestream.NewStore([]*litestream.DB{db}, levels) |
| 319 | |
| 320 | // Create files with gap at L0 |
| 321 | createTestLTXFile(t, client, 0, 1, 1) |
| 322 | createTestLTXFile(t, client, 0, 5, 5) // gap at 2-4 |
| 323 | |
| 324 | // Create files with overlap at L1 |
| 325 | createTestLTXFile(t, client, 1, 1, 5) |
| 326 | createTestLTXFile(t, client, 1, 3, 7) // overlap |
| 327 | |
| 328 | result, err := store.Validate(t.Context()) |
| 329 | if err != nil { |
| 330 | t.Fatal(err) |
| 331 | } |
| 332 | if result.Valid { |
| 333 | t.Error("expected invalid result") |
| 334 | } |
| 335 | if len(result.Errors) != 2 { |
| 336 | t.Errorf("expected 2 errors, got %d", len(result.Errors)) |
| 337 | } |
nothing calls this directly
no test coverage detected