mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
b5c833ca21
* Update go.mod dependencies before release Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add issue for showing query warnings in promtool Signed-off-by: Julius Volz <julius.volz@gmail.com> * Revert json-iterator back to 1.1.6 It produced errors when marshaling Point values with special float values. Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix expected step values in promtool tests after client_golang update Signed-off-by: Julius Volz <julius.volz@gmail.com> * Update generated protobuf code after proto dep updates Signed-off-by: Julius Volz <julius.volz@gmail.com>
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
// Copyright 2018 The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestQueryRange(t *testing.T) {
|
|
s, getRequest := mockServer(200, `{"status": "success", "data": {"resultType": "matrix", "result": []}}`)
|
|
defer s.Close()
|
|
|
|
p := &promqlPrinter{}
|
|
exitCode := QueryRange(s.URL, map[string]string{}, "up", "0", "300", 0, p)
|
|
expectedPath := "/api/v1/query_range"
|
|
gotPath := getRequest().URL.Path
|
|
if gotPath != expectedPath {
|
|
t.Errorf("unexpected URL path %s (wanted %s)", gotPath, expectedPath)
|
|
}
|
|
form := getRequest().Form
|
|
actual := form.Get("query")
|
|
if actual != "up" {
|
|
t.Errorf("unexpected value %s for query", actual)
|
|
}
|
|
actual = form.Get("step")
|
|
if actual != "1" {
|
|
t.Errorf("unexpected value %s for step", actual)
|
|
}
|
|
if exitCode > 0 {
|
|
t.Error()
|
|
}
|
|
|
|
exitCode = QueryRange(s.URL, map[string]string{}, "up", "0", "300", 10*time.Millisecond, p)
|
|
gotPath = getRequest().URL.Path
|
|
if gotPath != expectedPath {
|
|
t.Errorf("unexpected URL path %s (wanted %s)", gotPath, expectedPath)
|
|
}
|
|
form = getRequest().Form
|
|
actual = form.Get("query")
|
|
if actual != "up" {
|
|
t.Errorf("unexpected value %s for query", actual)
|
|
}
|
|
actual = form.Get("step")
|
|
if actual != "0.01" {
|
|
t.Errorf("unexpected value %s for step", actual)
|
|
}
|
|
if exitCode > 0 {
|
|
t.Error()
|
|
}
|
|
}
|
|
|
|
func mockServer(code int, body string) (*httptest.Server, func() *http.Request) {
|
|
var req *http.Request
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
r.ParseForm()
|
|
req = r
|
|
w.WriteHeader(code)
|
|
fmt.Fprintln(w, body)
|
|
}))
|
|
|
|
f := func() *http.Request {
|
|
return req
|
|
}
|
|
return server, f
|
|
}
|