Fix bugs from merge

This commit is contained in:
Jeanette Tan 2023-04-14 18:22:51 +08:00
parent a537d6c5c6
commit 894f657c48
2 changed files with 11 additions and 17 deletions

View file

@ -3114,11 +3114,11 @@ func TestRangeQuery(t *testing.T) {
Query: `foo > 2 or bar`, Query: `foo > 2 or bar`,
Result: Matrix{ Result: Matrix{
Series{ Series{
Points: []Point{{V: 1, T: 0}, {V: 3, T: 60000}, {V: 5, T: 120000}}, Floats: []FPoint{{F: 1, T: 0}, {F: 3, T: 60000}, {F: 5, T: 120000}},
Metric: labels.FromStrings("__name__", "bar", "job", "2"), Metric: labels.FromStrings("__name__", "bar", "job", "2"),
}, },
Series{ Series{
Points: []Point{{V: 3, T: 60000}, {V: 5, T: 120000}}, Floats: []FPoint{{F: 3, T: 60000}, {F: 5, T: 120000}},
Metric: labels.FromStrings("__name__", "foo", "job", "1"), Metric: labels.FromStrings("__name__", "foo", "job", "1"),
}, },
}, },

View file

@ -30,7 +30,7 @@ func TestJsonCodec_Encode(t *testing.T) {
expected string expected string
}{ }{
{ {
response: &queryData{ response: &QueryData{
ResultType: parser.ValueTypeMatrix, ResultType: parser.ValueTypeMatrix,
Result: promql.Matrix{ Result: promql.Matrix{
promql.Series{ promql.Series{
@ -42,7 +42,7 @@ func TestJsonCodec_Encode(t *testing.T) {
expected: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"foo"},"values":[[1,"1"]]}]}}`, expected: `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"foo"},"values":[[1,"1"]]}]}}`,
}, },
{ {
response: &queryData{ response: &QueryData{
ResultType: parser.ValueTypeMatrix, ResultType: parser.ValueTypeMatrix,
Result: promql.Matrix{ Result: promql.Matrix{
promql.Series{ promql.Series{
@ -160,21 +160,15 @@ func TestJsonCodec_Encode(t *testing.T) {
}, },
} }
for _, c := range cases { codec := JSONCodec{}
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
api := API{}
api.respond(w, c.response, nil)
}))
defer s.Close()
resp, err := http.Get(s.URL) for _, c := range cases {
body, err := codec.Encode(&Response{
Status: statusSuccess,
Data: c.response,
})
if err != nil { if err != nil {
t.Fatalf("Error on test request: %s", err) t.Fatalf("Error encoding response body: %s", err)
}
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
t.Fatalf("Error reading response body: %s", err)
} }
if string(body) != c.expected { if string(body) != c.expected {