1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Enable tenv and testifylint rules (#32852)

Enables tenv and testifylint linters
closes: https://github.com/go-gitea/gitea/issues/32842
This commit is contained in:
TheFox0x7
2024-12-15 11:41:29 +01:00
committed by GitHub
parent df9a78cd04
commit 33e8e82c4b
113 changed files with 272 additions and 282 deletions

View File

@@ -133,7 +133,7 @@ func TestActionsArtifactDownload(t *testing.T) {
}
}
assert.NotNil(t, artifactIdx)
assert.Equal(t, listResp.Value[artifactIdx].Name, "artifact-download")
assert.Equal(t, "artifact-download", listResp.Value[artifactIdx].Name)
assert.Contains(t, listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
idx := strings.Index(listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
@@ -374,7 +374,7 @@ func TestActionsArtifactOverwrite(t *testing.T) {
break
}
}
assert.Equal(t, uploadedItem.Name, "artifact-download")
assert.Equal(t, "artifact-download", uploadedItem.Name)
idx := strings.Index(uploadedItem.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
url := uploadedItem.FileContainerResourceURL[idx+1:] + "?itemPath=artifact-download"

View File

@@ -244,7 +244,7 @@ func TestAPIBranchProtection(t *testing.T) {
StatusCheckContexts: []string{"test1"},
}, http.StatusOK)
bp := testAPIGetBranchProtection(t, "master", http.StatusOK)
assert.Equal(t, true, bp.EnableStatusCheck)
assert.True(t, bp.EnableStatusCheck)
assert.Equal(t, []string{"test1"}, bp.StatusCheckContexts)
// disable status checks, clear the list of required checks
@@ -253,7 +253,7 @@ func TestAPIBranchProtection(t *testing.T) {
StatusCheckContexts: []string{},
}, http.StatusOK)
bp = testAPIGetBranchProtection(t, "master", http.StatusOK)
assert.Equal(t, false, bp.EnableStatusCheck)
assert.False(t, bp.EnableStatusCheck)
assert.Equal(t, []string{}, bp.StatusCheckContexts)
testAPIDeleteBranchProtection(t, "master", http.StatusNoContent)

View File

