MCPcopy
hub / github.com/grafana/dskit / TestRingPageHandler_handle

Function TestRingPageHandler_handle

ring/ring_http_test.go:16–242  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func 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

Callers

nothing calls this directly

Calls 8

newRingPageHandlerFunction · 0.85
RunMethod · 0.80
handleMethod · 0.80
GetMethod · 0.65
StringMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected