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

Function Test_CustomAPI

pkg/api/queryapi/query_api_test.go:73–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func Test_CustomAPI(t *testing.T) {
74 engine := engine2.New(
75 promql.EngineOpts{
76 MaxSamples: 100,
77 Timeout: time.Second * 2,
78 },
79 engine2.ThanosEngineConfig{Enabled: false},
80 prometheus.NewRegistry())
81
82 mockQueryable := &mockSampleAndChunkQueryable{
83 queryableFn: func(_, _ int64) (storage.Querier, error) {
84 return mockQuerier{
85 matrix: model.Matrix{
86 {
87 Metric: model.Metric{"__name__": "test", "foo": "bar"},
88 Values: []model.SamplePair{
89 {Timestamp: 1536673665000, Value: 0},
90 {Timestamp: 1536673670000, Value: 1},
91 },
92 },
93 },
94 }, nil
95 },
96 }
97
98 tests := []struct {
99 name string
100 path string
101 expectedCode int
102 expectedBody string
103 }{
104 {
105 name: "[Range Query] empty start",
106 path: "/api/v1/query_range?end=1536673680&query=test&step=5",
107 expectedCode: http.StatusBadRequest,
108 expectedBody: "{\"status\":\"error\",\"errorType\":\"bad_data\",\"error\":\"invalid parameter \\\"start\\\"; cannot parse \\\"\\\" to a valid timestamp\"}",
109 },
110 {
111 name: "[Range Query] empty end",
112 path: "/api/v1/query_range?query=test&start=1536673665&step=5",
113 expectedCode: http.StatusBadRequest,
114 expectedBody: "{\"status\":\"error\",\"errorType\":\"bad_data\",\"error\":\"invalid parameter \\\"end\\\"; cannot parse \\\"\\\" to a valid timestamp\"}",
115 },
116 {
117 name: "[Range Query] start is greater than end",
118 path: "/api/v1/query_range?end=1536673680&query=test&start=1536673681&step=5",
119 expectedCode: http.StatusBadRequest,
120 expectedBody: "{\"status\":\"error\",\"errorType\":\"bad_data\",\"error\":\"invalid parameter \\\"end\\\"; end timestamp must not be before start time\"}",
121 },
122 {
123 name: "[Range Query] negative step",
124 path: "/api/v1/query_range?end=1536673680&query=test&start=1536673665&step=-1",
125 expectedCode: http.StatusBadRequest,
126 expectedBody: "{\"status\":\"error\",\"errorType\":\"bad_data\",\"error\":\"invalid parameter \\\"step\\\"; zero or negative query resolution step widths are not accepted. Try a positive integer\"}",
127 },
128 {
129 name: "[Range Query] returned points are over 11000",
130 path: "/api/v1/query_range?end=1536700000&query=test&start=1536673665&step=1",

Callers

nothing calls this directly

Calls 6

WrapMethod · 0.95
ContextWithEmptyStatsFunction · 0.92
NewQueryAPIFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected