(t *testing.T)
| 22 | ) |
| 23 | |
| 24 | func TestPartitionRingPageHandler_ViewPage(t *testing.T) { |
| 25 | partRing, err := NewPartitionRing(PartitionRingDesc{ |
| 26 | Partitions: map[int32]PartitionDesc{ |
| 27 | 1: { |
| 28 | State: PartitionActive, |
| 29 | StateTimestamp: time.Now().Unix(), |
| 30 | Tokens: []uint32{1000000, 3000000, 6000000}, |
| 31 | }, |
| 32 | 2: { |
| 33 | State: PartitionInactive, |
| 34 | StateTimestamp: time.Now().Unix(), |
| 35 | Tokens: []uint32{2000000, 4000000, 5000000, 7000000}, |
| 36 | }, |
| 37 | }, |
| 38 | Owners: map[string]OwnerDesc{ |
| 39 | "ingester-zone-a-0": { |
| 40 | OwnedPartition: 1, |
| 41 | }, |
| 42 | "ingester-zone-a-1": { |
| 43 | OwnedPartition: 2, |
| 44 | }, |
| 45 | "ingester-zone-b-0": { |
| 46 | OwnedPartition: 1, |
| 47 | }, |
| 48 | "ingester-zone-b-1": { |
| 49 | OwnedPartition: 2, |
| 50 | }, |
| 51 | |
| 52 | // Simulate a corrupted partition, with a dangling owner but no partition. |
| 53 | "ingester-zone-b-2": { |
| 54 | OwnedPartition: 3, |
| 55 | }, |
| 56 | }, |
| 57 | }) |
| 58 | require.NoError(t, err) |
| 59 | |
| 60 | handler := NewPartitionRingPageHandler( |
| 61 | newStaticPartitionRingReader(partRing), |
| 62 | nil, |
| 63 | ) |
| 64 | |
| 65 | t.Run("displays expected partition info", func(t *testing.T) { |
| 66 | recorder := httptest.NewRecorder() |
| 67 | handler.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/partition-ring", nil)) |
| 68 | |
| 69 | assert.Equal(t, http.StatusOK, recorder.Code) |
| 70 | assert.Equal(t, "text/html", recorder.Header().Get("Content-Type")) |
| 71 | |
| 72 | assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ |
| 73 | "<td>", "1", "</td>", |
| 74 | "<td>", "Active", "</td>", |
| 75 | "<td>", "[^<]+", "</td>", |
| 76 | "<td>", "ingester-zone-a-0", "<br />", "ingester-zone-b-0", "<br />", "</td>", |
| 77 | "<td>", "3", "</td>", |
| 78 | "<td>", "99.9%", "</td>", |
| 79 | }, `\s*`))), recorder.Body.String()) |
| 80 | |
| 81 | assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ |
nothing calls this directly
no test coverage detected