@@ -47,7 +47,7 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
assert.True(t, issueConfig.BlankIssuesEnabled)
assert.Len(t, issueConfig.ContactLinks, 0)
assert.Empty(t, issueConfig.ContactLinks)
})
t.Run("DisableBlankIssues", func(t *testing.T) {
@@ -59,7 +59,7 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
assert.False(t, issueConfig.BlankIssuesEnabled)
assert.Len(t, issueConfig.ContactLinks, 0)
assert.Empty(t, issueConfig.ContactLinks)
})
t.Run("ContactLinks", func(t *testing.T) {
@@ -135,7 +135,7 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
assert.False(t, issueConfig.BlankIssuesEnabled)
assert.Len(t, issueConfig.ContactLinks, 0)
assert.Empty(t, issueConfig.ContactLinks)
_, err = deleteFileInBranch(owner, repo, fullPath, repo.DefaultBranch)
assert.NoError(t, err)

View File

@@ -153,7 +153,7 @@ func TestAPIListPinnedIssues(t *testing.T) {
var issueList []api.Issue
DecodeJSON(t, resp, &issueList)
assert.Equal(t, 1, len(issueList))
assert.Len(t, issueList, 1)
assert.Equal(t, issue.ID, issueList[0].ID)
}
@@ -169,7 +169,7 @@ func TestAPIListPinnedPullrequests(t *testing.T) {
var prList []api.PullRequest
DecodeJSON(t, resp, &prList)
assert.Equal(t, 0, len(prList))
assert.Empty(t, prList)
}
func TestAPINewPinAllowed(t *testing.T) {

View File

@@ -40,7 +40,7 @@ func TestAPIListStopWatches(t *testing.T) {
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
assert.Greater(t, apiWatches[0].Seconds, int64(0))
assert.Positive(t, apiWatches[0].Seconds)
}
}

View File

@@ -252,7 +252,7 @@ func TestAPIEditIssue(t *testing.T) {
assert.Equal(t, api.StateClosed, apiIssue.State)
assert.Equal(t, milestone, apiIssue.Milestone.ID)
assert.Equal(t, body, apiIssue.Body)
assert.True(t, apiIssue.Deadline == nil)
assert.Nil(t, apiIssue.Deadline)
assert.Equal(t, title, apiIssue.Title)
// in database

View File

@@ -168,7 +168,7 @@ func TestCreateUserKey(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Len(t, fingerprintPublicKeys, 0)
assert.Empty(t, fingerprintPublicKeys)
// Fail searching for wrong users key
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/keys?fingerprint=%s", "user2", newPublicKey.Fingerprint)).
@@ -176,7 +176,7 @@ func TestCreateUserKey(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Len(t, fingerprintPublicKeys, 0)
assert.Empty(t, fingerprintPublicKeys)
// Now login as user 2
session2 := loginUser(t, "user2")
@@ -208,5 +208,5 @@ func TestCreateUserKey(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fingerprintPublicKeys)
assert.Len(t, fingerprintPublicKeys, 0)
assert.Empty(t, fingerprintPublicKeys)
}

View File

@@ -120,7 +120,7 @@ func TestAPINotification(t *testing.T) {
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newStruct)
assert.True(t, newStruct.New > 0)
assert.Positive(t, newStruct.New)
// -- mark notifications as read --
req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread").
@@ -154,7 +154,7 @@ func TestAPINotification(t *testing.T) {
AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newStruct)
assert.True(t, newStruct.New == 0)
assert.Zero(t, newStruct.New)
}
func TestAPINotificationPUT(t *testing.T) {

View File

@@ -74,9 +74,9 @@ func testAPIListOAuth2Applications(t *testing.T) {
DecodeJSON(t, resp, &appList)
expectedApp := appList[0]
assert.EqualValues(t, existApp.Name, expectedApp.Name)
assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
assert.EqualValues(t, expectedApp.Name, existApp.Name)
assert.EqualValues(t, expectedApp.ClientID, existApp.ClientID)
assert.Equal(t, expectedApp.ConfidentialClient, existApp.ConfidentialClient)
assert.Len(t, expectedApp.ClientID, 36)
assert.Empty(t, expectedApp.ClientSecret)
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
@@ -128,13 +128,13 @@ func testAPIGetOAuth2Application(t *testing.T) {
DecodeJSON(t, resp, &app)
expectedApp := app
assert.EqualValues(t, existApp.Name, expectedApp.Name)
assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
assert.EqualValues(t, expectedApp.Name, existApp.Name)
assert.EqualValues(t, expectedApp.ClientID, existApp.ClientID)
assert.Equal(t, expectedApp.ConfidentialClient, existApp.ConfidentialClient)
assert.Len(t, expectedApp.ClientID, 36)
assert.Empty(t, expectedApp.ClientSecret)
assert.Len(t, expectedApp.RedirectURIs, 1)
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
assert.EqualValues(t, expectedApp.RedirectURIs[0], existApp.RedirectURIs[0])
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
}

View File

@@ -325,7 +325,7 @@ func TestPackageNpm(t *testing.T) {
pvs, err = packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
assert.NoError(t, err)
assert.Len(t, pvs, 0)
assert.Empty(t, pvs)
})
})
}

View File

@@ -48,7 +48,7 @@ func TestAPIViewPulls(t *testing.T) {
pull := pulls[0]
assert.EqualValues(t, 1, pull.Poster.ID)
assert.Len(t, pull.RequestedReviewers, 2)
assert.Len(t, pull.RequestedReviewersTeams, 0)
assert.Empty(t, pull.RequestedReviewersTeams)
assert.EqualValues(t, 5, pull.RequestedReviewers[0].ID)
assert.EqualValues(t, 6, pull.RequestedReviewers[1].ID)
assert.EqualValues(t, 1, pull.ChangedFiles)
@@ -83,7 +83,7 @@ func TestAPIViewPulls(t *testing.T) {
pull = pulls[1]
assert.EqualValues(t, 1, pull.Poster.ID)
assert.Len(t, pull.RequestedReviewers, 4)
assert.Len(t, pull.RequestedReviewersTeams, 0)
assert.Empty(t, pull.RequestedReviewersTeams)
assert.EqualValues(t, 3, pull.RequestedReviewers[0].ID)
assert.EqualValues(t, 4, pull.RequestedReviewers[1].ID)
assert.EqualValues(t, 2, pull.RequestedReviewers[2].ID)
@@ -120,7 +120,7 @@ func TestAPIViewPulls(t *testing.T) {
pull = pulls[2]
assert.EqualValues(t, 1, pull.Poster.ID)
assert.Len(t, pull.RequestedReviewers, 1)
assert.Len(t, pull.RequestedReviewersTeams, 0)
assert.Empty(t, pull.RequestedReviewersTeams)
assert.EqualValues(t, 1, pull.RequestedReviewers[0].ID)
assert.EqualValues(t, 0, pull.ChangedFiles)

View File

@@ -77,7 +77,7 @@ func TestAPIReposGitCommitList(t *testing.T) {
assert.EqualValues(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[1].CommitMeta.SHA)
compareCommitFiles(t, []string{"test.csv"}, apiData[1].Files)
assert.EqualValues(t, resp.Header().Get("X-Total"), "2")
assert.EqualValues(t, "2", resp.Header().Get("X-Total"))
}
func TestAPIReposGitCommitListNotMaster(t *testing.T) {
@@ -103,7 +103,7 @@ func TestAPIReposGitCommitListNotMaster(t *testing.T) {
assert.EqualValues(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[2].Files)
assert.EqualValues(t, resp.Header().Get("X-Total"), "3")
assert.EqualValues(t, "3", resp.Header().Get("X-Total"))
}
func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
@@ -121,7 +121,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
var apiData []api.Commit
DecodeJSON(t, resp, &apiData)
assert.Len(t, apiData, 0)
assert.Empty(t, apiData)
}
func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
@@ -208,7 +208,7 @@ func TestGetFileHistory(t *testing.T) {
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
assert.EqualValues(t, resp.Header().Get("X-Total"), "1")
assert.EqualValues(t, "1", resp.Header().Get("X-Total"))
}
func TestGetFileHistoryNotOnMaster(t *testing.T) {
@@ -229,5 +229,5 @@ func TestGetFileHistoryNotOnMaster(t *testing.T) {
assert.Equal(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[0].CommitMeta.SHA)
compareCommitFiles(t, []string{"test.csv"}, apiData[0].Files)
assert.EqualValues(t, resp.Header().Get("X-Total"), "1")
assert.EqualValues(t, "1", resp.Header().Get("X-Total"))
}

View File

@@ -176,6 +176,6 @@ func TestAPILFSLocksLogged(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLocks api.LFSLockList
DecodeJSON(t, resp, &lfsLocks)
assert.Len(t, lfsLocks.Locks, 0)
assert.Empty(t, lfsLocks.Locks)
}
}

View File

@@ -39,7 +39,7 @@ func TestAPIRepoTeams(t *testing.T) {
if assert.Len(t, teams, 2) {
assert.EqualValues(t, "Owners", teams[0].Name)
assert.True(t, teams[0].CanCreateOrgRepo)
assert.True(t, util.SliceSortedEqual(unit.AllUnitKeyNames(), teams[0].Units), fmt.Sprintf("%v == %v", unit.AllUnitKeyNames(), teams[0].Units))
assert.True(t, util.SliceSortedEqual(unit.AllUnitKeyNames(), teams[0].Units), "%v == %v", unit.AllUnitKeyNames(), teams[0].Units)
assert.EqualValues(t, "owner", teams[0].Permission)
assert.EqualValues(t, "test_team", teams[1].Name)

View File

@@ -76,7 +76,7 @@ func TestUserOrgs(t *testing.T) {
// unrelated user should not get private org membership of privateMemberUsername
orgs = getUserOrgs(t, unrelatedUsername, privateMemberUsername)
assert.Len(t, orgs, 0)
assert.Empty(t, orgs)
// not authenticated call should not be allowed
testUserOrgsUnauthenticated(t, privateMemberUsername)

View File

@@ -49,7 +49,7 @@ func TestAPIUserSearchLoggedIn(t *testing.T) {
for _, user := range results.Data {
assert.Contains(t, user.UserName, query)
assert.NotEmpty(t, user.Email)
assert.True(t, user.Visibility == "public")
assert.Equal(t, "public", user.Visibility)
}
}
@@ -83,7 +83,7 @@ func TestAPIUserSearchSystemUsers(t *testing.T) {
var results SearchResults
DecodeJSON(t, resp, &results)
assert.NotEmpty(t, results.Data)
if assert.EqualValues(t, 1, len(results.Data)) {
if assert.Len(t, results.Data, 1) {
user := results.Data[0]
assert.EqualValues(t, user.UserName, systemUser.Name)
assert.EqualValues(t, user.ID, systemUser.ID)
@@ -137,7 +137,7 @@ func TestAPIUserSearchByEmail(t *testing.T) {
var results SearchResults
DecodeJSON(t, resp, &results)
assert.Equal(t, 1, len(results.Data))
assert.Len(t, results.Data, 1)
assert.Equal(t, query, results.Data[0].Email)
// no login user can not search user with private email
@@ -155,6 +155,6 @@ func TestAPIUserSearchByEmail(t *testing.T) {
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &results)
assert.Equal(t, 1, len(results.Data))
assert.Len(t, results.Data, 1)
assert.Equal(t, query, results.Data[0].Email)
}

View File

@@ -265,7 +265,7 @@ func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
tr := htmlDoc.doc.Find("table.table tbody tr")
assert.True(t, tr.Length() == 0)
assert.Equal(t, 0, tr.Length())
}
for _, u := range gitLDAPUsers {

View File

@@ -40,10 +40,10 @@ func withKeyFile(t *testing.T, keyname string, callback func(string)) {
assert.NoError(t, err)
// Setup ssh wrapper
os.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
os.Setenv("GIT_SSH_COMMAND",
t.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
t.Setenv("GIT_SSH_COMMAND",
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
os.Setenv("GIT_SSH_VARIANT", "ssh")
t.Setenv("GIT_SSH_VARIANT", "ssh")
callback(keyFile)
}

View File

@@ -6,7 +6,6 @@ package integration
import (
"fmt"
"net/url"
"strings"
"testing"
auth_model "code.gitea.io/gitea/models/auth"
@@ -211,6 +210,6 @@ func TestPushPullRefs(t *testing.T) {
})
assert.Error(t, err)
assert.Empty(t, stdout)
assert.False(t, strings.Contains(stderr, "[deleted]"), "stderr: %s", stderr)
assert.NotContains(t, stderr, "[deleted]", "stderr: %s", stderr)
})
}

View File

@@ -29,10 +29,7 @@ func TestGPGGit(t *testing.T) {
err := os.Chmod(tmpDir, 0o700)
assert.NoError(t, err)
oldGNUPGHome := os.Getenv("GNUPGHOME")
err = os.Setenv("GNUPGHOME", tmpDir)
assert.NoError(t, err)
defer os.Setenv("GNUPGHOME", oldGNUPGHome)
t.Setenv("GNUPGHOME", tmpDir)
// Need to create a root key
rootKeyPair, err := importTestingKey()

View File

@@ -278,7 +278,7 @@ func getTokenForLoggedInUser(t testing.TB, session *TestSession, scopes ...auth.
resp = session.MakeRequest(t, req, http.StatusSeeOther)
// Log the flash values on failure
if !assert.Equal(t, resp.Result().Header["Location"], []string{"/user/settings/applications"}) {
if !assert.Equal(t, []string{"/user/settings/applications"}, resp.Result().Header["Location"]) {
for _, cookie := range resp.Result().Cookies() {
if cookie.Name != gitea_context.CookieNameFlash {
continue
@@ -453,16 +453,16 @@ func VerifyJSONSchema(t testing.TB, resp *httptest.ResponseRecorder, schemaFile
schemaFilePath := filepath.Join(filepath.Dir(setting.AppPath), "tests", "integration", "schemas", schemaFile)
_, schemaFileErr := os.Stat(schemaFilePath)
assert.Nil(t, schemaFileErr)
assert.NoError(t, schemaFileErr)
schema, schemaFileReadErr := os.ReadFile(schemaFilePath)
assert.Nil(t, schemaFileReadErr)
assert.True(t, len(schema) > 0)
assert.NoError(t, schemaFileReadErr)
assert.NotEmpty(t, schema)
nodeinfoSchema := gojsonschema.NewStringLoader(string(schema))
nodeinfoString := gojsonschema.NewStringLoader(resp.Body.String())
result, schemaValidationErr := gojsonschema.Validate(nodeinfoSchema, nodeinfoString)
assert.Nil(t, schemaValidationErr)
assert.NoError(t, schemaValidationErr)
assert.Empty(t, result.Errors())
assert.True(t, result.Valid())
}

View File

@@ -59,7 +59,7 @@ func initMigrationTest(t *testing.T) func() {
unittest.InitSettings()
assert.True(t, len(setting.RepoRootPath) != 0)
assert.NotEmpty(t, setting.RepoRootPath)
assert.NoError(t, unittest.SyncDirs(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
assert.NoError(t, git.InitFull(context.Background()))
setting.LoadDBSetting()

View File

@@ -78,7 +78,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
assert.True(t, doRemovePushMirror(t, session, user.Name, srcRepo.Name, mirrors[0].ID))
mirrors, _, err = repo_model.GetPushMirrorsByRepoID(db.DefaultContext, srcRepo.ID, db.ListOptions{})
assert.NoError(t, err)
assert.Len(t, mirrors, 0)
assert.Empty(t, mirrors)
}
func testCreatePushMirror(t *testing.T, session *TestSession, owner, repo, address, username, password, interval string) {

View File

@@ -89,7 +89,7 @@ func TestAuthorizeRedirectWithExistingGrant(t *testing.T) {
u, err := resp.Result().Location()
assert.NoError(t, err)
assert.Equal(t, "thestate", u.Query().Get("state"))
assert.Truef(t, len(u.Query().Get("code")) > 30, "authorization code '%s' should be longer then 30", u.Query().Get("code"))
assert.Greaterf(t, len(u.Query().Get("code")), 30, "authorization code '%s' should be longer then 30", u.Query().Get("code"))
u.RawQuery = ""
assert.Equal(t, "https://example.com/xyzzy", u.String())
}
@@ -125,8 +125,8 @@ func TestAccessTokenExchange(t *testing.T) {
parsed := new(response)
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
assert.Greater(t, len(parsed.AccessToken), 10)
assert.Greater(t, len(parsed.RefreshToken), 10)
}
func TestAccessTokenExchangeWithPublicClient(t *testing.T) {
@@ -148,8 +148,8 @@ func TestAccessTokenExchangeWithPublicClient(t *testing.T) {
parsed := new(response)
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
assert.Greater(t, len(parsed.AccessToken), 10)
assert.Greater(t, len(parsed.RefreshToken), 10)
}
func TestAccessTokenExchangeJSON(t *testing.T) {
@@ -172,8 +172,8 @@ func TestAccessTokenExchangeJSON(t *testing.T) {
parsed := new(response)
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
assert.Greater(t, len(parsed.AccessToken), 10)
assert.Greater(t, len(parsed.RefreshToken), 10)
}
func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
@@ -289,8 +289,8 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
parsed := new(response)
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
assert.Greater(t, len(parsed.AccessToken), 10)
assert.Greater(t, len(parsed.RefreshToken), 10)
// use wrong client_secret
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
@@ -449,8 +449,8 @@ func TestOAuthIntrospection(t *testing.T) {
parsed := new(response)
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
assert.Greater(t, len(parsed.AccessToken), 10)
assert.Greater(t, len(parsed.RefreshToken), 10)
// successful request with a valid client_id/client_secret and a valid token
req = NewRequestWithValues(t, "POST", "/login/oauth/introspect", map[string]string{

View File

@@ -130,7 +130,7 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
calcOrgCounts[org.LowerName] = org.NumRepos
count, ok := canonicalCounts[org.LowerName]
if ok {
assert.True(t, count == org.NumRepos, "Number of Repos in %s is %d when we expected %d", org.Name, org.NumRepos, count)
assert.Equal(t, count, org.NumRepos, "Number of Repos in %s is %d when we expected %d", org.Name, org.NumRepos, count)
} else {
assert.False(t, strict, "Did not expect to see %s with count %d", org.Name, org.NumRepos)
}

View File

@@ -40,7 +40,7 @@ func TestPullCompare(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body)
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
assert.Greater(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")
onGiteaRun(t, func(t *testing.T, u *url.URL) {
defer tests.PrepareTestEnv(t)()
@@ -58,7 +58,7 @@ func TestPullCompare(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body)
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
assert.Greater(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")
repoForked := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1"})
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
@@ -71,7 +71,7 @@ func TestPullCompare(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
doc = NewHTMLParser(t, resp.Body)
editButtonCount = doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
assert.EqualValues(t, editButtonCount, 0, "Expected not to find a button to edit a file in the PR diff view because head repository has been deleted")
assert.EqualValues(t, 0, editButtonCount, "Expected not to find a button to edit a file in the PR diff view because head repository has been deleted")
})
}

View File

@@ -661,7 +661,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) {
searchIssuesResp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
var apiIssuesBefore []*api.Issue
DecodeJSON(t, searchIssuesResp, &apiIssuesBefore)
assert.Len(t, apiIssuesBefore, 0)
assert.Empty(t, apiIssuesBefore)
// merge the pull request
elem := strings.Split(test.RedirectURL(createPullResp), "/")

View File

@@ -29,5 +29,5 @@ func TestRepoDownloadArchive(t *testing.T) {
bs, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
assert.Empty(t, resp.Header().Get("Content-Encoding"))
assert.Equal(t, 320, len(bs))
assert.Len(t, bs, 320)
}

View File

@@ -43,7 +43,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO
link, exists = htmlDoc.doc.Find(`form.ui.form[action*="/fork"]`).Attr("action")
assert.True(t, exists, "The template has changed")
_, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", forkOwner.ID)).Attr("data-value")
assert.True(t, exists, fmt.Sprintf("Fork owner '%s' is not present in select box", forkOwnerName))
assert.True(t, exists, "Fork owner '%s' is not present in select box", forkOwnerName)
req = NewRequestWithValues(t, "POST", link, map[string]string{
"_csrf": htmlDoc.GetCSRF(),
"uid": fmt.Sprintf("%d", forkOwner.ID),

View File

@@ -41,7 +41,7 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateID, templateOw
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/create\"]").Attr("action")
assert.True(t, exists, "The template has changed")
_, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", generateOwner.ID)).Attr("data-value")
assert.True(t, exists, fmt.Sprintf("Generate owner '%s' is not present in select box", generateOwnerName))
assert.True(t, exists, "Generate owner '%s' is not present in select box", generateOwnerName)
req = NewRequestWithValues(t, "POST", link, map[string]string{
"_csrf": htmlDoc.GetCSRF(),
"uid": fmt.Sprintf("%d", generateOwner.ID),

View File

@@ -228,7 +228,7 @@ func TestViewRepoDirectory(t *testing.T) {
repoSummary := htmlDoc.doc.Find(".repository-summary")
repoFilesTable := htmlDoc.doc.Find("#repo-files-table")
assert.NotZero(t, len(repoFilesTable.Nodes))
assert.NotEmpty(t, repoFilesTable.Nodes)
assert.Zero(t, description.Length())
assert.Zero(t, repoTopics.Length())

View File

@@ -28,10 +28,10 @@ func Test_RegenerateSession(t *testing.T) {
sess, err := auth.RegenerateSession(db.DefaultContext, "", key)
assert.NoError(t, err)
assert.EqualValues(t, key, sess.Key)
assert.Len(t, sess.Data, 0)
assert.Empty(t, sess.Data)
sess, err = auth.ReadSession(db.DefaultContext, key2)
assert.NoError(t, err)
assert.EqualValues(t, key2, sess.Key)
assert.Len(t, sess.Data, 0)
assert.Empty(t, sess.Data)
}

View File

@@ -255,7 +255,7 @@ func TestListStopWatches(t *testing.T) {
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
assert.Greater(t, apiWatches[0].Seconds, int64(0))
assert.Positive(t, apiWatches[0].Seconds)
}
}