Skip to content

Commit ffa4f4b

Browse files
nagoswxiaoguang
andauthored
Check for valid user token in integration tests (#21520)
Added checks for logged user token. Some builds fail at unrelated tests, due to missing token. Example: https://drone.gitea.io/go-gitea/gitea/62011/2/14 Co-authored-by: wxiaoguang <[email protected]>
1 parent 6a03309 commit ffa4f4b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tests/integration/integration_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"os"
1919
"path/filepath"
2020
"strings"
21+
"sync/atomic"
2122
"testing"
2223
"time"
2324

@@ -263,19 +264,19 @@ var tokenCounter int64
263264

264265
func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
265266
t.Helper()
266-
tokenCounter++
267267
req := NewRequest(t, "GET", "/user/settings/applications")
268268
resp := session.MakeRequest(t, req, http.StatusOK)
269269
doc := NewHTMLParser(t, resp.Body)
270270
req = NewRequestWithValues(t, "POST", "/user/settings/applications", map[string]string{
271271
"_csrf": doc.GetCSRF(),
272-
"name": fmt.Sprintf("api-testing-token-%d", tokenCounter),
272+
"name": fmt.Sprintf("api-testing-token-%d", atomic.AddInt64(&tokenCounter, 1)),
273273
})
274274
session.MakeRequest(t, req, http.StatusSeeOther)
275275
req = NewRequest(t, "GET", "/user/settings/applications")
276276
resp = session.MakeRequest(t, req, http.StatusOK)
277277
htmlDoc := NewHTMLParser(t, resp.Body)
278278
token := htmlDoc.doc.Find(".ui.info p").Text()
279+
assert.NotEmpty(t, token)
279280
return token
280281
}
281282

0 commit comments

Comments
 (0)