mirror of
https://github.com/go-gitea/gitea
synced 2024-11-20 00:54:25 +00:00
Fixed ineffectual assignments in tests (#7553)
Just makes it a bit more obvious which values we want to test for, and which ones we want to ignore.
This commit is contained in:
parent
cc384d767e
commit
12a098920c
@ -146,13 +146,13 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
// reset repo in db
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, *repoEditOption.Name, token2)
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &origRepoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Test editing a non-existing repo
|
||||
name := "repodoesnotexist"
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, name, token2)
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &api.EditRepoOption{Name: &name})
|
||||
resp = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
_ = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Test editing repo16 by user4 who does not have write access
|
||||
origRepoEditOption = getRepoEditOptionFromRepo(repo16)
|
||||
@ -166,18 +166,18 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
repoEditOption = getNewRepoEditOption(origRepoEditOption)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s", user2.Name, repo16.Name)
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
_ = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Test using access token for a private repo that the user of the token owns
|
||||
origRepoEditOption = getRepoEditOptionFromRepo(repo16)
|
||||
repoEditOption = getNewRepoEditOption(origRepoEditOption)
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo16.Name, token2)
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
// reset repo in db
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, *repoEditOption.Name, token2)
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &origRepoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Test making a repo public that is private
|
||||
repo16 = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
|
||||
@ -188,14 +188,14 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
}
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo16.Name, token2)
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
repo16 = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
|
||||
assert.False(t, repo16.IsPrivate)
|
||||
// Make it private again
|
||||
private = true
|
||||
repoEditOption.Private = &private
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Test using org repo "user3/repo3" where user2 is a collaborator
|
||||
origRepoEditOption = getRepoEditOptionFromRepo(repo3)
|
||||
@ -206,7 +206,7 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||
// reset repo in db
|
||||
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user3.Name, *repoEditOption.Name, token2)
|
||||
req = NewRequestWithJSON(t, "PATCH", url, &origRepoEditOption)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Test using org repo "user3/repo3" with no user token
|
||||
origRepoEditOption = getRepoEditOptionFromRepo(repo3)
|
||||
|
@ -41,10 +41,10 @@ func TestAPITeam(t *testing.T) {
|
||||
session = loginUser(t, user2.Name)
|
||||
token = getTokenForLoggedInUser(t, session)
|
||||
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamUser.TeamID)
|
||||
resp = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
_ = session.MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
req = NewRequestf(t, "GET", "/api/v1/teams/%d", teamUser.TeamID)
|
||||
resp = session.MakeRequest(t, req, http.StatusUnauthorized)
|
||||
_ = session.MakeRequest(t, req, http.StatusUnauthorized)
|
||||
|
||||
// Get an admin user able to create, update and delete teams.
|
||||
user = models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
|
||||
|
@ -55,13 +55,13 @@ func TestHasAccess(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
|
||||
has, err = HasAccess(user1.ID, repo2)
|
||||
_, err = HasAccess(user1.ID, repo2)
|
||||
assert.NoError(t, err)
|
||||
|
||||
has, err = HasAccess(user2.ID, repo1)
|
||||
_, err = HasAccess(user2.ID, repo1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
has, err = HasAccess(user2.ID, repo2)
|
||||
_, err = HasAccess(user2.ID, repo2)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user