mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
This commit is contained in:
@@ -22,7 +22,7 @@ func TestAPIAdminOrgCreate(t *testing.T) {
|
||||
session := loginUser(t, "user1")
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
var org = api.CreateOrgOption{
|
||||
org := api.CreateOrgOption{
|
||||
UserName: "user2_org",
|
||||
FullName: "User2's organization",
|
||||
Description: "This organization created by admin for user2",
|
||||
@@ -56,7 +56,7 @@ func TestAPIAdminOrgCreateBadVisibility(t *testing.T) {
|
||||
session := loginUser(t, "user1")
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
var org = api.CreateOrgOption{
|
||||
org := api.CreateOrgOption{
|
||||
UserName: "user2_org",
|
||||
FullName: "User2's organization",
|
||||
Description: "This organization created by admin for user2",
|
||||
@@ -74,7 +74,7 @@ func TestAPIAdminOrgCreateNotAdmin(t *testing.T) {
|
||||
nonAdminUsername := "user2"
|
||||
session := loginUser(t, nonAdminUsername)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
var org = api.CreateOrgOption{
|
||||
org := api.CreateOrgOption{
|
||||
UserName: "user2_org",
|
||||
FullName: "User2's organization",
|
||||
Description: "This organization created by admin for user2",
|
||||
|
@@ -106,7 +106,6 @@ func TestAPICreateBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
func testAPICreateBranches(t *testing.T, giteaURL *url.URL) {
|
||||
|
||||
username := "user2"
|
||||
ctx := NewAPITestContext(t, username, "my-noo-repo")
|
||||
giteaURL.Path = ctx.GitPath()
|
||||
|
@@ -44,10 +44,10 @@ func TestAPIListRepoComments(t *testing.T) {
|
||||
unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: c.IssueID, RepoID: repo.ID})
|
||||
}
|
||||
|
||||
//test before and since filters
|
||||
// test before and since filters
|
||||
query := url.Values{}
|
||||
before := "2000-01-01T00:00:11+00:00" //unix: 946684811
|
||||
since := "2000-01-01T00:00:12+00:00" //unix: 946684812
|
||||
before := "2000-01-01T00:00:11+00:00" // unix: 946684811
|
||||
since := "2000-01-01T00:00:12+00:00" // unix: 946684812
|
||||
query.Add("before", before)
|
||||
link.RawQuery = query.Encode()
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
|
@@ -28,15 +28,18 @@ func TestGPGKeys(t *testing.T) {
|
||||
token string
|
||||
results []int
|
||||
}{
|
||||
{name: "NoLogin", makeRequest: MakeRequest, token: "",
|
||||
{
|
||||
name: "NoLogin", makeRequest: MakeRequest, token: "",
|
||||
results: []int{http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized, http.StatusUnauthorized},
|
||||
},
|
||||
{name: "LoggedAsUser2", makeRequest: session.MakeRequest, token: token,
|
||||
results: []int{http.StatusOK, http.StatusOK, http.StatusNotFound, http.StatusNoContent, http.StatusUnprocessableEntity, http.StatusNotFound, http.StatusCreated, http.StatusNotFound, http.StatusCreated}},
|
||||
{
|
||||
name: "LoggedAsUser2", makeRequest: session.MakeRequest, token: token,
|
||||
results: []int{http.StatusOK, http.StatusOK, http.StatusNotFound, http.StatusNoContent, http.StatusUnprocessableEntity, http.StatusNotFound, http.StatusCreated, http.StatusNotFound, http.StatusCreated},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
//Basic test on result code
|
||||
// Basic test on result code
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Run("ViewOwnGPGKeys", func(t *testing.T) {
|
||||
testViewOwnGPGKeys(t, tc.makeRequest, tc.token, tc.results[0])
|
||||
@@ -66,28 +69,27 @@ func TestGPGKeys(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
//Check state after basic add
|
||||
// Check state after basic add
|
||||
t.Run("CheckState", func(t *testing.T) {
|
||||
|
||||
var keys []*api.GPGKey
|
||||
|
||||
req := NewRequest(t, "GET", "/api/v1/user/gpg_keys?token="+token) //GET all keys
|
||||
req := NewRequest(t, "GET", "/api/v1/user/gpg_keys?token="+token) // GET all keys
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &keys)
|
||||
assert.Len(t, keys, 1)
|
||||
|
||||
primaryKey1 := keys[0] //Primary key 1
|
||||
primaryKey1 := keys[0] // Primary key 1
|
||||
assert.EqualValues(t, "38EA3BCED732982C", primaryKey1.KeyID)
|
||||
assert.Len(t, primaryKey1.Emails, 1)
|
||||
assert.EqualValues(t, "user2@example.com", primaryKey1.Emails[0].Email)
|
||||
assert.True(t, primaryKey1.Emails[0].Verified)
|
||||
|
||||
subKey := primaryKey1.SubsKey[0] //Subkey of 38EA3BCED732982C
|
||||
subKey := primaryKey1.SubsKey[0] // Subkey of 38EA3BCED732982C
|
||||
assert.EqualValues(t, "70D7C694D17D03AD", subKey.KeyID)
|
||||
assert.Empty(t, subKey.Emails)
|
||||
|
||||
var key api.GPGKey
|
||||
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(primaryKey1.ID, 10)+"?token="+token) //Primary key 1
|
||||
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(primaryKey1.ID, 10)+"?token="+token) // Primary key 1
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &key)
|
||||
assert.EqualValues(t, "38EA3BCED732982C", key.KeyID)
|
||||
@@ -95,14 +97,14 @@ func TestGPGKeys(t *testing.T) {
|
||||
assert.EqualValues(t, "user2@example.com", key.Emails[0].Email)
|
||||
assert.True(t, key.Emails[0].Verified)
|
||||
|
||||
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(subKey.ID, 10)+"?token="+token) //Subkey of 38EA3BCED732982C
|
||||
req = NewRequest(t, "GET", "/api/v1/user/gpg_keys/"+strconv.FormatInt(subKey.ID, 10)+"?token="+token) // Subkey of 38EA3BCED732982C
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &key)
|
||||
assert.EqualValues(t, "70D7C694D17D03AD", key.KeyID)
|
||||
assert.Empty(t, key.Emails)
|
||||
})
|
||||
|
||||
//Check state after basic add
|
||||
// Check state after basic add
|
||||
t.Run("CheckCommits", func(t *testing.T) {
|
||||
t.Run("NotSigned", func(t *testing.T) {
|
||||
var branch api.Branch
|
||||
@@ -182,7 +184,7 @@ INx/MmBfmtCq05FqNclvU+sj2R3N1JJOtBOjZrJHQbJhzoILou8AkxeX1A+q9OAz
|
||||
}
|
||||
|
||||
func testCreateValidGPGKey(t *testing.T, makeRequest makeRequestFunc, token string, expected int) {
|
||||
//User2 <user2@example.com> //primary & activated
|
||||
// User2 <user2@example.com> //primary & activated
|
||||
testCreateGPGKey(t, makeRequest, token, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQENBFmGVsMBCACuxgZ7W7rI9xN08Y4M7B8yx/6/I4Slm94+wXf8YNRvAyqj30dW
|
||||
@@ -216,7 +218,7 @@ uy6MA3VSB99SK9ducGmE1Jv8mcziREroz2TEGr0zPs6h
|
||||
}
|
||||
|
||||
func testCreateValidSecondaryEmailGPGKey(t *testing.T, makeRequest makeRequestFunc, token string, expected int) {
|
||||
//User2 <user2-2@example.com> //secondary and not activated
|
||||
// User2 <user2-2@example.com> //secondary and not activated
|
||||
testCreateGPGKey(t, makeRequest, token, expected, `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQGNBGC2K2cBDAC1+Xgk+8UfhASVgRngQi4rnQ8k0t+bWsBz4Czd26+cxVDRwlTT
|
||||
|
@@ -53,21 +53,21 @@ func TestAPIModifyLabels(t *testing.T) {
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
//ListLabels
|
||||
// ListLabels
|
||||
req = NewRequest(t, "GET", urlStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
var apiLabels []*api.Label
|
||||
DecodeJSON(t, resp, &apiLabels)
|
||||
assert.Len(t, apiLabels, 2)
|
||||
|
||||
//GetLabel
|
||||
// GetLabel
|
||||
singleURLStr := fmt.Sprintf("/api/v1/repos/%s/%s/labels/%d?token=%s", owner.Name, repo.Name, dbLabel.ID, token)
|
||||
req = NewRequest(t, "GET", singleURLStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiLabel)
|
||||
assert.EqualValues(t, strings.TrimLeft(dbLabel.Color, "#"), apiLabel.Color)
|
||||
|
||||
//EditLabel
|
||||
// EditLabel
|
||||
newName := "LabelNewName"
|
||||
newColor := "09876a"
|
||||
newColorWrong := "09g76a"
|
||||
@@ -83,10 +83,9 @@ func TestAPIModifyLabels(t *testing.T) {
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
//DeleteLabel
|
||||
// DeleteLabel
|
||||
req = NewRequest(t, "DELETE", singleURLStr)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
}
|
||||
|
||||
func TestAPIAddIssueLabels(t *testing.T) {
|
||||
@@ -173,21 +172,21 @@ func TestAPIModifyOrgLabels(t *testing.T) {
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
//ListLabels
|
||||
// ListLabels
|
||||
req = NewRequest(t, "GET", urlStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
var apiLabels []*api.Label
|
||||
DecodeJSON(t, resp, &apiLabels)
|
||||
assert.Len(t, apiLabels, 4)
|
||||
|
||||
//GetLabel
|
||||
// GetLabel
|
||||
singleURLStr := fmt.Sprintf("/api/v1/orgs/%s/labels/%d?token=%s", owner.Name, dbLabel.ID, token)
|
||||
req = NewRequest(t, "GET", singleURLStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiLabel)
|
||||
assert.EqualValues(t, strings.TrimLeft(dbLabel.Color, "#"), apiLabel.Color)
|
||||
|
||||
//EditLabel
|
||||
// EditLabel
|
||||
newName := "LabelNewName"
|
||||
newColor := "09876a"
|
||||
newColorWrong := "09g76a"
|
||||
@@ -203,8 +202,7 @@ func TestAPIModifyOrgLabels(t *testing.T) {
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
//DeleteLabel
|
||||
// DeleteLabel
|
||||
req = NewRequest(t, "DELETE", singleURLStr)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
}
|
||||
|
@@ -33,19 +33,19 @@ func TestAPIIssuesReactions(t *testing.T) {
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/reactions?token=%s",
|
||||
owner.Name, issue.Repo.Name, issue.Index, token)
|
||||
|
||||
//Try to add not allowed reaction
|
||||
// Try to add not allowed reaction
|
||||
req := NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "wrong",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Delete not allowed reaction
|
||||
// Delete not allowed reaction
|
||||
req = NewRequestWithJSON(t, "DELETE", urlStr, &api.EditReactionOption{
|
||||
Reaction: "zzz",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
//Add allowed reaction
|
||||
// Add allowed reaction
|
||||
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "rocket",
|
||||
})
|
||||
@@ -53,10 +53,10 @@ func TestAPIIssuesReactions(t *testing.T) {
|
||||
var apiNewReaction api.Reaction
|
||||
DecodeJSON(t, resp, &apiNewReaction)
|
||||
|
||||
//Add existing reaction
|
||||
// Add existing reaction
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Get end result of reaction list of issue #1
|
||||
// Get end result of reaction list of issue #1
|
||||
req = NewRequestf(t, "GET", urlStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
var apiReactions []*api.Reaction
|
||||
@@ -93,19 +93,19 @@ func TestAPICommentReactions(t *testing.T) {
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/reactions?token=%s",
|
||||
owner.Name, issue.Repo.Name, comment.ID, token)
|
||||
|
||||
//Try to add not allowed reaction
|
||||
// Try to add not allowed reaction
|
||||
req := NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "wrong",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Delete none existing reaction
|
||||
// Delete none existing reaction
|
||||
req = NewRequestWithJSON(t, "DELETE", urlStr, &api.EditReactionOption{
|
||||
Reaction: "eyes",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
//Add allowed reaction
|
||||
// Add allowed reaction
|
||||
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "+1",
|
||||
})
|
||||
@@ -113,10 +113,10 @@ func TestAPICommentReactions(t *testing.T) {
|
||||
var apiNewReaction api.Reaction
|
||||
DecodeJSON(t, resp, &apiNewReaction)
|
||||
|
||||
//Add existing reaction
|
||||
// Add existing reaction
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Get end result of reaction list of issue #1
|
||||
// Get end result of reaction list of issue #1
|
||||
req = NewRequestf(t, "GET", urlStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
var apiReactions []*api.Reaction
|
||||
|
@@ -33,7 +33,6 @@ func TestAPIIssueSubscriptions(t *testing.T) {
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
testSubscription := func(issue *models.Issue, isWatching bool) {
|
||||
|
||||
issueRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}).(*repo_model.Repository)
|
||||
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/check?token=%s", issueRepo.OwnerName, issueRepo.Name, issue.Index, token)
|
||||
|
@@ -210,7 +210,7 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "15", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 10) //there are more but 10 is page item limit
|
||||
assert.Len(t, apiIssues, 10) // there are more but 10 is page item limit
|
||||
|
||||
query.Add("limit", "20")
|
||||
link.RawQuery = query.Encode()
|
||||
|
@@ -48,8 +48,8 @@ func TestAPIGetTrackedTimes(t *testing.T) {
|
||||
}
|
||||
|
||||
// test filter
|
||||
since := "2000-01-01T00%3A00%3A02%2B00%3A00" //946684802
|
||||
before := "2000-01-01T00%3A00%3A12%2B00%3A00" //946684812
|
||||
since := "2000-01-01T00%3A00%3A02%2B00%3A00" // 946684802
|
||||
before := "2000-01-01T00%3A00%3A12%2B00%3A00" // 946684812
|
||||
|
||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/times?since=%s&before=%s&token=%s", user2.Name, issue2.Repo.Name, issue2.Index, since, before, token)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
@@ -71,17 +71,17 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
|
||||
session := loginUser(t, user2.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
//Deletion not allowed
|
||||
// Deletion not allowed
|
||||
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time6.ID, token)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
time3 := unittest.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 3}).(*models.TrackedTime)
|
||||
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time3.ID, token)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
//Delete non existing time
|
||||
// Delete non existing time
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
//Reset time of user 2 on issue 2
|
||||
// Reset time of user 2 on issue 2
|
||||
trackedSeconds, err := models.GetTrackedSeconds(models.FindTrackedTimesOptions{IssueID: 2, UserID: 2})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(3661), trackedSeconds)
|
||||
|
@@ -30,7 +30,7 @@ func TestAPINotification(t *testing.T) {
|
||||
|
||||
// -- GET /notifications --
|
||||
// test filter
|
||||
since := "2000-01-01T00%3A50%3A01%2B00%3A00" //946687801
|
||||
since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?since=%s&token=%s", since, token))
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
var apiNL []api.NotificationThread
|
||||
@@ -40,7 +40,7 @@ func TestAPINotification(t *testing.T) {
|
||||
assert.EqualValues(t, 5, apiNL[0].ID)
|
||||
|
||||
// test filter
|
||||
before := "2000-01-01T01%3A06%3A59%2B00%3A00" //946688819
|
||||
before := "2000-01-01T01%3A06%3A59%2B00%3A00" // 946688819
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?all=%s&before=%s&token=%s", "true", before, token))
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
@@ -113,7 +113,7 @@ func TestAPINotification(t *testing.T) {
|
||||
DecodeJSON(t, resp, &apiNL)
|
||||
assert.Len(t, apiNL, 2)
|
||||
|
||||
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" //946687801 <- only Notification 4 is in this filter ...
|
||||
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ...
|
||||
req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?last_read_at=%s&token=%s", user2.Name, repo1.Name, lastReadAt, token))
|
||||
session.MakeRequest(t, req, http.StatusResetContent)
|
||||
|
||||
|
@@ -23,7 +23,7 @@ func TestAPIOrgCreate(t *testing.T) {
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
var org = api.CreateOrgOption{
|
||||
org := api.CreateOrgOption{
|
||||
UserName: "user1_org",
|
||||
FullName: "User1's organization",
|
||||
Description: "This organization created by user1",
|
||||
@@ -80,7 +80,7 @@ func TestAPIOrgEdit(t *testing.T) {
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
var org = api.EditOrgOption{
|
||||
org := api.EditOrgOption{
|
||||
FullName: "User3 organization new full name",
|
||||
Description: "A new description",
|
||||
Website: "https://try.gitea.io/new",
|
||||
@@ -107,7 +107,7 @@ func TestAPIOrgEditBadVisibility(t *testing.T) {
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
var org = api.EditOrgOption{
|
||||
org := api.EditOrgOption{
|
||||
FullName: "User3 organization new full name",
|
||||
Description: "A new description",
|
||||
Website: "https://try.gitea.io/new",
|
||||
@@ -126,7 +126,7 @@ func TestAPIOrgDeny(t *testing.T) {
|
||||
setting.Service.RequireSignInView = false
|
||||
}()
|
||||
|
||||
var orgName = "user1_org"
|
||||
orgName := "user1_org"
|
||||
req := NewRequestf(t, "GET", "/api/v1/orgs/%s", orgName)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
|
@@ -150,7 +150,5 @@ func TestAPIPrivateServ(t *testing.T) {
|
||||
assert.Equal(t, "user15", results.OwnerName)
|
||||
assert.Equal(t, "big_test_private_2", results.RepoName)
|
||||
assert.Equal(t, int64(20), results.RepoID)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
@@ -80,22 +80,23 @@ func TestAPIPullReview(t *testing.T) {
|
||||
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{
|
||||
Body: "body1",
|
||||
// Event: "" # will result in PENDING
|
||||
Comments: []api.CreatePullReviewComment{{
|
||||
Path: "README.md",
|
||||
Body: "first new line",
|
||||
OldLineNum: 0,
|
||||
NewLineNum: 1,
|
||||
}, {
|
||||
Path: "README.md",
|
||||
Body: "first old line",
|
||||
OldLineNum: 1,
|
||||
NewLineNum: 0,
|
||||
}, {
|
||||
Path: "iso-8859-1.txt",
|
||||
Body: "this line contains a non-utf-8 character",
|
||||
OldLineNum: 0,
|
||||
NewLineNum: 1,
|
||||
},
|
||||
Comments: []api.CreatePullReviewComment{
|
||||
{
|
||||
Path: "README.md",
|
||||
Body: "first new line",
|
||||
OldLineNum: 0,
|
||||
NewLineNum: 1,
|
||||
}, {
|
||||
Path: "README.md",
|
||||
Body: "first old line",
|
||||
OldLineNum: 1,
|
||||
NewLineNum: 0,
|
||||
}, {
|
||||
Path: "iso-8859-1.txt",
|
||||
Body: "this line contains a non-utf-8 character",
|
||||
OldLineNum: 0,
|
||||
NewLineNum: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
@@ -147,17 +148,18 @@ func TestAPIPullReview(t *testing.T) {
|
||||
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{
|
||||
// Body: "",
|
||||
Event: "COMMENT",
|
||||
Comments: []api.CreatePullReviewComment{{
|
||||
Path: "README.md",
|
||||
Body: "first new line",
|
||||
OldLineNum: 0,
|
||||
NewLineNum: 1,
|
||||
}, {
|
||||
Path: "README.md",
|
||||
Body: "first old line",
|
||||
OldLineNum: 1,
|
||||
NewLineNum: 0,
|
||||
},
|
||||
Comments: []api.CreatePullReviewComment{
|
||||
{
|
||||
Path: "README.md",
|
||||
Body: "first new line",
|
||||
OldLineNum: 0,
|
||||
NewLineNum: 1,
|
||||
}, {
|
||||
Path: "README.md",
|
||||
Body: "first old line",
|
||||
OldLineNum: 1,
|
||||
NewLineNum: 0,
|
||||
},
|
||||
},
|
||||
})
|
||||
var commentReview api.PullReview
|
||||
|
@@ -175,7 +175,7 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
assert.Equal(t, *repoEditOption.Private, *repo1editedOption.Private)
|
||||
assert.Equal(t, *repoEditOption.HasWiki, *repo1editedOption.HasWiki)
|
||||
|
||||
//Test editing repo1 to use internal issue and wiki (default)
|
||||
// Test editing repo1 to use internal issue and wiki (default)
|
||||
*repoEditOption.HasIssues = true
|
||||
repoEditOption.ExternalTracker = nil
|
||||
repoEditOption.InternalTracker = &api.InternalTracker{
|
||||
@@ -199,7 +199,7 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
assert.Equal(t, *repo1editedOption.HasWiki, true)
|
||||
assert.Nil(t, repo1editedOption.ExternalWiki)
|
||||
|
||||
//Test editing repo1 to use external issue and wiki
|
||||
// Test editing repo1 to use external issue and wiki
|
||||
repoEditOption.ExternalTracker = &api.ExternalTracker{
|
||||
ExternalTrackerURL: "http://www.somewebsite.com",
|
||||
ExternalTrackerFormat: "http://www.somewebsite.com/{user}/{repo}?issue={index}",
|
||||
@@ -233,7 +233,7 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
//Test small repo change through API with issue and wiki option not set; They shall not be touched.
|
||||
// Test small repo change through API with issue and wiki option not set; They shall not be touched.
|
||||
*repoEditOption.Description = "small change"
|
||||
repoEditOption.HasIssues = nil
|
||||
repoEditOption.ExternalTracker = nil
|
||||
|
@@ -130,7 +130,6 @@ func TestDownloadCommitDiffOrPatch(t *testing.T) {
|
||||
assert.EqualValues(t,
|
||||
"From f27c2b2b03dcab38beaf89b0ab4ff61f6de63441 Mon Sep 17 00:00:00 2001\nFrom: User2 <user2@example.com>\nDate: Sun, 6 Aug 2017 19:55:01 +0200\nSubject: [PATCH] good signed commit\n\n---\n readme.md | 1 +\n 1 file changed, 1 insertion(+)\n create mode 100644 readme.md\n\ndiff --git a/readme.md b/readme.md\nnew file mode 100644\nindex 0000000..458121c\n--- /dev/null\n+++ b/readme.md\n@@ -0,0 +1 @@\n+good sign\n",
|
||||
resp.Body.String())
|
||||
|
||||
}
|
||||
|
||||
func TestGetFileHistory(t *testing.T) {
|
||||
|
@@ -53,8 +53,8 @@ func TestAPILFSLocksNotLogin(t *testing.T) {
|
||||
func TestAPILFSLocksLogged(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
setting.LFS.StartServer = true
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) //in org 3
|
||||
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User) //in org 3
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // in org 3
|
||||
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User) // in org 3
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository) // own by org 3
|
||||
@@ -101,7 +101,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
|
||||
lockID string
|
||||
}{}
|
||||
|
||||
//create locks
|
||||
// create locks
|
||||
for _, test := range tests {
|
||||
session := loginUser(t, test.user.Name)
|
||||
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks", test.repo.FullName()), map[string]string{"path": test.path})
|
||||
@@ -111,14 +111,14 @@ func TestAPILFSLocksLogged(t *testing.T) {
|
||||
if len(test.addTime) > 0 {
|
||||
var lfsLock api.LFSLockResponse
|
||||
DecodeJSON(t, resp, &lfsLock)
|
||||
assert.EqualValues(t, lfsLock.Lock.LockedAt.Format(time.RFC3339), lfsLock.Lock.LockedAt.Format(time.RFC3339Nano)) //locked at should be rounded to second
|
||||
assert.EqualValues(t, lfsLock.Lock.LockedAt.Format(time.RFC3339), lfsLock.Lock.LockedAt.Format(time.RFC3339Nano)) // locked at should be rounded to second
|
||||
for _, id := range test.addTime {
|
||||
resultsTests[id].locksTimes = append(resultsTests[id].locksTimes, time.Now())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check creation
|
||||
// check creation
|
||||
for _, test := range resultsTests {
|
||||
session := loginUser(t, test.user.Name)
|
||||
req := NewRequestf(t, "GET", "/%s.git/info/lfs/locks", test.repo.FullName())
|
||||
@@ -130,7 +130,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
|
||||
for i, lock := range lfsLocks.Locks {
|
||||
assert.EqualValues(t, test.locksOwners[i].DisplayName(), lock.Owner.Name)
|
||||
assert.WithinDuration(t, test.locksTimes[i], lock.LockedAt, 10*time.Second)
|
||||
assert.EqualValues(t, lock.LockedAt.Format(time.RFC3339), lock.LockedAt.Format(time.RFC3339Nano)) //locked at should be rounded to second
|
||||
assert.EqualValues(t, lock.LockedAt.Format(time.RFC3339), lock.LockedAt.Format(time.RFC3339Nano)) // locked at should be rounded to second
|
||||
}
|
||||
|
||||
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks/verify", test.repo.FullName()), map[string]string{})
|
||||
@@ -154,7 +154,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
//remove all locks
|
||||
// remove all locks
|
||||
for _, test := range deleteTests {
|
||||
session := loginUser(t, test.user.Name)
|
||||
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks/%s/unlock", test.repo.FullName(), test.lockID), map[string]string{})
|
||||
|
@@ -79,76 +79,99 @@ func TestAPISearchRepo(t *testing.T) {
|
||||
name, requestURL string
|
||||
expectedResults
|
||||
}{
|
||||
{name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 30},
|
||||
user: {count: 30},
|
||||
user2: {count: 30}},
|
||||
{
|
||||
name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 30},
|
||||
user: {count: 30},
|
||||
user2: {count: 30},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 10},
|
||||
user: {count: 10},
|
||||
user2: {count: 10}},
|
||||
{
|
||||
name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 10},
|
||||
user: {count: 10},
|
||||
user2: {count: 10},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesDefault", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 10},
|
||||
user: {count: 10},
|
||||
user2: {count: 10}},
|
||||
{
|
||||
name: "RepositoriesDefault", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 10},
|
||||
user: {count: 10},
|
||||
user2: {count: 10},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "big_test_"), expectedResults: expectedResults{
|
||||
nil: {count: 7, repoName: "big_test_"},
|
||||
user: {count: 7, repoName: "big_test_"},
|
||||
user2: {count: 7, repoName: "big_test_"}},
|
||||
{
|
||||
name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "big_test_"), expectedResults: expectedResults{
|
||||
nil: {count: 7, repoName: "big_test_"},
|
||||
user: {count: 7, repoName: "big_test_"},
|
||||
user2: {count: 7, repoName: "big_test_"},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{
|
||||
nil: {count: 5},
|
||||
user: {count: 9, includesPrivate: true},
|
||||
user2: {count: 6, includesPrivate: true}},
|
||||
{
|
||||
name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{
|
||||
nil: {count: 5},
|
||||
user: {count: 9, includesPrivate: true},
|
||||
user2: {count: 6, includesPrivate: true},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 2, includesPrivate: true},
|
||||
user2: {count: 2, includesPrivate: true},
|
||||
user4: {count: 1}},
|
||||
{
|
||||
name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 2, includesPrivate: true},
|
||||
user2: {count: 2, includesPrivate: true},
|
||||
user4: {count: 1},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser3", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user3.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 4, includesPrivate: true},
|
||||
user2: {count: 3, includesPrivate: true},
|
||||
user3: {count: 4, includesPrivate: true}},
|
||||
{
|
||||
name: "RepositoriesAccessibleAndRelatedToUser3", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user3.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 4, includesPrivate: true},
|
||||
user2: {count: 3, includesPrivate: true},
|
||||
user3: {count: 4, includesPrivate: true},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1, repoOwnerID: orgUser.ID},
|
||||
user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true},
|
||||
user2: {count: 1, repoOwnerID: orgUser.ID}},
|
||||
{
|
||||
name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{
|
||||
nil: {count: 1, repoOwnerID: orgUser.ID},
|
||||
user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true},
|
||||
user2: {count: 1, repoOwnerID: orgUser.ID},
|
||||
},
|
||||
},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser4", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user4.ID), expectedResults: expectedResults{
|
||||
nil: {count: 3},
|
||||
user: {count: 4, includesPrivate: true},
|
||||
user4: {count: 7, includesPrivate: true}}},
|
||||
user4: {count: 7, includesPrivate: true},
|
||||
}},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeSource", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "source"), expectedResults: expectedResults{
|
||||
nil: {count: 0},
|
||||
user: {count: 1, includesPrivate: true},
|
||||
user4: {count: 1, includesPrivate: true}}},
|
||||
user4: {count: 1, includesPrivate: true},
|
||||
}},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeFork", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "fork"), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 1},
|
||||
user4: {count: 2, includesPrivate: true}}},
|
||||
user4: {count: 2, includesPrivate: true},
|
||||
}},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeFork/Exclusive", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s&exclusive=1", user4.ID, "fork"), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 1},
|
||||
user4: {count: 2, includesPrivate: true}}},
|
||||
user4: {count: 2, includesPrivate: true},
|
||||
}},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeMirror", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "mirror"), expectedResults: expectedResults{
|
||||
nil: {count: 2},
|
||||
user: {count: 2},
|
||||
user4: {count: 4, includesPrivate: true}}},
|
||||
user4: {count: 4, includesPrivate: true},
|
||||
}},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeMirror/Exclusive", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s&exclusive=1", user4.ID, "mirror"), expectedResults: expectedResults{
|
||||
nil: {count: 1},
|
||||
user: {count: 1},
|
||||
user4: {count: 2, includesPrivate: true}}},
|
||||
user4: {count: 2, includesPrivate: true},
|
||||
}},
|
||||
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeCollaborative", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "collaborative"), expectedResults: expectedResults{
|
||||
nil: {count: 0},
|
||||
user: {count: 1, includesPrivate: true},
|
||||
user4: {count: 1, includesPrivate: true}}},
|
||||
user4: {count: 1, includesPrivate: true},
|
||||
}},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
@@ -464,7 +487,7 @@ func TestAPIRepoTransfer(t *testing.T) {
|
||||
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
//create repo to move
|
||||
// create repo to move
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||||
session := loginUser(t, user.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
@@ -480,7 +503,7 @@ func TestAPIRepoTransfer(t *testing.T) {
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
DecodeJSON(t, resp, apiRepo)
|
||||
|
||||
//start testing
|
||||
// start testing
|
||||
for _, testCase := range testCases {
|
||||
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID}).(*user_model.User)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}).(*repo_model.Repository)
|
||||
@@ -493,13 +516,13 @@ func TestAPIRepoTransfer(t *testing.T) {
|
||||
session.MakeRequest(t, req, testCase.expectedStatus)
|
||||
}
|
||||
|
||||
//cleanup
|
||||
// cleanup
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}).(*repo_model.Repository)
|
||||
_ = models.DeleteRepository(user, repo.OwnerID, repo.ID)
|
||||
}
|
||||
|
||||
func transfer(t *testing.T) *repo_model.Repository {
|
||||
//create repo to move
|
||||
// create repo to move
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
session := loginUser(t, user.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
@@ -155,5 +155,4 @@ func TestAPIRepoTopic(t *testing.T) {
|
||||
// Test add a topic to repo with write access (requires repo admin access)
|
||||
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user3.Name, repo3.Name, "topicName", token4)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ func TestUserHeatmap(t *testing.T) {
|
||||
normalUsername := "user2"
|
||||
session := loginUser(t, adminUsername)
|
||||
|
||||
var fakeNow = time.Date(2011, 10, 20, 0, 0, 0, 0, time.Local)
|
||||
fakeNow := time.Date(2011, 10, 20, 0, 0, 0, 0, time.Local)
|
||||
timeutil.Set(fakeNow)
|
||||
defer timeutil.Unset()
|
||||
|
||||
|
@@ -54,7 +54,7 @@ func TestUserOrgs(t *testing.T) {
|
||||
}
|
||||
|
||||
func getUserOrgs(t *testing.T, userDoer, userCheck string) (orgs []*api.Organization) {
|
||||
var token = ""
|
||||
token := ""
|
||||
session := emptyTestSession(t)
|
||||
if len(userDoer) != 0 {
|
||||
session = loginUser(t, userDoer)
|
||||
|
@@ -32,7 +32,7 @@ func generateImg() bytes.Buffer {
|
||||
func createAttachment(t *testing.T, session *TestSession, repoURL, filename string, buff bytes.Buffer, expectedStatus int) string {
|
||||
body := &bytes.Buffer{}
|
||||
|
||||
//Setup multi-part
|
||||
// Setup multi-part
|
||||
writer := multipart.NewWriter(body)
|
||||
part, err := writer.CreateFormFile("file", filename)
|
||||
assert.NoError(t, err)
|
||||
@@ -86,7 +86,7 @@ func TestCreateIssueAttachment(t *testing.T) {
|
||||
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||
test.RedirectURL(resp) // check that redirect URL exists
|
||||
|
||||
//Validate that attachment is available
|
||||
// Validate that attachment is available
|
||||
req = NewRequest(t, "GET", "/attachments/"+uuid)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
@@ -120,12 +120,12 @@ func TestGetAttachment(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
//Write empty file to be available for response
|
||||
// Write empty file to be available for response
|
||||
if tc.createFile {
|
||||
_, err := storage.Attachments.Save(repo_model.AttachmentRelativePath(tc.uuid), strings.NewReader("hello world"), -1)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
//Actual test
|
||||
// Actual test
|
||||
req := NewRequest(t, "GET", "/attachments/"+tc.uuid)
|
||||
tc.session.MakeRequest(t, req, tc.want)
|
||||
})
|
||||
|
@@ -58,7 +58,7 @@ func BenchmarkRepoBranchCommit(b *testing.B) {
|
||||
req := NewRequestf(b, "GET", "/api/v1/repos/%s/branches", repo.FullName())
|
||||
resp := session.MakeRequest(b, req, http.StatusOK)
|
||||
DecodeJSON(b, resp, &branches)
|
||||
b.ResetTimer() //We measure from here
|
||||
b.ResetTimer() // We measure from here
|
||||
if len(branches) != 0 {
|
||||
for i := 0; i < b.N; i++ {
|
||||
req := NewRequestf(b, "GET", "/api/v1/repos/%s/commits?sha=%s", repo.FullName(), branches[i%len(branches)].Name)
|
||||
|
@@ -29,7 +29,8 @@ func Test_CmdKeys(t *testing.T) {
|
||||
}{
|
||||
{"test_empty_1", []string{"keys", "--username=git", "--type=test", "--content=test"}, true, ""},
|
||||
{"test_empty_2", []string{"keys", "-e", "git", "-u", "git", "-t", "test", "-k", "test"}, true, ""},
|
||||
{"with_key",
|
||||
{
|
||||
"with_key",
|
||||
[]string{"keys", "-e", "git", "-u", "git", "-t", "ssh-rsa", "-k", "AAAAB3NzaC1yc2EAAAADAQABAAABgQDWVj0fQ5N8wNc0LVNA41wDLYJ89ZIbejrPfg/avyj3u/ZohAKsQclxG4Ju0VirduBFF9EOiuxoiFBRr3xRpqzpsZtnMPkWVWb+akZwBFAx8p+jKdy4QXR/SZqbVobrGwip2UjSrri1CtBxpJikojRIZfCnDaMOyd9Jp6KkujvniFzUWdLmCPxUE9zhTaPu0JsEP7MW0m6yx7ZUhHyfss+NtqmFTaDO+QlMR7L2QkDliN2Jl3Xa3PhuWnKJfWhdAq1Cw4oraKUOmIgXLkuiuxVQ6mD3AiFupkmfqdHq6h+uHHmyQqv3gU+/sD8GbGAhf6ftqhTsXjnv1Aj4R8NoDf9BS6KRkzkeun5UisSzgtfQzjOMEiJtmrep2ZQrMGahrXa+q4VKr0aKJfm+KlLfwm/JztfsBcqQWNcTURiCFqz+fgZw0Ey/de0eyMzldYTdXXNRYCKjs9bvBK+6SSXRM7AhftfQ0ZuoW5+gtinPrnmoOaSCEJbAiEiTO/BzOHgowiM="},
|
||||
false,
|
||||
"# gitea public key\ncommand=\"" + setting.AppPath + " --config=" + util.ShellEscape(setting.CustomConf) + " serv key-1\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,no-user-rc,restrict ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDWVj0fQ5N8wNc0LVNA41wDLYJ89ZIbejrPfg/avyj3u/ZohAKsQclxG4Ju0VirduBFF9EOiuxoiFBRr3xRpqzpsZtnMPkWVWb+akZwBFAx8p+jKdy4QXR/SZqbVobrGwip2UjSrri1CtBxpJikojRIZfCnDaMOyd9Jp6KkujvniFzUWdLmCPxUE9zhTaPu0JsEP7MW0m6yx7ZUhHyfss+NtqmFTaDO+QlMR7L2QkDliN2Jl3Xa3PhuWnKJfWhdAq1Cw4oraKUOmIgXLkuiuxVQ6mD3AiFupkmfqdHq6h+uHHmyQqv3gU+/sD8GbGAhf6ftqhTsXjnv1Aj4R8NoDf9BS6KRkzkeun5UisSzgtfQzjOMEiJtmrep2ZQrMGahrXa+q4VKr0aKJfm+KlLfwm/JztfsBcqQWNcTURiCFqz+fgZw0Ey/de0eyMzldYTdXXNRYCKjs9bvBK+6SSXRM7AhftfQ0ZuoW5+gtinPrnmoOaSCEJbAiEiTO/BzOHgowiM= user2@localhost\n",
|
||||
@@ -38,7 +39,7 @@ func Test_CmdKeys(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
realStdout := os.Stdout //Backup Stdout
|
||||
realStdout := os.Stdout // Backup Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
|
||||
@@ -56,7 +57,7 @@ func Test_CmdKeys(t *testing.T) {
|
||||
if tt.expectedOutput != commandOutput {
|
||||
t.Errorf("expectedOutput: %#v, commandOutput: %#v", tt.expectedOutput, commandOutput)
|
||||
}
|
||||
//Restore stdout
|
||||
// Restore stdout
|
||||
os.Stdout = realStdout
|
||||
})
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ func TestDumpRestore(t *testing.T) {
|
||||
//
|
||||
|
||||
ctx := context.Background()
|
||||
var opts = migrations.MigrateOptions{
|
||||
opts := migrations.MigrateOptions{
|
||||
GitServiceType: structs.GiteaService,
|
||||
Issues: true,
|
||||
Labels: true,
|
||||
@@ -109,11 +109,11 @@ func TestDumpRestore(t *testing.T) {
|
||||
|
||||
beforeBytes, err := os.ReadFile(filepath.Join(d, "issue.yml"))
|
||||
assert.NoError(t, err)
|
||||
var before = make([]*base.Issue, 0, 10)
|
||||
before := make([]*base.Issue, 0, 10)
|
||||
assert.NoError(t, yaml.Unmarshal(beforeBytes, &before))
|
||||
afterBytes, err := os.ReadFile(filepath.Join(newd, "issue.yml"))
|
||||
assert.NoError(t, err)
|
||||
var after = make([]*base.Issue, 0, 10)
|
||||
after := make([]*base.Issue, 0, 10)
|
||||
assert.NoError(t, yaml.Unmarshal(afterBytes, &after))
|
||||
|
||||
assert.EqualValues(t, len(before), len(after))
|
||||
|
@@ -120,7 +120,6 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
|
||||
}
|
||||
|
||||
func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *httptest.ResponseRecorder {
|
||||
|
||||
// Get to the 'edit this file' page
|
||||
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
@@ -69,7 +69,7 @@ func TestEventSourceManagerRun(t *testing.T) {
|
||||
DecodeJSON(t, resp, &apiNL)
|
||||
assert.Len(t, apiNL, 2)
|
||||
|
||||
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" //946687801 <- only Notification 4 is in this filter ...
|
||||
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ...
|
||||
req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?last_read_at=%s&token=%s", user2.Name, repo1.Name, lastReadAt, token))
|
||||
session.MakeRequest(t, req, http.StatusResetContent)
|
||||
|
||||
|
@@ -27,12 +27,11 @@ import (
|
||||
)
|
||||
|
||||
func withKeyFile(t *testing.T, keyname string, callback func(string)) {
|
||||
|
||||
tmpDir, err := os.MkdirTemp("", "key-file")
|
||||
assert.NoError(t, err)
|
||||
defer util.RemoveAll(tmpDir)
|
||||
|
||||
err = os.Chmod(tmpDir, 0700)
|
||||
err = os.Chmod(tmpDir, 0o700)
|
||||
assert.NoError(t, err)
|
||||
|
||||
keyFile := filepath.Join(tmpDir, keyname)
|
||||
@@ -40,10 +39,10 @@ func withKeyFile(t *testing.T, keyname string, callback func(string)) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = os.WriteFile(path.Join(tmpDir, "ssh"), []byte("#!/bin/bash\n"+
|
||||
"ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"IdentitiesOnly=yes\" -i \""+keyFile+"\" \"$@\""), 0700)
|
||||
"ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"IdentitiesOnly=yes\" -i \""+keyFile+"\" \"$@\""), 0o700)
|
||||
assert.NoError(t, err)
|
||||
|
||||
//Setup ssh wrapper
|
||||
// Setup ssh wrapper
|
||||
os.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
|
||||
os.Setenv("GIT_SSH_COMMAND",
|
||||
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
|
||||
@@ -103,7 +102,7 @@ func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...
|
||||
}()
|
||||
|
||||
go s.Serve(listener)
|
||||
//Started by config go ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs)
|
||||
// Started by config go ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs)
|
||||
|
||||
callback(t, u)
|
||||
}
|
||||
@@ -142,7 +141,7 @@ func doGitInitTestRepository(dstPath string) func(*testing.T) {
|
||||
// forcibly set default branch to master
|
||||
_, err := git.NewCommand("symbolic-ref", "HEAD", git.BranchPrefix+"master").RunInDir(dstPath)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, os.WriteFile(filepath.Join(dstPath, "README.md"), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s", dstPath)), 0644))
|
||||
assert.NoError(t, os.WriteFile(filepath.Join(dstPath, "README.md"), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s", dstPath)), 0o644))
|
||||
assert.NoError(t, git.AddChanges(dstPath, true))
|
||||
signature := git.Signature{
|
||||
Email: "test@example.com",
|
||||
|
@@ -18,7 +18,7 @@ func TestGitSmartHTTP(t *testing.T) {
|
||||
}
|
||||
|
||||
func testGitSmartHTTP(t *testing.T, u *url.URL) {
|
||||
var kases = []struct {
|
||||
kases := []struct {
|
||||
p string
|
||||
code int
|
||||
}{
|
||||
|
@@ -32,8 +32,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
littleSize = 1024 //1ko
|
||||
bigSize = 128 * 1024 * 1024 //128Mo
|
||||
littleSize = 1024 // 1ko
|
||||
bigSize = 128 * 1024 * 1024 // 128Mo
|
||||
)
|
||||
|
||||
func TestGit(t *testing.T) {
|
||||
@@ -96,15 +96,15 @@ func testGit(t *testing.T, u *url.URL) {
|
||||
t.Run("AddUserAsCollaborator", doAPIAddCollaborator(forkedUserCtx, sshContext.Username, perm.AccessModeRead))
|
||||
t.Run("ForkFromDifferentUser", doAPIForkRepository(sshContext, forkedUserCtx.Username))
|
||||
|
||||
//Setup key the user ssh key
|
||||
// Setup key the user ssh key
|
||||
withKeyFile(t, keyname, func(keyFile string) {
|
||||
t.Run("CreateUserKey", doAPICreateUserKey(sshContext, "test-key", keyFile))
|
||||
|
||||
//Setup remote link
|
||||
//TODO: get url from api
|
||||
// Setup remote link
|
||||
// TODO: get url from api
|
||||
sshURL := createSSHUrl(sshContext.GitPath(), u)
|
||||
|
||||
//Setup clone folder
|
||||
// Setup clone folder
|
||||
dstPath, err := os.MkdirTemp("", sshContext.Reponame)
|
||||
assert.NoError(t, err)
|
||||
defer util.RemoveAll(dstPath)
|
||||
@@ -135,7 +135,6 @@ func ensureAnonymousClone(t *testing.T, u *url.URL) {
|
||||
assert.NoError(t, err)
|
||||
defer util.RemoveAll(dstLocalPath)
|
||||
t.Run("CloneAnonymous", doGitClone(dstLocalPath, u))
|
||||
|
||||
}
|
||||
|
||||
func standardCommitAndPushTest(t *testing.T, dstPath string) (little, big string) {
|
||||
@@ -300,13 +299,13 @@ func lockFileTest(t *testing.T, filename, repoPath string) {
|
||||
func doCommitAndPush(t *testing.T, size int, repoPath, prefix string) string {
|
||||
name, err := generateCommitWithNewData(size, repoPath, "user2@example.com", "User Two", prefix)
|
||||
assert.NoError(t, err)
|
||||
_, err = git.NewCommand("push", "origin", "master").RunInDir(repoPath) //Push
|
||||
_, err = git.NewCommand("push", "origin", "master").RunInDir(repoPath) // Push
|
||||
assert.NoError(t, err)
|
||||
return name
|
||||
}
|
||||
|
||||
func generateCommitWithNewData(size int, repoPath, email, fullName, prefix string) (string, error) {
|
||||
//Generate random file
|
||||
// Generate random file
|
||||
bufSize := 4 * 1024
|
||||
if bufSize > size {
|
||||
bufSize = size
|
||||
@@ -339,7 +338,7 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
|
||||
return "", err
|
||||
}
|
||||
|
||||
//Commit
|
||||
// Commit
|
||||
// Now here we should explicitly allow lfs filters to run
|
||||
globalArgs := allowLFSFilters()
|
||||
err = git.AddChangesWithArgs(repoPath, globalArgs, false, filepath.Base(tmpFile.Name()))
|
||||
@@ -639,7 +638,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
||||
t.Run("CreateHeadBranch", doGitCreateBranch(dstPath, headBranch))
|
||||
|
||||
t.Run("AddCommit", func(t *testing.T) {
|
||||
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content"), 0666)
|
||||
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content"), 0o666)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
@@ -713,7 +712,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
||||
}
|
||||
|
||||
t.Run("AddCommit2", func(t *testing.T) {
|
||||
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content \n ## test content 2"), 0666)
|
||||
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content \n ## test content 2"), 0o666)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ func TestGPGGit(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer util.RemoveAll(tmpDir)
|
||||
|
||||
err = os.Chmod(tmpDir, 0700)
|
||||
err = os.Chmod(tmpDir, 0o700)
|
||||
assert.NoError(t, err)
|
||||
|
||||
oldGNUPGHome := os.Getenv("GNUPGHOME")
|
||||
@@ -257,7 +257,6 @@ func TestGPGGit(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, "gitea@fake.local", response.Verification.Signer.Email)
|
||||
}))
|
||||
|
||||
})
|
||||
}, false)
|
||||
var pr api.PullRequest
|
||||
@@ -321,7 +320,6 @@ func TestGPGGit(t *testing.T) {
|
||||
assert.NotNil(t, branch.Commit.Verification)
|
||||
assert.True(t, branch.Commit.Verification.Verified)
|
||||
}))
|
||||
|
||||
})
|
||||
}, false)
|
||||
}
|
||||
|
@@ -268,10 +268,10 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
|
||||
}
|
||||
for _, repoDir := range repoDirs {
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
|
||||
return session
|
||||
}
|
||||
|
||||
//token has to be unique this counter take care of
|
||||
// token has to be unique this counter take care of
|
||||
var tokenCounter int64
|
||||
|
||||
func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
|
||||
@@ -564,10 +564,10 @@ func resetFixtures(t *testing.T) {
|
||||
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
|
||||
}
|
||||
for _, repoDir := range repoDirs {
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -121,7 +121,6 @@ func TestNoLoginViewIssue(t *testing.T) {
|
||||
}
|
||||
|
||||
func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content string) string {
|
||||
|
||||
req := NewRequest(t, "GET", path.Join(user, repo, "issues", "new"))
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
@@ -149,7 +148,6 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content
|
||||
}
|
||||
|
||||
func testIssueAddComment(t *testing.T, session *TestSession, issueURL, content, status string) int64 {
|
||||
|
||||
req := NewRequest(t, "GET", issueURL)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
@@ -244,7 +242,8 @@ func TestIssueCrossReference(t *testing.T) {
|
||||
RefIssueID: issueRef.ID,
|
||||
RefCommentID: 0,
|
||||
RefIsPull: false,
|
||||
RefAction: references.XRefActionNone})
|
||||
RefAction: references.XRefActionNone,
|
||||
})
|
||||
|
||||
// Edit title, neuter ref
|
||||
testIssueChangeInfo(t, "user2", issueRefURL, "title", "Title no ref")
|
||||
@@ -254,7 +253,8 @@ func TestIssueCrossReference(t *testing.T) {
|
||||
RefIssueID: issueRef.ID,
|
||||
RefCommentID: 0,
|
||||
RefIsPull: false,
|
||||
RefAction: references.XRefActionNeutered})
|
||||
RefAction: references.XRefActionNeutered,
|
||||
})
|
||||
|
||||
// Ref from issue content
|
||||
issueRefURL, issueRef = testIssueWithBean(t, "user2", 1, "TitleXRef", fmt.Sprintf("Description ref #%d", issueBase.Index))
|
||||
@@ -264,7 +264,8 @@ func TestIssueCrossReference(t *testing.T) {
|
||||
RefIssueID: issueRef.ID,
|
||||
RefCommentID: 0,
|
||||
RefIsPull: false,
|
||||
RefAction: references.XRefActionNone})
|
||||
RefAction: references.XRefActionNone,
|
||||
})
|
||||
|
||||
// Edit content, neuter ref
|
||||
testIssueChangeInfo(t, "user2", issueRefURL, "content", "Description no ref")
|
||||
@@ -274,7 +275,8 @@ func TestIssueCrossReference(t *testing.T) {
|
||||
RefIssueID: issueRef.ID,
|
||||
RefCommentID: 0,
|
||||
RefIsPull: false,
|
||||
RefAction: references.XRefActionNeutered})
|
||||
RefAction: references.XRefActionNeutered,
|
||||
})
|
||||
|
||||
// Ref from a comment
|
||||
session := loginUser(t, "user2")
|
||||
@@ -285,7 +287,8 @@ func TestIssueCrossReference(t *testing.T) {
|
||||
RefIssueID: issueRef.ID,
|
||||
RefCommentID: commentID,
|
||||
RefIsPull: false,
|
||||
RefAction: references.XRefActionNone}
|
||||
RefAction: references.XRefActionNone,
|
||||
}
|
||||
unittest.AssertExistsAndLoadBean(t, comment)
|
||||
|
||||
// Ref from a different repository
|
||||
@@ -296,7 +299,8 @@ func TestIssueCrossReference(t *testing.T) {
|
||||
RefIssueID: issueRef.ID,
|
||||
RefCommentID: 0,
|
||||
RefIsPull: false,
|
||||
RefAction: references.XRefActionNone})
|
||||
RefAction: references.XRefActionNone,
|
||||
})
|
||||
}
|
||||
|
||||
func testIssueWithBean(t *testing.T, user string, repoID int64, title, content string) (string, *models.Issue) {
|
||||
|
@@ -29,13 +29,13 @@ func TestDetermineLocalEndpoint(t *testing.T) {
|
||||
|
||||
rootdotgit, _ := os.MkdirTemp("", "lfs_test")
|
||||
defer os.RemoveAll(rootdotgit)
|
||||
os.Mkdir(filepath.Join(rootdotgit, ".git"), 0700)
|
||||
os.Mkdir(filepath.Join(rootdotgit, ".git"), 0o700)
|
||||
|
||||
lfsroot, _ := os.MkdirTemp("", "lfs_test")
|
||||
defer os.RemoveAll(lfsroot)
|
||||
|
||||
// Test cases
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
cloneurl string
|
||||
lfsurl string
|
||||
expected *url.URL
|
||||
|
@@ -20,7 +20,7 @@ import (
|
||||
func TestLinksNoLogin(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
var links = []string{
|
||||
links := []string{
|
||||
"/explore/repos",
|
||||
"/explore/repos?q=test&tab=",
|
||||
"/explore/users",
|
||||
@@ -49,7 +49,7 @@ func TestLinksNoLogin(t *testing.T) {
|
||||
func TestRedirectsNoLogin(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
var redirects = map[string]string{
|
||||
redirects := map[string]string{
|
||||
"/user2/repo1/commits/master": "/user2/repo1/commits/branch/master",
|
||||
"/user2/repo1/src/master": "/user2/repo1/src/branch/master",
|
||||
"/user2/repo1/src/master/file.txt": "/user2/repo1/src/branch/master/file.txt",
|
||||
@@ -67,7 +67,7 @@ func TestRedirectsNoLogin(t *testing.T) {
|
||||
func TestNoLoginNotExist(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
var links = []string{
|
||||
links := []string{
|
||||
"/user5/repo4/projects",
|
||||
"/user5/repo4/projects/3",
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func TestNoLoginNotExist(t *testing.T) {
|
||||
}
|
||||
|
||||
func testLinksAsUser(userName string, t *testing.T) {
|
||||
var links = []string{
|
||||
links := []string{
|
||||
"/explore/repos",
|
||||
"/explore/repos?q=test&tab=",
|
||||
"/explore/users",
|
||||
@@ -138,7 +138,7 @@ func testLinksAsUser(userName string, t *testing.T) {
|
||||
var apiRepos []*api.Repository
|
||||
DecodeJSON(t, respAPI, &apiRepos)
|
||||
|
||||
var repoLinks = []string{
|
||||
repoLinks := []string{
|
||||
"",
|
||||
"/issues",
|
||||
"/pulls",
|
||||
|
@@ -74,10 +74,10 @@ func initMigrationTest(t *testing.T) func() {
|
||||
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
|
||||
}
|
||||
for _, repoDir := range repoDirs {
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755)
|
||||
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +315,5 @@ func TestMigrations(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("Migrate-%s-%s", dialect, version), func(t *testing.T) {
|
||||
doMigrationTest(t, version)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -210,5 +210,4 @@ func TestNonasciiBranches(t *testing.T) {
|
||||
}
|
||||
|
||||
setDefaultBranch(t, session, user, repo, "master")
|
||||
|
||||
}
|
||||
|
@@ -18,8 +18,10 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const privateActivityTestAdmin = "user1"
|
||||
const privateActivityTestUser = "user2"
|
||||
const (
|
||||
privateActivityTestAdmin = "user1"
|
||||
privateActivityTestUser = "user2"
|
||||
)
|
||||
|
||||
// user3 is an organization so it is not usable here
|
||||
const privateActivityTestOtherUser = "user4"
|
||||
|
@@ -65,7 +65,7 @@ func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum str
|
||||
|
||||
func TestPullMerge(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
|
||||
hookTasks, err := webhook.HookTasks(1, 1) // Retrieve previous hook number
|
||||
assert.NoError(t, err)
|
||||
hookTasksLenBefore := len(hookTasks)
|
||||
|
||||
@@ -87,7 +87,7 @@ func TestPullMerge(t *testing.T) {
|
||||
|
||||
func TestPullRebase(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
|
||||
hookTasks, err := webhook.HookTasks(1, 1) // Retrieve previous hook number
|
||||
assert.NoError(t, err)
|
||||
hookTasksLenBefore := len(hookTasks)
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestPullRebase(t *testing.T) {
|
||||
|
||||
func TestPullRebaseMerge(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
|
||||
hookTasks, err := webhook.HookTasks(1, 1) // Retrieve previous hook number
|
||||
assert.NoError(t, err)
|
||||
hookTasksLenBefore := len(hookTasks)
|
||||
|
||||
@@ -131,7 +131,7 @@ func TestPullRebaseMerge(t *testing.T) {
|
||||
|
||||
func TestPullSquash(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
hookTasks, err := webhook.HookTasks(1, 1) //Retrieve previous hook number
|
||||
hookTasks, err := webhook.HookTasks(1, 1) // Retrieve previous hook number
|
||||
assert.NoError(t, err)
|
||||
hookTasksLenBefore := len(hookTasks)
|
||||
|
||||
|
@@ -23,12 +23,12 @@ import (
|
||||
|
||||
func TestAPIPullUpdate(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
//Create PR to test
|
||||
// Create PR to test
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
org26 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 26}).(*user_model.User)
|
||||
pr := createOutdatedPR(t, user, org26)
|
||||
|
||||
//Test GetDiverging
|
||||
// Test GetDiverging
|
||||
diffCount, err := pull_service.GetDiverging(git.DefaultContext, pr)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, diffCount.Behind)
|
||||
@@ -41,7 +41,7 @@ func TestAPIPullUpdate(t *testing.T) {
|
||||
req := NewRequestf(t, "POST", "/api/v1/repos/%s/%s/pulls/%d/update?token="+token, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, pr.Issue.Index)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
//Test GetDiverging after update
|
||||
// Test GetDiverging after update
|
||||
diffCount, err = pull_service.GetDiverging(git.DefaultContext, pr)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 0, diffCount.Behind)
|
||||
@@ -51,12 +51,12 @@ func TestAPIPullUpdate(t *testing.T) {
|
||||
|
||||
func TestAPIPullUpdateByRebase(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
//Create PR to test
|
||||
// Create PR to test
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
org26 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 26}).(*user_model.User)
|
||||
pr := createOutdatedPR(t, user, org26)
|
||||
|
||||
//Test GetDiverging
|
||||
// Test GetDiverging
|
||||
diffCount, err := pull_service.GetDiverging(git.DefaultContext, pr)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, diffCount.Behind)
|
||||
@@ -69,7 +69,7 @@ func TestAPIPullUpdateByRebase(t *testing.T) {
|
||||
req := NewRequestf(t, "POST", "/api/v1/repos/%s/%s/pulls/%d/update?style=rebase&token="+token, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, pr.Issue.Index)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
//Test GetDiverging after update
|
||||
// Test GetDiverging after update
|
||||
diffCount, err = pull_service.GetDiverging(git.DefaultContext, pr)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 0, diffCount.Behind)
|
||||
@@ -98,7 +98,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *models.Pul
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, headRepo)
|
||||
|
||||
//create a commit on base Repo
|
||||
// create a commit on base Repo
|
||||
_, err = files_service.CreateOrUpdateRepoFile(git.DefaultContext, baseRepo, actor, &files_service.UpdateRepoFileOptions{
|
||||
TreePath: "File_A",
|
||||
Message: "Add File A",
|
||||
@@ -121,7 +121,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *models.Pul
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
//create a commit on head Repo
|
||||
// create a commit on head Repo
|
||||
_, err = files_service.CreateOrUpdateRepoFile(git.DefaultContext, headRepo, actor, &files_service.UpdateRepoFileOptions{
|
||||
TreePath: "File_B",
|
||||
Message: "Add File on PR branch",
|
||||
@@ -144,7 +144,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *models.Pul
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
//create Pull
|
||||
// create Pull
|
||||
pullIssue := &models.Issue{
|
||||
RepoID: baseRepo.ID,
|
||||
Title: "Test Pull -to-update-",
|
||||
|
@@ -18,7 +18,6 @@ import (
|
||||
|
||||
func TestRepoActivity(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
// Create PRs (1 merged & 2 proposed)
|
||||
|
@@ -71,12 +71,12 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||
assert.True(t, sel.HasClass(class))
|
||||
}
|
||||
|
||||
//By SHA
|
||||
// By SHA
|
||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/statuses")
|
||||
reqOne := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/status")
|
||||
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
|
||||
|
||||
//By Ref
|
||||
// By Ref
|
||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/statuses")
|
||||
reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/status")
|
||||
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
|
||||
|
@@ -399,7 +399,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
|
||||
|
||||
t.Run("create file that already exists", func(t *testing.T) {
|
||||
opts := getCreateRepoFileOptions(repo)
|
||||
opts.TreePath = "README.md" //already exists
|
||||
opts.TreePath = "README.md" // already exists
|
||||
fileResponse, err := files_service.CreateOrUpdateRepoFile(git.DefaultContext, repo, doer, opts)
|
||||
assert.Nil(t, fileResponse)
|
||||
assert.Error(t, err)
|
||||
|
@@ -77,7 +77,6 @@ func TestSettingShowUserEmailProfile(t *testing.T) {
|
||||
htmlDoc.doc.Find(".user.profile").Text(),
|
||||
"user2@example.com",
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func TestSettingLandingPage(t *testing.T) {
|
||||
|
@@ -28,7 +28,7 @@ func doCheckRepositoryEmptyStatus(ctx APITestContext, isEmpty bool) func(*testin
|
||||
|
||||
func doAddChangesToCheckout(dstPath, filename string) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
assert.NoError(t, os.WriteFile(filepath.Join(dstPath, filename), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s at time: %v", dstPath, time.Now())), 0644))
|
||||
assert.NoError(t, os.WriteFile(filepath.Join(dstPath, filename), []byte(fmt.Sprintf("# Testing Repository\n\nOriginally created in: %s at time: %v", dstPath, time.Now())), 0o644))
|
||||
assert.NoError(t, git.AddChanges(dstPath, true))
|
||||
signature := git.Signature{
|
||||
Email: "test@example.com",
|
||||
@@ -67,7 +67,7 @@ func testPushDeployKeyOnEmptyRepo(t *testing.T, u *url.URL) {
|
||||
|
||||
t.Run("InitTestRepository", doGitInitTestRepository(dstPath))
|
||||
|
||||
//Setup remote link
|
||||
// Setup remote link
|
||||
sshURL := createSSHUrl(ctx.GitPath(), u)
|
||||
|
||||
t.Run("AddRemote", doGitAddRemote(dstPath, "origin", sshURL))
|
||||
|
@@ -185,7 +185,7 @@ func (log *TestLogger) Init(config string) error {
|
||||
func (log *TestLogger) Flush() {
|
||||
}
|
||||
|
||||
//ReleaseReopen does nothing
|
||||
// ReleaseReopen does nothing
|
||||
func (log *TestLogger) ReleaseReopen() error {
|
||||
return nil
|
||||
}
|
||||
|
@@ -19,15 +19,16 @@ func TestViewTimetrackingControls(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
session := loginUser(t, "user2")
|
||||
testViewTimetrackingControls(t, session, "user2", "repo1", "1", true)
|
||||
//user2/repo1
|
||||
// user2/repo1
|
||||
}
|
||||
|
||||
func TestNotViewTimetrackingControls(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
session := loginUser(t, "user5")
|
||||
testViewTimetrackingControls(t, session, "user2", "repo1", "1", false)
|
||||
//user2/repo1
|
||||
// user2/repo1
|
||||
}
|
||||
|
||||
func TestViewTimetrackingControlsDisabled(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
session := loginUser(t, "user2")
|
||||
|
@@ -42,7 +42,7 @@ func TestUserAvatar(t *testing.T) {
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
|
||||
//Setup multi-part
|
||||
// Setup multi-part
|
||||
writer := multipart.NewWriter(body)
|
||||
writer.WriteField("source", "local")
|
||||
part, err := writer.CreateFormFile("avatar", "avatar-for-testuseravatar.png")
|
||||
|
@@ -119,15 +119,15 @@ func TestRenameReservedUsername(t *testing.T) {
|
||||
|
||||
func TestExportUserGPGKeys(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
//Export empty key list
|
||||
// Export empty key list
|
||||
testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
|
||||
=twTO
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
`)
|
||||
//Import key
|
||||
//User1 <user1@example.com>
|
||||
// Import key
|
||||
// User1 <user1@example.com>
|
||||
session := loginUser(t, "user1")
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
testCreateGPGKey(t, session.MakeRequest, token, http.StatusCreated, `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
@@ -161,7 +161,7 @@ GrE0MHOxUbc9tbtyk0F1SuzREUBH
|
||||
=DDXw
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
`)
|
||||
//Export new key
|
||||
// Export new key
|
||||
testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
xsBNBFyy/VUBCADJ7zbM20Z1RWmFoVgp5WkQfI2rU1Vj9cQHes9i42wVLLtcbPeo
|
||||
@@ -200,6 +200,6 @@ func testExportUserGPGKeys(t *testing.T, user, expected string) {
|
||||
t.Logf("Testing username %s export gpg keys", user)
|
||||
req := NewRequest(t, "GET", "/"+user+".gpg")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
//t.Log(resp.Body.String())
|
||||
// t.Log(resp.Body.String())
|
||||
assert.Equal(t, expected, resp.Body.String())
|
||||
}
|
||||
|
Reference in New Issue
Block a user