mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
Use more specific test methods (#24265)
Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
@ -123,7 +123,7 @@ func TestAPIListUsers(t *testing.T) {
|
||||
}
|
||||
assert.True(t, found)
|
||||
numberOfUsers := unittest.GetCount(t, &user_model.User{}, "type = 0")
|
||||
assert.Equal(t, numberOfUsers, len(users))
|
||||
assert.Len(t, users, numberOfUsers)
|
||||
}
|
||||
|
||||
func TestAPIListUsersNotLoggedIn(t *testing.T) {
|
||||
|
@ -68,7 +68,7 @@ func TestAPIListCommentAttachments(t *testing.T) {
|
||||
var apiAttachments []*api.Attachment
|
||||
DecodeJSON(t, resp, &apiAttachments)
|
||||
expectedCount := unittest.GetCount(t, &repo_model.Attachment{CommentID: comment.ID})
|
||||
assert.EqualValues(t, expectedCount, len(apiAttachments))
|
||||
assert.Len(t, apiAttachments, expectedCount)
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachments[0].ID, CommentID: comment.ID})
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func TestAPIListIssueComments(t *testing.T) {
|
||||
DecodeJSON(t, resp, &comments)
|
||||
expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID},
|
||||
unittest.Cond("type = ?", issues_model.CommentTypeComment))
|
||||
assert.EqualValues(t, expectedCount, len(comments))
|
||||
assert.Len(t, comments, expectedCount)
|
||||
}
|
||||
|
||||
func TestAPICreateComment(t *testing.T) {
|
||||
@ -196,5 +196,5 @@ func TestAPIListIssueTimeline(t *testing.T) {
|
||||
var comments []*api.TimelineComment
|
||||
DecodeJSON(t, resp, &comments)
|
||||
expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID})
|
||||
assert.EqualValues(t, expectedCount, len(comments))
|
||||
assert.Len(t, comments, expectedCount)
|
||||
}
|
||||
|
@ -48,5 +48,5 @@ func TestAPIReposValidateDefaultIssueConfig(t *testing.T) {
|
||||
DecodeJSON(t, resp, &issueConfigValidation)
|
||||
|
||||
assert.True(t, issueConfigValidation.Valid)
|
||||
assert.Equal(t, issueConfigValidation.Message, "")
|
||||
assert.Empty(t, issueConfigValidation.Message)
|
||||
}
|
||||
|
@ -170,8 +170,8 @@ func TestAPIPullReview(t *testing.T) {
|
||||
DecodeJSON(t, resp, &commentReview)
|
||||
assert.EqualValues(t, "COMMENT", commentReview.State)
|
||||
assert.EqualValues(t, 2, commentReview.CodeCommentsCount)
|
||||
assert.EqualValues(t, "", commentReview.Body)
|
||||
assert.EqualValues(t, false, commentReview.Dismissed)
|
||||
assert.Empty(t, commentReview.Body)
|
||||
assert.False(t, commentReview.Dismissed)
|
||||
|
||||
// test CreatePullReview Comment with body but without comments
|
||||
commentBody := "This is a body of the comment."
|
||||
@ -186,7 +186,7 @@ func TestAPIPullReview(t *testing.T) {
|
||||
assert.EqualValues(t, "COMMENT", commentReview.State)
|
||||
assert.EqualValues(t, 0, commentReview.CodeCommentsCount)
|
||||
assert.EqualValues(t, commentBody, commentReview.Body)
|
||||
assert.EqualValues(t, false, commentReview.Dismissed)
|
||||
assert.False(t, commentReview.Dismissed)
|
||||
|
||||
// test CreatePullReview Comment without body and no comments
|
||||
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{
|
||||
|
@ -49,12 +49,12 @@ func TestAPIViewPulls(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("APIGetPullFiles_%d", pull.ID),
|
||||
doAPIGetPullFiles(ctx, pull, func(t *testing.T, files []*api.ChangedFile) {
|
||||
if assert.Len(t, files, 1) {
|
||||
assert.EqualValues(t, "File-WoW", files[0].Filename)
|
||||
assert.EqualValues(t, "", files[0].PreviousFilename)
|
||||
assert.Equal(t, "File-WoW", files[0].Filename)
|
||||
assert.Empty(t, files[0].PreviousFilename)
|
||||
assert.EqualValues(t, 1, files[0].Additions)
|
||||
assert.EqualValues(t, 1, files[0].Changes)
|
||||
assert.EqualValues(t, 0, files[0].Deletions)
|
||||
assert.EqualValues(t, "added", files[0].Status)
|
||||
assert.Equal(t, "added", files[0].Status)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
@ -32,21 +32,21 @@ func TestAPIDownloadArchive(t *testing.T) {
|
||||
resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
||||
bs, err := io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 320, len(bs))
|
||||
assert.Len(t, bs, 320)
|
||||
|
||||
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name))
|
||||
link.RawQuery = url.Values{"token": {token}}.Encode()
|
||||
resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
||||
bs, err = io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 266, len(bs))
|
||||
assert.Len(t, bs, 266)
|
||||
|
||||
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name))
|
||||
link.RawQuery = url.Values{"token": {token}}.Encode()
|
||||
resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
||||
bs, err = io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 382, len(bs))
|
||||
assert.Len(t, bs, 382)
|
||||
|
||||
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
|
||||
link.RawQuery = url.Values{"token": {token}}.Encode()
|
||||
|
@ -194,10 +194,10 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
// check repo1 was written to database
|
||||
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
|
||||
assert.Equal(t, *repo1editedOption.HasIssues, true)
|
||||
assert.True(t, *repo1editedOption.HasIssues)
|
||||
assert.Nil(t, repo1editedOption.ExternalTracker)
|
||||
assert.Equal(t, *repo1editedOption.InternalTracker, *repoEditOption.InternalTracker)
|
||||
assert.Equal(t, *repo1editedOption.HasWiki, true)
|
||||
assert.True(t, *repo1editedOption.HasWiki)
|
||||
assert.Nil(t, repo1editedOption.ExternalWiki)
|
||||
|
||||
// Test editing repo1 to use external issue and wiki
|
||||
@ -216,9 +216,9 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
// check repo1 was written to database
|
||||
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
|
||||
assert.Equal(t, *repo1editedOption.HasIssues, true)
|
||||
assert.True(t, *repo1editedOption.HasIssues)
|
||||
assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker)
|
||||
assert.Equal(t, *repo1editedOption.HasWiki, true)
|
||||
assert.True(t, *repo1editedOption.HasWiki)
|
||||
assert.Equal(t, *repo1editedOption.ExternalWiki, *repoEditOption.ExternalWiki)
|
||||
|
||||
repoEditOption.ExternalTracker.ExternalTrackerStyle = "regexp"
|
||||
@ -229,7 +229,7 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
assert.NotNil(t, repo)
|
||||
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
|
||||
assert.Equal(t, *repo1editedOption.HasIssues, true)
|
||||
assert.True(t, *repo1editedOption.HasIssues)
|
||||
assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker)
|
||||
|
||||
// Do some tests with invalid URL for external tracker and wiki
|
||||
@ -259,9 +259,9 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
|
||||
assert.Equal(t, *repo1editedOption.Description, *repoEditOption.Description)
|
||||
assert.Equal(t, *repo1editedOption.HasIssues, true)
|
||||
assert.True(t, *repo1editedOption.HasIssues)
|
||||
assert.NotNil(t, *repo1editedOption.ExternalTracker)
|
||||
assert.Equal(t, *repo1editedOption.HasWiki, true)
|
||||
assert.True(t, *repo1editedOption.HasWiki)
|
||||
assert.NotNil(t, *repo1editedOption.ExternalWiki)
|
||||
|
||||
// reset repo in db
|
||||
|
@ -412,7 +412,7 @@ func TestAPIMirrorSyncNonMirrorRepo(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &repo)
|
||||
assert.EqualValues(t, false, repo.Mirror)
|
||||
assert.False(t, repo.Mirror)
|
||||
|
||||
req = NewRequestf(t, "POST", "/api/v1/repos/user2/repo1/mirror-sync?token=%s", token)
|
||||
resp = MakeRequest(t, req, http.StatusBadRequest)
|
||||
@ -469,7 +469,7 @@ func testAPIRepoCreateConflict(t *testing.T, u *url.URL) {
|
||||
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
|
||||
respJSON := map[string]string{}
|
||||
DecodeJSON(t, resp, &respJSON)
|
||||
assert.Equal(t, respJSON["message"], "The repository with the same name already exists.")
|
||||
assert.Equal(t, "The repository with the same name already exists.", respJSON["message"])
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ func TestLDAPAuthChange(t *testing.T) {
|
||||
host, _ := doc.Find(`input[name="host"]`).Attr("value")
|
||||
assert.Equal(t, host, getLDAPServerHost())
|
||||
binddn, _ := doc.Find(`input[name="bind_dn"]`).Attr("value")
|
||||
assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com")
|
||||
assert.Equal(t, "uid=gitea,ou=service,dc=planetexpress,dc=com", binddn)
|
||||
|
||||
req = NewRequestWithValues(t, "POST", href, buildAuthSourceLDAPPayload(csrf, "", "", "", "off"))
|
||||
session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
@ -214,7 +214,7 @@ func TestLDAPAuthChange(t *testing.T) {
|
||||
host, _ = doc.Find(`input[name="host"]`).Attr("value")
|
||||
assert.Equal(t, host, getLDAPServerHost())
|
||||
binddn, _ = doc.Find(`input[name="bind_dn"]`).Attr("value")
|
||||
assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com")
|
||||
assert.Equal(t, "uid=gitea,ou=service,dc=planetexpress,dc=com", binddn)
|
||||
}
|
||||
|
||||
func TestLDAPUserSync(t *testing.T) {
|
||||
@ -397,8 +397,8 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
if user.Name == "fry" || user.Name == "leela" || user.Name == "bender" {
|
||||
// assert members of LDAP group "cn=ship_crew" are added to mapped teams
|
||||
assert.Equal(t, len(usersOrgs), 1, "User [%s] should be member of one organization", user.Name)
|
||||
assert.Equal(t, usersOrgs[0].Name, "org26", "Membership should be added to the right organization")
|
||||
assert.Len(t, usersOrgs, 1, "User [%s] should be member of one organization", user.Name)
|
||||
assert.Equal(t, "org26", usersOrgs[0].Name, "Membership should be added to the right organization")
|
||||
isMember, err := organization.IsTeamMember(db.DefaultContext, usersOrgs[0].ID, team.ID, user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, isMember, "Membership should be added to the right team")
|
||||
|
@ -19,5 +19,5 @@ func TestCORSNotSet(t *testing.T) {
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
assert.Equal(t, resp.Code, http.StatusOK)
|
||||
corsHeader := resp.Header().Get("Access-Control-Allow-Origin")
|
||||
assert.Equal(t, corsHeader, "", "Access-Control-Allow-Origin: generated header should match") // header not set
|
||||
assert.Empty(t, corsHeader, "Access-Control-Allow-Origin: generated header should match") // header not set
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func TestEmptyRepoAddFile(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`)
|
||||
assert.Equal(t, "", doc.AttrOr("checked", "_no_"))
|
||||
assert.Empty(t, doc.AttrOr("checked", "_no_"))
|
||||
req = NewRequestWithValues(t, "POST", "/user30/empty/_new/"+setting.Repository.DefaultBranch, map[string]string{
|
||||
"_csrf": GetCSRF(t, session, "/user/settings"),
|
||||
"commit_choice": "direct",
|
||||
@ -76,7 +76,7 @@ func TestEmptyRepoUploadFile(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`)
|
||||
assert.Equal(t, "", doc.AttrOr("checked", "_no_"))
|
||||
assert.Empty(t, doc.AttrOr("checked", "_no_"))
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
mpForm := multipart.NewWriter(body)
|
||||
|
@ -763,7 +763,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
||||
return
|
||||
}
|
||||
assert.Equal(t, "user2/"+headBranch, pr1.HeadBranch)
|
||||
assert.Equal(t, false, prMsg.HasMerged)
|
||||
assert.False(t, prMsg.HasMerged)
|
||||
assert.Contains(t, "Testing commit 1", prMsg.Body)
|
||||
assert.Equal(t, commit, prMsg.Head.Sha)
|
||||
|
||||
@ -785,7 +785,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
||||
return
|
||||
}
|
||||
assert.Equal(t, "user2/test/"+headBranch, pr2.HeadBranch)
|
||||
assert.Equal(t, false, prMsg.HasMerged)
|
||||
assert.False(t, prMsg.HasMerged)
|
||||
})
|
||||
|
||||
if pr1 == nil || pr2 == nil {
|
||||
@ -829,7 +829,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, false, prMsg.HasMerged)
|
||||
assert.False(t, prMsg.HasMerged)
|
||||
assert.Equal(t, commit, prMsg.Head.Sha)
|
||||
|
||||
_, _, err = git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/test/" + headBranch).RunStdString(&git.RunOpts{Dir: dstPath})
|
||||
@ -841,7 +841,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, false, prMsg.HasMerged)
|
||||
assert.False(t, prMsg.HasMerged)
|
||||
assert.Equal(t, commit, prMsg.Head.Sha)
|
||||
})
|
||||
t.Run("Merge", doAPIMergePullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index))
|
||||
|
@ -414,7 +414,7 @@ func TestConflictChecking(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Ensure conflictedFiles is populated.
|
||||
assert.Equal(t, 1, len(conflictingPR.ConflictedFiles))
|
||||
assert.Len(t, conflictingPR.ConflictedFiles, 1)
|
||||
// Check if status is correct.
|
||||
assert.Equal(t, issues_model.PullRequestStatusConflict, conflictingPR.Status)
|
||||
// Ensure that mergeable returns false
|
||||
|
@ -376,7 +376,7 @@ func TestMarkDownReadmeImage(t *testing.T) {
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
src, exists := htmlDoc.doc.Find(`.markdown img`).Attr("src")
|
||||
assert.True(t, exists, "Image not found in README")
|
||||
assert.Equal(t, src, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg")
|
||||
assert.Equal(t, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg", src)
|
||||
|
||||
req = NewRequest(t, "GET", "/user2/repo1/src/branch/home-md-img-check/README.md")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
@ -384,7 +384,7 @@ func TestMarkDownReadmeImage(t *testing.T) {
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
src, exists = htmlDoc.doc.Find(`.markdown img`).Attr("src")
|
||||
assert.True(t, exists, "Image not found in markdown file")
|
||||
assert.Equal(t, src, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg")
|
||||
assert.Equal(t, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg", src)
|
||||
}
|
||||
|
||||
func TestMarkDownReadmeImageSubfolder(t *testing.T) {
|
||||
@ -399,7 +399,7 @@ func TestMarkDownReadmeImageSubfolder(t *testing.T) {
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
src, exists := htmlDoc.doc.Find(`.markdown img`).Attr("src")
|
||||
assert.True(t, exists, "Image not found in README")
|
||||
assert.Equal(t, src, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg")
|
||||
assert.Equal(t, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg", src)
|
||||
|
||||
req = NewRequest(t, "GET", "/user2/repo1/src/branch/sub-home-md-img-check/docs/README.md")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
@ -407,5 +407,5 @@ func TestMarkDownReadmeImageSubfolder(t *testing.T) {
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
src, exists = htmlDoc.doc.Find(`.markdown img`).Attr("src")
|
||||
assert.True(t, exists, "Image not found in markdown file")
|
||||
assert.Equal(t, src, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg")
|
||||
assert.Equal(t, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg", src)
|
||||
}
|
||||
|
Reference in New Issue
Block a user