Fix flaky TestPublic_FindCommentsCtrl_ConsistentCount

The test decided the expected HTTP status with strings.Contains(tc.params,
"=bad"), but comment IDs are random UUIDs. When one started with "bad"
(e.g. offset_id=bad49e60-...), the param string contained "=bad" and the
case was wrongly expected to return 400 while the handler correctly
returned 200, failing the run about 0.2% of the time.

Identify bad-request cases by their error response body instead, which
is deterministic per case and independent of the generated IDs.
This commit is contained in:
Dmitry Verkhoturov
2026-07-11 01:50:36 -05:00
committed by Umputun
parent 8f61ec691b
commit db9d8703ef
+5 -1
View File
@@ -771,8 +771,12 @@ func TestPublic_FindCommentsCtrl_ConsistentCount(t *testing.T) {
t.Run(tc.params, func(t *testing.T) {
url := fmt.Sprintf(ts.URL+"/api/v1/find?site=remark42&%s", tc.params)
body, code := get(t, url)
// bad-request cases are identified by their error response body rather than
// a "=bad" substring of the params: comment IDs are random UUIDs and one
// starting with "bad" (e.g. offset_id=bad49e60-...) would otherwise be
// misread as a bad request, making this test flaky.
expectedStatus := http.StatusOK
if strings.Contains(tc.params, "=bad") {
if strings.Contains(tc.expectedBody, `"error":`) {
expectedStatus = http.StatusBadRequest
}
assert.Equal(t, expectedStatus, code)