Add unittest for federation external_labels behaviour

This commit is contained in:
Brian Brazil 2017-03-27 14:58:34 +01:00 committed by Brian Brazil
parent 5856f87be3
commit dbb65846f1
1 changed files with 19 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import (
var scenarios = map[string]struct {
params string
accept string
externalLabels model.LabelSet
code int
body string
}{
@ -124,6 +125,19 @@ test_metric1{foo="boo"} 1 6000000
test_metric2{foo="boo"} 1 6000000
# TYPE test_metric_without_labels untyped
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 {
h.externalLabels = scenario.externalLabels
req, err := http.ReadRequest(bufio.NewReader(strings.NewReader(
"GET http://example.org/federate?" + scenario.params + " HTTP/1.0\r\n\r\n",
)))