MCPcopy Create free account
hub / github.com/prometheus/common / TestQuery

Function TestQuery

route/route_test.go:95–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestQuery(t *testing.T) {
96 router := New()
97 const body = "query=up"
98 called := false
99 router.Query("/test/:foo/", func(w http.ResponseWriter, r *http.Request) {
100 called = true
101 want := "bar"
102 got := Param(r.Context(), "foo")
103 require.Equalf(t, want, got, "Unexpected context value: want %q, got %q", want, got)
104
105 gotBody, err := io.ReadAll(r.Body)
106 require.NoError(t, err)
107 require.Equal(t, body, string(gotBody))
108 w.WriteHeader(http.StatusOK)
109 })
110
111 w := httptest.NewRecorder()
112 r, err := http.NewRequest(MethodQuery, "http://localhost:9090/test/bar/", strings.NewReader(body))
113 require.NoErrorf(t, err, "Error building test request: %s", err)
114 router.ServeHTTP(w, r)
115 require.Truef(t, called, "QUERY handler was not called")
116 require.Equal(t, http.StatusOK, w.Code)
117}
118
119func TestInstrumentation(t *testing.T) {
120 var got string

Callers

nothing calls this directly

Calls 5

ParamFunction · 0.85
QueryMethod · 0.80
ServeHTTPMethod · 0.80
NewFunction · 0.70
EqualMethod · 0.45

Tested by

no test coverage detected