mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:49:52 +01:00
Remove unnecessary variable assignments (#17695)
* Remove unnecessary variable assignments As title * enable ineffassign Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
b01f6c1a8c
commit
c98dd7a3e0
32 changed files with 59 additions and 72 deletions
|
@ -15,6 +15,7 @@ linters:
|
|||
- misspell
|
||||
- gocritic
|
||||
- bidichk
|
||||
- ineffassign
|
||||
enable-all: false
|
||||
disable-all: true
|
||||
fast: false
|
||||
|
|
|
@ -293,7 +293,6 @@ Gitea or set your environment appropriately.`, "")
|
|||
}
|
||||
} else if lastline > 0 {
|
||||
fmt.Fprintf(out, "\n")
|
||||
lastline = 0
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "Checked %d references in total\n", total)
|
||||
|
|
|
@ -224,7 +224,6 @@ func DecodeSectionKey(encoded string) (string, string) {
|
|||
if !inKey {
|
||||
if splitter := strings.Index(remaining, "__"); splitter > -1 {
|
||||
section += remaining[:splitter]
|
||||
inKey = true
|
||||
key += remaining[splitter+2:]
|
||||
} else {
|
||||
section += remaining
|
||||
|
|
|
@ -119,9 +119,9 @@ func TestAPIGetComment(t *testing.T) {
|
|||
session := loginUser(t, repoOwner.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d?token=%s", repoOwner.Name, repo.Name, comment.ID, token)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var apiComment api.Comment
|
||||
DecodeJSON(t, resp, &apiComment)
|
||||
|
|
|
@ -83,7 +83,7 @@ func TestAPIModifyLabels(t *testing.T) {
|
|||
|
||||
//DeleteLabel
|
||||
req = NewRequest(t, "DELETE", singleURLStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
}
|
||||
|
||||
|
@ -203,6 +203,6 @@ func TestAPIModifyOrgLabels(t *testing.T) {
|
|||
|
||||
//DeleteLabel
|
||||
req = NewRequest(t, "DELETE", singleURLStr)
|
||||
resp = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
}
|
||||
|
|
|
@ -74,5 +74,5 @@ func TestAPIIssuesMilestone(t *testing.T) {
|
|||
assert.Equal(t, int64(2), apiMilestones[0].ID)
|
||||
|
||||
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d?token=%s", owner.Name, repo.Name, apiMilestone.ID, token))
|
||||
resp = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
}
|
||||
|
|
|
@ -36,24 +36,24 @@ func TestAPIIssuesReactions(t *testing.T) {
|
|||
req := NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "wrong",
|
||||
})
|
||||
resp := session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Delete not allowed reaction
|
||||
req = NewRequestWithJSON(t, "DELETE", urlStr, &api.EditReactionOption{
|
||||
Reaction: "zzz",
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
//Add allowed reaction
|
||||
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "rocket",
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusCreated)
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
var apiNewReaction api.Reaction
|
||||
DecodeJSON(t, resp, &apiNewReaction)
|
||||
|
||||
//Add existing reaction
|
||||
resp = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Get end result of reaction list of issue #1
|
||||
req = NewRequestf(t, "GET", urlStr)
|
||||
|
@ -96,24 +96,24 @@ func TestAPICommentReactions(t *testing.T) {
|
|||
req := NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "wrong",
|
||||
})
|
||||
resp := session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Delete none existing reaction
|
||||
req = NewRequestWithJSON(t, "DELETE", urlStr, &api.EditReactionOption{
|
||||
Reaction: "eyes",
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
//Add allowed reaction
|
||||
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
|
||||
Reaction: "+1",
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusCreated)
|
||||
resp := session.MakeRequest(t, req, http.StatusCreated)
|
||||
var apiNewReaction api.Reaction
|
||||
DecodeJSON(t, resp, &apiNewReaction)
|
||||
|
||||
//Add existing reaction
|
||||
resp = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
//Get end result of reaction list of issue #1
|
||||
req = NewRequestf(t, "GET", urlStr)
|
||||
|
|
|
@ -66,7 +66,7 @@ func TestAPINotification(t *testing.T) {
|
|||
// -- GET /notifications/threads/{id} --
|
||||
// get forbidden
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", 1, token))
|
||||
resp = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
// get own
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
|
||||
|
@ -100,7 +100,7 @@ func TestAPINotification(t *testing.T) {
|
|||
|
||||
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))
|
||||
resp = session.MakeRequest(t, req, http.StatusResetContent)
|
||||
session.MakeRequest(t, req, http.StatusResetContent)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?status-types=unread&token=%s", token))
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
@ -109,7 +109,7 @@ func TestAPINotification(t *testing.T) {
|
|||
|
||||
// -- PATCH /notifications/threads/{id} --
|
||||
req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
|
||||
resp = session.MakeRequest(t, req, http.StatusResetContent)
|
||||
session.MakeRequest(t, req, http.StatusResetContent)
|
||||
|
||||
assert.Equal(t, models.NotificationStatusUnread, thread5.Status)
|
||||
thread5 = unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
|
||||
|
|
|
@ -140,7 +140,7 @@ func TestAPIPullReview(t *testing.T) {
|
|||
assert.EqualValues(t, "COMMENT", review.State)
|
||||
assert.EqualValues(t, 0, review.CodeCommentsCount)
|
||||
req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, review.ID, token)
|
||||
resp = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// test CreatePullReview Comment without body but with 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{
|
||||
|
|
|
@ -145,7 +145,6 @@ func TestAPIRepoEdit(t *testing.T) {
|
|||
// Get user2's token
|
||||
session := loginUser(t, user2.Name)
|
||||
token2 := getTokenForLoggedInUser(t, session)
|
||||
session = emptyTestSession(t)
|
||||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
token4 := getTokenForLoggedInUser(t, session)
|
||||
|
@ -223,15 +222,15 @@ func TestAPIRepoEdit(t *testing.T) {
|
|||
// Do some tests with invalid URL for external tracker and wiki
|
||||
repoEditOption.ExternalTracker.ExternalTrackerURL = "htp://www.somewebsite.com"
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
repoEditOption.ExternalTracker.ExternalTrackerURL = "http://www.somewebsite.com"
|
||||
repoEditOption.ExternalTracker.ExternalTrackerFormat = "http://www.somewebsite.com/{user/{repo}?issue={index}"
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
repoEditOption.ExternalTracker.ExternalTrackerFormat = "http://www.somewebsite.com/{user}/{repo}?issue={index}"
|
||||
repoEditOption.ExternalWiki.ExternalWikiURL = "htp://www.somewebsite.com"
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
//Test small repo change through API with issue and wiki option not set; They shall not be touched.
|
||||
*repoEditOption.Description = "small change"
|
||||
|
|
|
@ -149,7 +149,6 @@ func TestAPICreateFile(t *testing.T) {
|
|||
// Get user2's token
|
||||
session := loginUser(t, user2.Name)
|
||||
token2 := getTokenForLoggedInUser(t, session)
|
||||
session = emptyTestSession(t)
|
||||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
token4 := getTokenForLoggedInUser(t, session)
|
||||
|
|
|
@ -49,7 +49,6 @@ func TestAPIDeleteFile(t *testing.T) {
|
|||
// Get user2's token
|
||||
session := loginUser(t, user2.Name)
|
||||
token2 := getTokenForLoggedInUser(t, session)
|
||||
session = emptyTestSession(t)
|
||||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
token4 := getTokenForLoggedInUser(t, session)
|
||||
|
@ -111,7 +110,7 @@ func TestAPIDeleteFile(t *testing.T) {
|
|||
deleteFileOptions.SHA = "badsha"
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
|
||||
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
|
||||
resp = session.MakeRequest(t, req, http.StatusBadRequest)
|
||||
session.MakeRequest(t, req, http.StatusBadRequest)
|
||||
|
||||
// Test creating a file in repo16 by user4 who does not have write access
|
||||
fileID++
|
||||
|
|
|
@ -115,7 +115,6 @@ func TestAPIUpdateFile(t *testing.T) {
|
|||
// Get user2's token
|
||||
session := loginUser(t, user2.Name)
|
||||
token2 := getTokenForLoggedInUser(t, session)
|
||||
session = emptyTestSession(t)
|
||||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
token4 := getTokenForLoggedInUser(t, session)
|
||||
|
|
|
@ -64,7 +64,6 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
|
|||
// Get user2's token
|
||||
session := loginUser(t, user2.Name)
|
||||
token2 := getTokenForLoggedInUser(t, session)
|
||||
session = emptyTestSession(t)
|
||||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
token4 := getTokenForLoggedInUser(t, session)
|
||||
|
@ -139,7 +138,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
|
|||
// Test file contents a file with a bad ref
|
||||
ref = "badref"
|
||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
|
||||
resp = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Test accessing private ref with user token that does not have access - should fail
|
||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
|
||||
|
|
|
@ -65,7 +65,6 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
|
|||
// Get user2's token
|
||||
session := loginUser(t, user2.Name)
|
||||
token2 := getTokenForLoggedInUser(t, session)
|
||||
session = emptyTestSession(t)
|
||||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
token4 := getTokenForLoggedInUser(t, session)
|
||||
|
@ -141,7 +140,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
|
|||
// Test file contents a file with a bad ref
|
||||
ref = "badref"
|
||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
|
||||
resp = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Test accessing private ref with user token that does not have access - should fail
|
||||
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
|
||||
|
|
|
@ -62,10 +62,10 @@ func TestAPIRepoTags(t *testing.T) {
|
|||
|
||||
// delete tag
|
||||
delReq := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/tags/%s?token=%s", user.Name, repoName, newTag.Name, token)
|
||||
resp = session.MakeRequest(t, delReq, http.StatusNoContent)
|
||||
session.MakeRequest(t, delReq, http.StatusNoContent)
|
||||
|
||||
// check if it's gone
|
||||
resp = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func createNewTagUsingAPI(t *testing.T, session *TestSession, token string, ownerName, repoName, name, target, msg string) *api.Tag {
|
||||
|
|
|
@ -54,12 +54,12 @@ func TestAPIRepoTeams(t *testing.T) {
|
|||
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "NonExistingTeam", token)
|
||||
req = NewRequest(t, "GET", url)
|
||||
res = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// AddTeam with user4
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
|
||||
req = NewRequest(t, "PUT", url)
|
||||
res = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
// AddTeam with user2
|
||||
user = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
|
@ -67,12 +67,12 @@ func TestAPIRepoTeams(t *testing.T) {
|
|||
token = getTokenForLoggedInUser(t, session)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
|
||||
req = NewRequest(t, "PUT", url)
|
||||
res = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
res = session.MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
|
||||
|
||||
// DeleteTeam
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
|
||||
req = NewRequest(t, "DELETE", url)
|
||||
res = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
res = session.MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity) // test duplicate request
|
||||
}
|
||||
|
|
|
@ -75,15 +75,15 @@ func TestAPIRepoTopic(t *testing.T) {
|
|||
|
||||
// Test delete a topic
|
||||
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "Topicname1", token2)
|
||||
res = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// Test add an existing topic
|
||||
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "Golang", token2)
|
||||
res = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// Test add a topic
|
||||
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "topicName3", token2)
|
||||
res = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// Test read topics using token
|
||||
req = NewRequest(t, "GET", url)
|
||||
|
@ -96,7 +96,7 @@ func TestAPIRepoTopic(t *testing.T) {
|
|||
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
|
||||
Topics: newTopics,
|
||||
})
|
||||
res = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
req = NewRequest(t, "GET", url)
|
||||
res = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, res, &topics)
|
||||
|
@ -107,7 +107,7 @@ func TestAPIRepoTopic(t *testing.T) {
|
|||
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
|
||||
Topics: newTopics,
|
||||
})
|
||||
res = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
req = NewRequest(t, "GET", url)
|
||||
res = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, res, &topics)
|
||||
|
@ -118,7 +118,7 @@ func TestAPIRepoTopic(t *testing.T) {
|
|||
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
|
||||
Topics: newTopics,
|
||||
})
|
||||
res = session.MakeRequest(t, req, http.StatusNoContent)
|
||||
session.MakeRequest(t, req, http.StatusNoContent)
|
||||
req = NewRequest(t, "GET", url)
|
||||
res = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, res, &topics)
|
||||
|
@ -129,15 +129,15 @@ func TestAPIRepoTopic(t *testing.T) {
|
|||
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
|
||||
Topics: newTopics,
|
||||
})
|
||||
res = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
// Test add a topic when there is already maximum
|
||||
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "t26", token2)
|
||||
res = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
// Test delete a topic that repo doesn't have
|
||||
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "Topicname1", token2)
|
||||
res = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Get user4's token
|
||||
session = loginUser(t, user4.Name)
|
||||
|
@ -153,6 +153,6 @@ 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)
|
||||
res = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
}
|
||||
|
|
|
@ -160,6 +160,6 @@ func TestAPITeamSearch(t *testing.T) {
|
|||
csrf = GetCSRF(t, session, "/"+org.Name)
|
||||
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "team")
|
||||
req.Header.Add("X-Csrf-Token", csrf)
|
||||
resp = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
}
|
||||
|
|
|
@ -72,13 +72,13 @@ func TestMyOrgs(t *testing.T) {
|
|||
|
||||
session := emptyTestSession(t)
|
||||
req := NewRequest(t, "GET", "/api/v1/user/orgs")
|
||||
resp := session.MakeRequest(t, req, http.StatusUnauthorized)
|
||||
session.MakeRequest(t, req, http.StatusUnauthorized)
|
||||
|
||||
normalUsername := "user2"
|
||||
session = loginUser(t, normalUsername)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
req = NewRequest(t, "GET", "/api/v1/user/orgs?token="+token)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
var orgs []*api.Organization
|
||||
DecodeJSON(t, resp, &orgs)
|
||||
user3 := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
|
||||
|
|
|
@ -69,7 +69,7 @@ func TestEventSourceManagerRun(t *testing.T) {
|
|||
|
||||
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))
|
||||
resp = session.MakeRequest(t, req, http.StatusResetContent)
|
||||
session.MakeRequest(t, req, http.StatusResetContent)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications?token=%s&status-types=unread", token))
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
|
|
@ -287,7 +287,7 @@ func TestIssueCrossReference(t *testing.T) {
|
|||
unittest.AssertExistsAndLoadBean(t, comment)
|
||||
|
||||
// Ref from a different repository
|
||||
issueRefURL, issueRef = testIssueWithBean(t, "user12", 10, "TitleXRef", fmt.Sprintf("Description ref user2/repo1#%d", issueBase.Index))
|
||||
_, issueRef = testIssueWithBean(t, "user12", 10, "TitleXRef", fmt.Sprintf("Description ref user2/repo1#%d", issueBase.Index))
|
||||
unittest.AssertExistsAndLoadBean(t, &models.Comment{
|
||||
IssueID: issueBase.ID,
|
||||
RefRepoID: 10,
|
||||
|
|
|
@ -33,12 +33,12 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
|||
|
||||
req = NewRequest(t, "GET", "/user1/repo1/pulls")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
NewHTMLParser(t, resp.Body)
|
||||
|
||||
// Request repository commits page
|
||||
req = NewRequest(t, "GET", "/user1/repo1/pulls/1/commits")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
doc = NewHTMLParser(t, resp.Body)
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
// Get first commit URL
|
||||
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Last().Attr("href")
|
||||
|
|
|
@ -21,11 +21,11 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO
|
|||
|
||||
// Step0: check the existence of the to-fork repo
|
||||
req := NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName)
|
||||
resp := session.MakeRequest(t, req, http.StatusNotFound)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Step1: go to the main page of repo
|
||||
req = NewRequestf(t, "GET", "/%s/%s", ownerName, repoName)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Step2: click the fork button
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
|
|
@ -21,11 +21,11 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateOwnerName, tem
|
|||
|
||||
// Step0: check the existence of the generated repo
|
||||
req := NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName)
|
||||
resp := session.MakeRequest(t, req, http.StatusNotFound)
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Step1: go to the main page of template repo
|
||||
req = NewRequestf(t, "GET", "/%s/%s", templateOwnerName, templateRepoName)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Step2: click the "Use this template" button
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
|
|
@ -72,7 +72,7 @@ func TestMakeIDsFromAPIAssigneesToAdd(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, []int64{}, IDs)
|
||||
|
||||
IDs, err = MakeIDsFromAPIAssigneesToAdd("", []string{"none_existing_user"})
|
||||
_, err = MakeIDsFromAPIAssigneesToAdd("", []string{"none_existing_user"})
|
||||
assert.Error(t, err)
|
||||
|
||||
IDs, err = MakeIDsFromAPIAssigneesToAdd("user1", []string{"user1"})
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
func TestAddTopic(t *testing.T) {
|
||||
totalNrOfTopics := 6
|
||||
repo1NrOfTopics := 3
|
||||
repo2NrOfTopics := 2
|
||||
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
|
@ -38,7 +37,7 @@ func TestAddTopic(t *testing.T) {
|
|||
assert.Len(t, topics, repo1NrOfTopics)
|
||||
|
||||
assert.NoError(t, SaveTopics(2, "golang"))
|
||||
repo2NrOfTopics = 1
|
||||
repo2NrOfTopics := 1
|
||||
topics, _, err = FindTopics(&FindTopicOptions{})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, topics, totalNrOfTopics)
|
||||
|
|
|
@ -111,14 +111,14 @@ func TestListEmails(t *testing.T) {
|
|||
|
||||
// Must find only primary addresses (i.e. from the `user` table)
|
||||
opts = &SearchEmailOptions{IsPrimary: util.OptionalBoolTrue}
|
||||
emails, count, err = SearchEmails(opts)
|
||||
emails, _, err = SearchEmails(opts)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, contains(func(s *SearchEmailResult) bool { return s.IsPrimary }))
|
||||
assert.False(t, contains(func(s *SearchEmailResult) bool { return !s.IsPrimary }))
|
||||
|
||||
// Must find only inactive addresses (i.e. not validated)
|
||||
opts = &SearchEmailOptions{IsActivated: util.OptionalBoolFalse}
|
||||
emails, count, err = SearchEmails(opts)
|
||||
emails, _, err = SearchEmails(opts)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, contains(func(s *SearchEmailResult) bool { return !s.IsActivated }))
|
||||
assert.False(t, contains(func(s *SearchEmailResult) bool { return s.IsActivated }))
|
||||
|
|
|
@ -55,11 +55,10 @@ func BenchmarkParseGlyphs(b *testing.B) {
|
|||
parser.Reset()
|
||||
tgBytes := []byte(testglyphs)
|
||||
tg := tgBytes
|
||||
idx := bytes.Index(tg, []byte("\n"))
|
||||
for i := 0; i < b.N; i++ {
|
||||
parser.Reset()
|
||||
tg = tgBytes
|
||||
idx = bytes.Index(tg, []byte("\n"))
|
||||
idx := bytes.Index(tg, []byte("\n"))
|
||||
for idx > 0 {
|
||||
parser.ParseGlyphs(tg[:idx])
|
||||
tg = tg[idx+1:]
|
||||
|
|
|
@ -48,13 +48,12 @@ func (m *Manager) GetLevelDB(connection string) (*leveldb.DB, error) {
|
|||
|
||||
return db.db, nil
|
||||
}
|
||||
dataDir := connection
|
||||
uri := ToLevelDBURI(connection)
|
||||
db = &levelDBHolder{
|
||||
name: []string{connection, uri.String()},
|
||||
}
|
||||
|
||||
dataDir = path.Join(uri.Host, uri.Path)
|
||||
dataDir := path.Join(uri.Host, uri.Path)
|
||||
opts := &opt.Options{}
|
||||
for k, v := range uri.Query() {
|
||||
switch replacer.Replace(strings.ToLower(k)) {
|
||||
|
|
|
@ -93,11 +93,9 @@ func Validate(errs binding.Errors, data map[string]interface{}, f Form, l transl
|
|||
AssignForm(f, data)
|
||||
|
||||
typ := reflect.TypeOf(f)
|
||||
val := reflect.ValueOf(f)
|
||||
|
||||
if typ.Kind() == reflect.Ptr {
|
||||
typ = typ.Elem()
|
||||
val = val.Elem()
|
||||
}
|
||||
|
||||
if field, ok := typ.FieldByName(errs[0].FieldNames[0]); ok {
|
||||
|
|
|
@ -91,7 +91,6 @@ func TeamsAction(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
err = ctx.Org.Team.RemoveMember(uid)
|
||||
page = "team"
|
||||
if err != nil {
|
||||
if models.IsErrLastOrgOwner(err) {
|
||||
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
|
||||
|
|
Loading…
Reference in a new issue