Add unittest for federation external_labels behaviour
This commit is contained in:
parent
5856f87be3
commit
dbb65846f1
|
@ -27,10 +27,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var scenarios = map[string]struct {
|
var scenarios = map[string]struct {
|
||||||
params string
|
params string
|
||||||
accept string
|
accept string
|
||||||
code int
|
externalLabels model.LabelSet
|
||||||
body string
|
code int
|
||||||
|
body string
|
||||||
}{
|
}{
|
||||||
"empty": {
|
"empty": {
|
||||||
params: "",
|
params: "",
|
||||||
|
@ -124,6 +125,19 @@ test_metric1{foo="boo"} 1 6000000
|
||||||
test_metric2{foo="boo"} 1 6000000
|
test_metric2{foo="boo"} 1 6000000
|
||||||
# TYPE test_metric_without_labels untyped
|
# TYPE test_metric_without_labels untyped
|
||||||
test_metric_without_labels 1001 6000000
|
test_metric_without_labels 1001 6000000
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"external labels are added if not already present": {
|
||||||
|
params: "match[]={__name__=~'.%2b'}", // '%2b' is an URL-encoded '+'.
|
||||||
|
externalLabels: model.LabelSet{"zone": "ie", "foo": "baz"},
|
||||||
|
code: 200,
|
||||||
|
body: `# TYPE test_metric1 untyped
|
||||||
|
test_metric1{foo="bar",zone="ie"} 10000 6000000
|
||||||
|
test_metric1{foo="boo",zone="ie"} 1 6000000
|
||||||
|
# TYPE test_metric2 untyped
|
||||||
|
test_metric2{foo="boo",zone="ie"} 1 6000000
|
||||||
|
# TYPE test_metric_without_labels untyped
|
||||||
|
test_metric_without_labels{zone="ie",foo="baz"} 1001 6000000
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -152,6 +166,7 @@ func TestFederation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, scenario := range scenarios {
|
for name, scenario := range scenarios {
|
||||||
|
h.externalLabels = scenario.externalLabels
|
||||||
req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(
|
req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(
|
||||||
"GET http://example.org/federate?" + scenario.params + " HTTP/1.0\r\n\r\n",
|
"GET http://example.org/federate?" + scenario.params + " HTTP/1.0\r\n\r\n",
|
||||||
)))
|
)))
|
||||||
|
|
Loading…
Reference in New Issue