| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "reasonix/internal/event" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestReadStatusUsesDisjointOneBasedRanges(t *testing.T) { |
| 10 | got := readStatusLabelText(&event.ReadStatusPayload{ReadID: "r", Path: "a.go", Active: true, HasMore: true, Covered: [][2]int{{0, 10}, {100, 110}}}) |
| 11 | if !strings.Contains(got, "1-10, 101-110") { |
| 12 | t.Fatalf("false continuous coverage: %s", got) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | func TestReadStatusFencesGenerationsAndIndependentReads(t *testing.T) { |
| 17 | var state readStatusState |
| 18 | state.ingest(&event.ReadStatusPayload{ReadID: "a", Path: "a.go", Generation: 2, Sequence: 1, Active: true}) |
| 19 | state.ingest(&event.ReadStatusPayload{ReadID: "a", Path: "a.go", Generation: 1, Sequence: 99, Active: false}) |
| 20 | if !strings.Contains(state.readStatusLabel, "a.go") { |
| 21 | t.Fatal("stale frame cleared current state") |
| 22 | } |
| 23 | state.ingest(&event.ReadStatusPayload{ReadID: "b", Path: "b.go", Sequence: 1, Active: true}) |
| 24 | state.ingest(&event.ReadStatusPayload{ReadID: "a", Path: "a.go", Generation: 2, Sequence: 2, Active: false}) |
| 25 | if !strings.Contains(state.readStatusLabel, "b.go") { |
| 26 | t.Fatal("independent read disappeared") |
| 27 | } |
| 28 | } |
| 29 |