mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-23 00:21:53 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// This is primarily coped from /tests/integration/integration_test.go
|
||||
// TODO: Move common functions to shared file
|
||||
|
||||
//nolint:forbidigo
|
||||
package e2e
|
||||
|
||||
import (
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ref: refs/heads/main
|
||||
@@ -0,0 +1,4 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
@@ -0,0 +1 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
||||
@@ -0,0 +1,6 @@
|
||||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+2
@@ -0,0 +1,2 @@
|
||||
x•ŽA
|
||||
Ă »öîĹoŚšRJŻňŐ÷i 6Áčń›+t;0ĂäµÖąkKńŇ ‹ 1�¤4şÂdś�5$aoŮg;©Ť>]St6FŚśERNČ›4MgeHd‹0'V|ô÷Úô±Ł‘~p)
|
||||
BIN
Binary file not shown.
@@ -0,0 +1 @@
|
||||
7197b56fdc75b453f47c9110938cb46a303579fd
|
||||
@@ -0,0 +1 @@
|
||||
a8a700e8c644c783ba2c6e742bb81bf91e244bff
|
||||
@@ -0,0 +1 @@
|
||||
a8a700e8c644c783ba2c6e742bb81bf91e244bff
|
||||
@@ -0,0 +1 @@
|
||||
cef06e48f2642cd0dc9597b4bea09f4b3f74aad6
|
||||
@@ -0,0 +1 @@
|
||||
7197b56fdc75b453f47c9110938cb46a303579fd
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ import (
|
||||
"testing"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
org_model "code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -51,6 +55,22 @@ func TestAPIOrgCreate(t *testing.T) {
|
||||
FullName: org.FullName,
|
||||
})
|
||||
|
||||
// Check owner team permission
|
||||
ownerTeam, _ := org_model.GetOwnerTeam(db.DefaultContext, apiOrg.ID)
|
||||
|
||||
for _, ut := range unit_model.AllRepoUnitTypes {
|
||||
up := perm.AccessModeOwner
|
||||
if ut == unit_model.TypeExternalTracker || ut == unit_model.TypeExternalWiki {
|
||||
up = perm.AccessModeRead
|
||||
}
|
||||
unittest.AssertExistsAndLoadBean(t, &org_model.TeamUnit{
|
||||
OrgID: apiOrg.ID,
|
||||
TeamID: ownerTeam.ID,
|
||||
Type: ut,
|
||||
AccessMode: up,
|
||||
})
|
||||
}
|
||||
|
||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s?token=%s", org.UserName, token)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiOrg)
|
||||
@@ -127,16 +147,14 @@ func TestAPIOrgDeny(t *testing.T) {
|
||||
setting.Service.RequireSignInView = false
|
||||
}()
|
||||
|
||||
token := getUserToken(t, "user1", auth_model.AccessTokenScopeReadOrg)
|
||||
|
||||
orgName := "user1_org"
|
||||
req := NewRequestf(t, "GET", "/api/v1/orgs/%s?token=%s", orgName, token)
|
||||
req := NewRequestf(t, "GET", "/api/v1/orgs/%s", orgName)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token=%s", orgName, token)
|
||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/repos", orgName)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/members?token=%s", orgName, token)
|
||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/members", orgName)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
@@ -146,16 +164,24 @@ func TestAPIGetAll(t *testing.T) {
|
||||
|
||||
token := getUserToken(t, "user1", auth_model.AccessTokenScopeReadOrg)
|
||||
|
||||
// accessing with a token will return all orgs
|
||||
req := NewRequestf(t, "GET", "/api/v1/orgs?token=%s", token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var apiOrgList []*api.Organization
|
||||
DecodeJSON(t, resp, &apiOrgList)
|
||||
|
||||
// accessing with a token will return all orgs
|
||||
DecodeJSON(t, resp, &apiOrgList)
|
||||
assert.Len(t, apiOrgList, 9)
|
||||
assert.Equal(t, "org25", apiOrgList[1].FullName)
|
||||
assert.Equal(t, "public", apiOrgList[1].Visibility)
|
||||
|
||||
// accessing without a token will return only public orgs
|
||||
req = NewRequestf(t, "GET", "/api/v1/orgs")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
DecodeJSON(t, resp, &apiOrgList)
|
||||
assert.Len(t, apiOrgList, 7)
|
||||
assert.Equal(t, "org25", apiOrgList[0].FullName)
|
||||
assert.Equal(t, "public", apiOrgList[0].Visibility)
|
||||
}
|
||||
|
||||
func TestAPIOrgSearchEmptyTeam(t *testing.T) {
|
||||
|
||||
@@ -120,7 +120,7 @@ description: ` + packageDescription
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(len(content)), pb.Size)
|
||||
|
||||
resp = uploadFile(t, result.URL, content, http.StatusBadRequest)
|
||||
_ = uploadFile(t, result.URL, content, http.StatusBadRequest)
|
||||
})
|
||||
|
||||
t.Run("Download", func(t *testing.T) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -82,9 +82,9 @@ func TestAPISearchRepo(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 31},
|
||||
user: {count: 31},
|
||||
user2: {count: 31},
|
||||
nil: {count: 32},
|
||||
user: {count: 32},
|
||||
user2: {count: 32},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -183,18 +183,17 @@ func TestAPISearchRepo(t *testing.T) {
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
for userToLogin, expected := range testCase.expectedResults {
|
||||
var session *TestSession
|
||||
var testName string
|
||||
var userID int64
|
||||
var token string
|
||||
if userToLogin != nil && userToLogin.ID > 0 {
|
||||
testName = fmt.Sprintf("LoggedUser%d", userToLogin.ID)
|
||||
session = loginUser(t, userToLogin.Name)
|
||||
session := loginUser(t, userToLogin.Name)
|
||||
token = getTokenForLoggedInUser(t, session)
|
||||
userID = userToLogin.ID
|
||||
} else {
|
||||
testName = "AnonymousUser"
|
||||
session = emptyTestSession(t)
|
||||
_ = emptyTestSession(t)
|
||||
}
|
||||
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
@@ -413,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)
|
||||
@@ -470,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
|
||||
}
|
||||
|
||||
@@ -4,12 +4,19 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -17,7 +24,7 @@ import (
|
||||
|
||||
func TestEmptyRepo(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
subpaths := []string{
|
||||
subPaths := []string{
|
||||
"commits/master",
|
||||
"raw/foo",
|
||||
"commit/1ae57b34ccf7e18373",
|
||||
@@ -26,8 +33,75 @@ func TestEmptyRepo(t *testing.T) {
|
||||
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5})
|
||||
assert.True(t, emptyRepo.IsEmpty)
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: emptyRepo.OwnerID})
|
||||
for _, subpath := range subpaths {
|
||||
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subpath)
|
||||
for _, subPath := range subPaths {
|
||||
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subPath)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyRepoAddFile(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
err := user_model.UpdateUserCols(db.DefaultContext, &user_model.User{ID: 30, ProhibitLogin: false}, "prohibit_login")
|
||||
assert.NoError(t, err)
|
||||
|
||||
session := loginUser(t, "user30")
|
||||
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.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",
|
||||
"tree_path": "test-file.md",
|
||||
"content": "newly-added-test-file",
|
||||
})
|
||||
|
||||
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
redirect := test.RedirectURL(resp)
|
||||
assert.Equal(t, "/user30/empty/src/branch/"+setting.Repository.DefaultBranch+"/test-file.md", redirect)
|
||||
|
||||
req = NewRequest(t, "GET", redirect)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
assert.Contains(t, resp.Body.String(), "newly-added-test-file")
|
||||
}
|
||||
|
||||
func TestEmptyRepoUploadFile(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
err := user_model.UpdateUserCols(db.DefaultContext, &user_model.User{ID: 30, ProhibitLogin: false}, "prohibit_login")
|
||||
assert.NoError(t, err)
|
||||
|
||||
session := loginUser(t, "user30")
|
||||
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.Empty(t, doc.AttrOr("checked", "_no_"))
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
mpForm := multipart.NewWriter(body)
|
||||
_ = mpForm.WriteField("_csrf", GetCSRF(t, session, "/user/settings"))
|
||||
file, _ := mpForm.CreateFormFile("file", "uploaded-file.txt")
|
||||
_, _ = io.Copy(file, bytes.NewBufferString("newly-uploaded-test-file"))
|
||||
_ = mpForm.Close()
|
||||
|
||||
req = NewRequestWithBody(t, "POST", "/user30/empty/upload-file", body)
|
||||
req.Header.Add("Content-Type", mpForm.FormDataContentType())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
respMap := map[string]string{}
|
||||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &respMap))
|
||||
|
||||
req = NewRequestWithValues(t, "POST", "/user30/empty/_upload/"+setting.Repository.DefaultBranch, map[string]string{
|
||||
"_csrf": GetCSRF(t, session, "/user/settings"),
|
||||
"commit_choice": "direct",
|
||||
"files": respMap["uuid"],
|
||||
"tree_path": "",
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
redirect := test.RedirectURL(resp)
|
||||
assert.Equal(t, "/user30/empty/src/branch/"+setting.Repository.DefaultBranch+"/", redirect)
|
||||
|
||||
req = NewRequest(t, "GET", redirect)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
assert.Contains(t, resp.Body.String(), "uploaded-file.txt")
|
||||
}
|
||||
|
||||
@@ -807,7 +807,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)
|
||||
|
||||
@@ -829,7 +829,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 {
|
||||
@@ -873,7 +873,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})
|
||||
@@ -885,7 +885,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))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//nolint:forbidigo
|
||||
package integration
|
||||
|
||||
import (
|
||||
@@ -124,6 +125,9 @@ func TestMain(m *testing.M) {
|
||||
fmt.Printf("Error initializing test database: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// FIXME: the console logger is deleted by mistake, so if there is any `log.Fatal`, developers won't see any error message.
|
||||
// Instead, "No tests were found", last nonsense log is "According to the configuration, subsequent logs will not be printed to the console"
|
||||
exitCode := m.Run()
|
||||
|
||||
tests.WriterCloser.Reset()
|
||||
@@ -366,10 +370,12 @@ const NoExpectedStatus = -1
|
||||
func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
recorder := httptest.NewRecorder()
|
||||
if req.RemoteAddr == "" {
|
||||
req.RemoteAddr = "test-mock:12345"
|
||||
}
|
||||
c.ServeHTTP(recorder, req)
|
||||
if expectedStatus != NoExpectedStatus {
|
||||
if !assert.EqualValues(t, expectedStatus, recorder.Code,
|
||||
"Request: %s %s", req.Method, req.URL.String()) {
|
||||
if !assert.EqualValues(t, expectedStatus, recorder.Code, "Request: %s %s", req.Method, req.URL.String()) {
|
||||
logUnexpectedResponse(t, recorder)
|
||||
}
|
||||
}
|
||||
@@ -410,8 +416,10 @@ func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
|
||||
return
|
||||
} else if len(respBytes) < 500 {
|
||||
// if body is short, just log the whole thing
|
||||
t.Log("Response:", string(respBytes))
|
||||
t.Log("Response: ", string(respBytes))
|
||||
return
|
||||
} else {
|
||||
t.Log("Response length: ", len(respBytes))
|
||||
}
|
||||
|
||||
// log the "flash" error message, if one exists
|
||||
|
||||
@@ -22,7 +22,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch, titl
|
||||
|
||||
// Click the PR button to create a pull
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
link, exists := htmlDoc.doc.Find("#new-pull-request").Parent().Attr("href")
|
||||
link, exists := htmlDoc.doc.Find("#new-pull-request").Attr("href")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
if branch != "master" {
|
||||
link = strings.Replace(link, ":master", ":"+branch, 1)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -134,7 +134,7 @@ func TestCreateReleasePaging(t *testing.T) {
|
||||
func TestViewReleaseListNoLogin(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 57, OwnerName: "user2", LowerName: "repo-release"})
|
||||
|
||||
link := repo.Link() + "/releases"
|
||||
|
||||
@@ -143,18 +143,43 @@ func TestViewReleaseListNoLogin(t *testing.T) {
|
||||
|
||||
htmlDoc := NewHTMLParser(t, rsp.Body)
|
||||
releases := htmlDoc.Find("#release-list li.ui.grid")
|
||||
assert.Equal(t, 2, releases.Length())
|
||||
assert.Equal(t, 3, releases.Length())
|
||||
|
||||
links := make([]string, 0, 5)
|
||||
links := make([]string, 0, 3)
|
||||
commitsToMain := make([]string, 0, 3)
|
||||
releases.Each(func(i int, s *goquery.Selection) {
|
||||
link, exist := s.Find(".release-list-title a").Attr("href")
|
||||
if !exist {
|
||||
return
|
||||
}
|
||||
links = append(links, link)
|
||||
|
||||
commitsToMain = append(commitsToMain, s.Find(".ahead > a").Text())
|
||||
})
|
||||
|
||||
assert.EqualValues(t, []string{"/user2/repo1/releases/tag/v1.0", "/user2/repo1/releases/tag/v1.1"}, links)
|
||||
assert.EqualValues(t, []string{
|
||||
"/user2/repo-release/releases/tag/v2.0",
|
||||
"/user2/repo-release/releases/tag/v1.1",
|
||||
"/user2/repo-release/releases/tag/v1.0",
|
||||
}, links)
|
||||
assert.EqualValues(t, []string{
|
||||
"0 commits",
|
||||
"1 commits", // should be 3 commits ahead and 2 commits behind, but not implemented yet
|
||||
"3 commits",
|
||||
}, commitsToMain)
|
||||
}
|
||||
|
||||
func TestViewSingleReleaseNoLogin(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/repo-release/releases/tag/v1.0")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
// check the "number of commits to main since this release"
|
||||
releaseList := htmlDoc.doc.Find("#release-list .ahead > a")
|
||||
assert.EqualValues(t, 1, releaseList.Length())
|
||||
assert.EqualValues(t, "3 commits", releaseList.First().Text())
|
||||
}
|
||||
|
||||
func TestViewReleaseListLogin(t *testing.T) {
|
||||
|
||||
@@ -354,7 +354,6 @@ func TestViewRepoDirectoryReadme(t *testing.T) {
|
||||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
_, exists := htmlDoc.doc.Find(".file-view").Attr("class")
|
||||
fmt.Printf("%s", resp.Body)
|
||||
|
||||
assert.False(t, exists, "README should not have rendered")
|
||||
})
|
||||
@@ -376,7 +375,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 +383,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 +398,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 +406,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)
|
||||
}
|
||||
|
||||
+26
-12
@@ -1,6 +1,7 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//nolint:forbidigo
|
||||
package tests
|
||||
|
||||
import (
|
||||
@@ -10,7 +11,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
@@ -30,29 +30,44 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func exitf(format string, args ...interface{}) {
|
||||
fmt.Printf(format+"\n", args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func InitTest(requireGitea bool) {
|
||||
giteaRoot := base.SetupGiteaRoot()
|
||||
if giteaRoot == "" {
|
||||
fmt.Println("Environment variable $GITEA_ROOT not set")
|
||||
os.Exit(1)
|
||||
exitf("Environment variable $GITEA_ROOT not set")
|
||||
}
|
||||
setting.AppWorkPath = giteaRoot
|
||||
if requireGitea {
|
||||
giteaBinary := "gitea"
|
||||
if runtime.GOOS == "windows" {
|
||||
if setting.IsWindows {
|
||||
giteaBinary += ".exe"
|
||||
}
|
||||
setting.AppPath = path.Join(giteaRoot, giteaBinary)
|
||||
if _, err := os.Stat(setting.AppPath); err != nil {
|
||||
fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath)
|
||||
os.Exit(1)
|
||||
exitf("Could not find gitea binary at %s", setting.AppPath)
|
||||
}
|
||||
}
|
||||
|
||||
giteaConf := os.Getenv("GITEA_CONF")
|
||||
if giteaConf == "" {
|
||||
fmt.Println("Environment variable $GITEA_CONF not set")
|
||||
os.Exit(1)
|
||||
} else if !path.IsAbs(giteaConf) {
|
||||
// By default, use sqlite.ini for testing, then IDE like GoLand can start the test process with debugger.
|
||||
// It's easier for developers to debug bugs step by step with a debugger.
|
||||
// Notice: when doing "ssh push", Gitea executes sub processes, debugger won't work for the sub processes.
|
||||
giteaConf = "tests/sqlite.ini"
|
||||
_ = os.Setenv("GITEA_CONF", giteaConf)
|
||||
fmt.Printf("Environment variable $GITEA_CONF not set, use default: %s\n", giteaConf)
|
||||
if !setting.EnableSQLite3 {
|
||||
exitf(`Need to enable SQLite3 for sqlite.ini testing, please set: -tags "sqlite,sqlite_unlock_notify"`)
|
||||
}
|
||||
}
|
||||
|
||||
setting.IsInTesting = true
|
||||
|
||||
if !path.IsAbs(giteaConf) {
|
||||
setting.CustomConf = path.Join(giteaRoot, giteaConf)
|
||||
} else {
|
||||
setting.CustomConf = giteaConf
|
||||
@@ -69,8 +84,7 @@ func InitTest(requireGitea bool) {
|
||||
|
||||
setting.LoadDBSetting()
|
||||
if err := storage.Init(); err != nil {
|
||||
fmt.Printf("Init storage failed: %v", err)
|
||||
os.Exit(1)
|
||||
exitf("Init storage failed: %v", err)
|
||||
}
|
||||
|
||||
switch {
|
||||
@@ -221,7 +235,7 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
return deferFn
|
||||
}
|
||||
|
||||
// resetFixtures flushes queues, reloads fixtures and resets test repositories within a single test.
|
||||
// ResetFixtures flushes queues, reloads fixtures and resets test repositories within a single test.
|
||||
// Most tests should call defer tests.PrepareTestEnv(t)() (or have onGiteaRun do that for them) but sometimes
|
||||
// within a single test this is required
|
||||
func ResetFixtures(t *testing.T) {
|
||||
|
||||
@@ -180,11 +180,6 @@ func (log *TestLogger) Init(config string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Content returns the content accumulated in the content provider
|
||||
func (log *TestLogger) Content() (string, error) {
|
||||
return "", fmt.Errorf("not supported")
|
||||
}
|
||||
|
||||
// Flush when log should be flushed
|
||||
func (log *TestLogger) Flush() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user