From c1be31dd3c8ef68ab35e3c52bfbdaad8b0cbebdc Mon Sep 17 00:00:00 2001 From: Vladimir Yakovlev Date: Thu, 20 Oct 2022 21:20:01 +0300 Subject: [PATCH] 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 --- integrations/integration_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integrations/integration_test.go b/integrations/integration_test.go index b0004927f7b5..3117587f4285 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -21,6 +21,7 @@ import ( "path/filepath" "runtime" "strings" + "sync/atomic" "testing" "time" @@ -430,19 +431,19 @@ var tokenCounter int64 func getTokenForLoggedInUser(t testing.TB, session *TestSession) string { t.Helper() - tokenCounter++ req := NewRequest(t, "GET", "/user/settings/applications") resp := session.MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body) req = NewRequestWithValues(t, "POST", "/user/settings/applications", map[string]string{ "_csrf": doc.GetCSRF(), - "name": fmt.Sprintf("api-testing-token-%d", tokenCounter), + "name": fmt.Sprintf("api-testing-token-%d", atomic.AddInt64(&tokenCounter, 1)), }) resp = session.MakeRequest(t, req, http.StatusSeeOther) req = NewRequest(t, "GET", "/user/settings/applications") resp = session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) token := htmlDoc.doc.Find(".ui.info p").Text() + assert.NotEmpty(t, token) return token }