mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Test target URL
This commit is contained in:
parent
50c2f20756
commit
499f4af4aa
|
@ -20,7 +20,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
// "net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -89,50 +89,38 @@ func TestTargetOffset(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestTargetURLParams(t *testing.T) {
|
func TestTargetURL(t *testing.T) {
|
||||||
// server := httptest.NewServer(
|
params := url.Values{
|
||||||
// http.HandlerFunc(
|
"abc": []string{"foo", "bar", "baz"},
|
||||||
// func(w http.ResponseWriter, r *http.Request) {
|
"xyz": []string{"hoo"},
|
||||||
// w.Header().Set("Content-Type", `text/plain; version=0.0.4`)
|
}
|
||||||
// w.Write([]byte{})
|
labels := model.LabelSet{
|
||||||
// r.ParseForm()
|
model.AddressLabel: "example.com:1234",
|
||||||
// if r.Form["foo"][0] != "bar" {
|
model.SchemeLabel: "https",
|
||||||
// t.Fatalf("URL parameter 'foo' had unexpected first value '%v'", r.Form["foo"][0])
|
model.MetricsPathLabel: "/metricz",
|
||||||
// }
|
"__param_abc": "overwrite",
|
||||||
// if r.Form["foo"][1] != "baz" {
|
"__param_cde": "huu",
|
||||||
// t.Fatalf("URL parameter 'foo' had unexpected second value '%v'", r.Form["foo"][1])
|
}
|
||||||
// }
|
target := NewTarget(labels, labels, params)
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
// defer server.Close()
|
|
||||||
// serverURL, err := url.Parse(server.URL)
|
|
||||||
// if err != nil {
|
|
||||||
// t.Fatal(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// target, err := NewTarget(
|
// The reserved labels are concatenated into a full URL. The first value for each
|
||||||
// &config.ScrapeConfig{
|
// URL query parameter can be set/modified via labels as well.
|
||||||
// JobName: "test_job1",
|
expectedParams := url.Values{
|
||||||
// Scheme: "https",
|
"abc": []string{"overwrite", "bar", "baz"},
|
||||||
// Params: url.Values{
|
"cde": []string{"huu"},
|
||||||
// "foo": []string{"bar", "baz"},
|
"xyz": []string{"hoo"},
|
||||||
// },
|
}
|
||||||
// },
|
expectedURL := url.URL{
|
||||||
// model.LabelSet{
|
Scheme: "https",
|
||||||
// model.SchemeLabel: model.LabelValue(serverURL.Scheme),
|
Host: "example.com:1234",
|
||||||
// model.AddressLabel: model.LabelValue(serverURL.Host),
|
Path: "/metricz",
|
||||||
// "__param_foo": "bar_override",
|
RawQuery: expectedParams.Encode(),
|
||||||
// },
|
}
|
||||||
// nil,
|
|
||||||
// )
|
if u := target.URL(); !reflect.DeepEqual(u.String(), expectedURL.String()) {
|
||||||
// if err != nil {
|
t.Fatalf("Expected URL %q but got %q", expectedURL, u)
|
||||||
// t.Fatal(err)
|
}
|
||||||
// }
|
}
|
||||||
// if _, err = target.scrape(context.Background(), time.Now()); err != nil {
|
|
||||||
// t.Fatal(err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func newTestTarget(targetURL string, deadline time.Duration, labels model.LabelSet) *Target {
|
func newTestTarget(targetURL string, deadline time.Duration, labels model.LabelSet) *Target {
|
||||||
labels = labels.Clone()
|
labels = labels.Clone()
|
||||||
|
|
Loading…
Reference in a new issue