(t *testing.T)
| 1482 | } |
| 1483 | |
| 1484 | func TestPurgeStream(t *testing.T) { |
| 1485 | tests := []struct { |
| 1486 | name string |
| 1487 | opts []jetstream.StreamPurgeOpt |
| 1488 | expectedSeq []uint64 |
| 1489 | timeout time.Duration |
| 1490 | withError error |
| 1491 | }{ |
| 1492 | { |
| 1493 | name: "purge all messages", |
| 1494 | expectedSeq: []uint64{}, |
| 1495 | timeout: 5 * time.Second, |
| 1496 | }, |
| 1497 | { |
| 1498 | name: "with empty context", |
| 1499 | expectedSeq: []uint64{}, |
| 1500 | }, |
| 1501 | { |
| 1502 | name: "purge on subject", |
| 1503 | opts: []jetstream.StreamPurgeOpt{jetstream.WithPurgeSubject("FOO.2")}, |
| 1504 | expectedSeq: []uint64{1, 3, 5, 7, 9}, |
| 1505 | timeout: 5 * time.Second, |
| 1506 | }, |
| 1507 | { |
| 1508 | name: "purge with sequence", |
| 1509 | opts: []jetstream.StreamPurgeOpt{jetstream.WithPurgeSequence(5)}, |
| 1510 | expectedSeq: []uint64{5, 6, 7, 8, 9, 10}, |
| 1511 | timeout: 5 * time.Second, |
| 1512 | }, |
| 1513 | { |
| 1514 | name: "purge with keep", |
| 1515 | opts: []jetstream.StreamPurgeOpt{jetstream.WithPurgeKeep(3)}, |
| 1516 | expectedSeq: []uint64{8, 9, 10}, |
| 1517 | timeout: 5 * time.Second, |
| 1518 | }, |
| 1519 | { |
| 1520 | name: "purge with filter and sequence", |
| 1521 | opts: []jetstream.StreamPurgeOpt{jetstream.WithPurgeSubject("FOO.2"), jetstream.WithPurgeSequence(8)}, |
| 1522 | expectedSeq: []uint64{1, 3, 5, 7, 8, 9, 10}, |
| 1523 | timeout: 5 * time.Second, |
| 1524 | }, |
| 1525 | { |
| 1526 | name: "purge with filter and keep", |
| 1527 | opts: []jetstream.StreamPurgeOpt{jetstream.WithPurgeSubject("FOO.2"), jetstream.WithPurgeKeep(3)}, |
| 1528 | expectedSeq: []uint64{1, 3, 5, 6, 7, 8, 9, 10}, |
| 1529 | timeout: 5 * time.Second, |
| 1530 | }, |
| 1531 | { |
| 1532 | name: "with sequence and keep", |
| 1533 | opts: []jetstream.StreamPurgeOpt{jetstream.WithPurgeSequence(5), jetstream.WithPurgeKeep(3)}, |
| 1534 | withError: jetstream.ErrInvalidOption, |
| 1535 | }, |
| 1536 | { |
| 1537 | name: "context timeout", |
| 1538 | timeout: 1 * time.Microsecond, |
| 1539 | withError: context.DeadlineExceeded, |
| 1540 | }, |
| 1541 | } |
nothing calls this directly
no test coverage detected