Merge pull request #13714 from bboreham/fix-testendpoints

API tests: fix flaky TestEndpoints
This commit is contained in:
Bryan Boreham 2024-03-06 11:43:29 +00:00 committed by GitHub
commit 0eb39a604b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1054,7 +1054,7 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
params map[string]string params map[string]string
query url.Values query url.Values
response interface{} response interface{}
responseLen int responseLen int // If nonzero, check only the length; `response` is ignored.
responseMetadataTotal int responseMetadataTotal int
responseAsJSON string responseAsJSON string
errType errorType errType errorType
@ -1388,17 +1388,16 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
labels.FromStrings("__name__", "test_metric2", "foo", "boo"), labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
}, },
}, },
// Missing match[] query params in series requests. // Series request with limit.
{ {
endpoint: api.series, endpoint: api.series,
query: url.Values{ query: url.Values{
"match[]": []string{"test_metric1"}, "match[]": []string{"test_metric1"},
"limit": []string{"1"}, "limit": []string{"1"},
}, },
response: []labels.Labels{ responseLen: 1, // API does not specify which particular value will come back.
labels.FromStrings("__name__", "test_metric1", "foo", "bar"),
},
}, },
// Missing match[] query params in series requests.
{ {
endpoint: api.series, endpoint: api.series,
errType: errorBadData, errType: errorBadData,
@ -2670,18 +2669,16 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
"boo", "boo",
}, },
}, },
// Label values with limit.
{ {
endpoint: api.labelValues, endpoint: api.labelValues,
params: map[string]string{ params: map[string]string{
"name": "foo", "name": "__name__",
}, },
query: url.Values{ query: url.Values{
"match[]": []string{"test_metric4"}, "limit": []string{"2"},
"limit": []string{"1"},
},
response: []string{
"bar",
}, },
responseLen: 2, // API does not specify which particular values will come back.
}, },
// Label names. // Label names.
{ {
@ -2822,13 +2819,13 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
}, },
response: []string{"__name__", "foo"}, response: []string{"__name__", "foo"},
}, },
// Label names with limit.
{ {
endpoint: api.labelNames, endpoint: api.labelNames,
query: url.Values{ query: url.Values{
"match[]": []string{"test_metric2"}, "limit": []string{"2"},
"limit": []string{"1"},
}, },
response: []string{"__name__"}, responseLen: 2, // API does not specify which particular values will come back.
}, },
}...) }...)
} }