MCPcopy
hub / github.com/prometheus/pushgateway / TestStatusAPI

Function TestStatusAPI

api/v1/api_test.go:203–234  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

201}
202
203func TestStatusAPI(t *testing.T) {
204 dms := storage.NewDiskMetricStore("", 100*time.Millisecond, nil, logger)
205 testAPI := New(logger, dms, testFlags, testBuildInfo)
206
207 req, err := http.NewRequest("GET", "http://example.org/", &bytes.Buffer{})
208 if err != nil {
209 t.Fatal(err)
210 }
211
212 w := httptest.NewRecorder()
213
214 testResponse := response{}
215 testAPI.status(w, req)
216 if err := json.Unmarshal(w.Body.Bytes(), &testResponse); err != nil {
217 t.Fatalf("unexpected error unmarshaling response: %v", err)
218 }
219 jsonData := testResponse.Data.(map[string]any)
220 responseFlagData := jsonData["flags"].(map[string]any)
221 responseBuildInfo := jsonData["build_information"].(map[string]any)
222
223 if expected, got := http.StatusOK, w.Code; expected != got {
224 t.Errorf("Wanted status code %v, got %v.", expected, got)
225 }
226
227 if !reflect.DeepEqual(responseFlagData, convertMap(testFlags)) {
228 t.Errorf("Wanted following flags %q, got %q.", testFlags, responseFlagData)
229 }
230
231 if !reflect.DeepEqual(responseBuildInfo, convertMap(testBuildInfo)) {
232 t.Errorf("Wanted following build info %q, got %q.", testBuildInfo, responseBuildInfo)
233 }
234}
235
236func TestMetricsAPI(t *testing.T) {
237 dms := storage.NewDiskMetricStore("", 100*time.Millisecond, nil, logger)

Callers

nothing calls this directly

Calls 4

NewDiskMetricStoreFunction · 0.92
NewFunction · 0.85
convertMapFunction · 0.85
statusMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…