MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestBuildInfoAPI

Function TestBuildInfoAPI

pkg/api/handlers_test.go:200–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198}
199
200func TestBuildInfoAPI(t *testing.T) {
201 type buildInfo struct {
202 Status string `json:"status"`
203 Data v1.PrometheusVersion `json:"data"`
204 }
205
206 for _, tc := range []struct {
207 name string
208 version string
209 branch string
210 revision string
211 expected buildInfo
212 }{
213 {
214 name: "empty",
215 expected: buildInfo{Status: "success", Data: v1.PrometheusVersion{
216 GoVersion: runtime.Version(),
217 }},
218 },
219 {
220 name: "set versions",
221 version: "v0.14.0",
222 branch: "test",
223 revision: "foo",
224 expected: buildInfo{Status: "success", Data: v1.PrometheusVersion{
225 Version: "v0.14.0",
226 Branch: "test",
227 Revision: "foo",
228 GoVersion: runtime.Version(),
229 }},
230 },
231 } {
232 t.Run(tc.name, func(t *testing.T) {
233 cfg := Config{buildInfoEnabled: true}
234 querierConfig := querier.Config{}
235 version.Version = tc.version
236 version.Branch = tc.branch
237 version.Revision = tc.revision
238 handler := NewQuerierHandler(cfg, querierConfig, nil, nil, nil, nil, nil, &FakeLogger{})
239 writer := httptest.NewRecorder()
240 req := httptest.NewRequest("GET", "/api/v1/status/buildinfo", nil)
241 req = req.WithContext(user.InjectOrgID(req.Context(), "test"))
242 handler.ServeHTTP(writer, req)
243 out, err := io.ReadAll(writer.Body)
244 require.NoError(t, err)
245
246 var info buildInfo
247 err = json.Unmarshal(out, &info)
248 require.NoError(t, err)
249 require.Equal(t, tc.expected, info)
250 })
251 }
252}

Callers

nothing calls this directly

Calls 6

NewQuerierHandlerFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
ContextMethod · 0.45
ServeHTTPMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected