API tests: fix flaky TestEndpoints

When a limit is specified, the API may return arbitrary rows, so don't
check specific response values.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2024-03-06 09:58:40 +00:00
parent e6b7bbcb6a
commit 25f200bf85
1 changed files with 11 additions and 14 deletions

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.
}, },
}...) }...)
} }