| 14 | ) |
| 15 | |
| 16 | func TestRingPageHandler_handle(t *testing.T) { |
| 17 | now := time.Now() |
| 18 | ring := fakeRingAccess{ |
| 19 | desc: &Desc{ |
| 20 | Ingesters: map[string]InstanceDesc{ |
| 21 | "1": { |
| 22 | Zone: "zone-a", |
| 23 | State: ACTIVE, |
| 24 | Addr: "addr-a", |
| 25 | Timestamp: now.Unix(), |
| 26 | Tokens: []uint32{1000000, 3000000, 6000000}, |
| 27 | Versions: map[uint64]uint64{1: 2, 3: 4}, |
| 28 | }, |
| 29 | "2": { |
| 30 | Zone: "zone-b", |
| 31 | State: ACTIVE, |
| 32 | Addr: "addr-b", |
| 33 | Timestamp: now.Unix(), |
| 34 | Tokens: []uint32{2000000, 4000000, 5000000, 7000000}, |
| 35 | Versions: map[uint64]uint64{1: 3, 3: 5}, |
| 36 | }, |
| 37 | }, |
| 38 | }, |
| 39 | } |
| 40 | componentNames := map[uint64]string{1: "Component X"} |
| 41 | handler := newRingPageHandler(&ring, 10*time.Second, StatusPageConfig{ |
| 42 | HideTokensUIElements: false, |
| 43 | ShowVersions: true, |
| 44 | ComponentNames: componentNames, |
| 45 | }) |
| 46 | |
| 47 | t.Run("displays instance info", func(t *testing.T) { |
| 48 | recorder := httptest.NewRecorder() |
| 49 | handler.handle(recorder, httptest.NewRequest(http.MethodGet, "/ring", nil)) |
| 50 | |
| 51 | assert.Equal(t, http.StatusOK, recorder.Code) |
| 52 | assert.Equal(t, "text/html", recorder.Header().Get("Content-Type")) |
| 53 | |
| 54 | assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ |
| 55 | "<td>", "1", "</td>", |
| 56 | "<td>", "zone-a", "</td>", |
| 57 | "<td>", "ACTIVE", "</td>", |
| 58 | "<td>", "addr-a", "</td>", |
| 59 | }, `\s*`))), recorder.Body.String()) |
| 60 | |
| 61 | assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ |
| 62 | "<td>", "3", "</td>", |
| 63 | "<td>", "100%", "</td>", |
| 64 | "<td>", `1 \(Component X\): v2`, "<br/>", "3: v4", "<br/>", "</td>", |
| 65 | }, `\s*`))), recorder.Body.String()) |
| 66 | |
| 67 | assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ |
| 68 | "<td>", "2", "</td>", |
| 69 | "<td>", "zone-b", "</td>", |
| 70 | "<td>", "ACTIVE", "</td>", |
| 71 | "<td>", "addr-b", "</td>", |
| 72 | }, `\s*`))), recorder.Body.String()) |
| 73 | |