From dbb65846f11e04008a738ffefac21f2ea0f805fe Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Mon, 27 Mar 2017 14:58:34 +0100 Subject: [PATCH] Add unittest for federation external_labels behaviour --- web/federate_test.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/web/federate_test.go b/web/federate_test.go index 7537a129c..6539e17c3 100644 --- a/web/federate_test.go +++ b/web/federate_test.go @@ -27,10 +27,11 @@ import ( ) var scenarios = map[string]struct { - params string - accept string - code int - body string + params string + accept string + externalLabels model.LabelSet + code int + body string }{ "empty": { params: "", @@ -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", )))