aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/api_repo_file_create_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-12-02 11:39:42 +0800
committerGitHub <noreply@github.com>2022-12-01 22:39:42 -0500
commitdf676a47d05b20f7bfe4fdae350f50af15b52905 (patch)
treedc747e21fd2a533aeacb1686f747bba0a8f60736 /tests/integration/api_repo_file_create_test.go
parent665d02efaf6ebaadf3ffb5b412ea77c4502f0baf (diff)
downloadgitea-df676a47d05b20f7bfe4fdae350f50af15b52905.tar.gz
gitea-df676a47d05b20f7bfe4fdae350f50af15b52905.zip
Remove session in api tests (#21984)
It's no meaning to request an API route with session.
Diffstat (limited to 'tests/integration/api_repo_file_create_test.go')
-rw-r--r--tests/integration/api_repo_file_create_test.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/tests/integration/api_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go
index 17e26d966b..476441dbb1 100644
--- a/tests/integration/api_repo_file_create_test.go
+++ b/tests/integration/api_repo_file_create_test.go
@@ -154,7 +154,6 @@ func TestAPICreateFile(t *testing.T) {
// Get user4's token
session = loginUser(t, user4.Name)
token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
// Test creating a file in repo1 which user2 owns, try both with branch and empty branch
for _, branch := range [...]string{
@@ -167,7 +166,7 @@ func TestAPICreateFile(t *testing.T) {
treePath := fmt.Sprintf("new/file%d.txt", fileID)
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
@@ -194,7 +193,7 @@ func TestAPICreateFile(t *testing.T) {
treePath := fmt.Sprintf("new/file%d.txt", fileID)
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req := NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var fileResponse api.FileResponse
DecodeJSON(t, resp, &fileResponse)
expectedSHA := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
@@ -212,7 +211,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, &fileResponse)
expectedMessage := "Add '" + treePath + "'\n"
assert.EqualValues(t, expectedMessage, fileResponse.Commit.Message)
@@ -222,7 +221,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = "README.md"
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
expectedAPIError := context.APIError{
Message: "repository file already exists [path: " + treePath + "]",
URL: setting.API.SwaggerURL,
@@ -237,7 +236,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Tests a repo with no token given so will fail
createFileOptions = getCreateFileOptions()
@@ -245,7 +244,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns
createFileOptions = getCreateFileOptions()
@@ -253,7 +252,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
// Test using org repo "user3/repo3" where user2 is a collaborator
createFileOptions = getCreateFileOptions()
@@ -261,7 +260,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusCreated)
+ MakeRequest(t, req, http.StatusCreated)
// Test using org repo "user3/repo3" with no user token
createFileOptions = getCreateFileOptions()
@@ -269,7 +268,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user3.Name, repo3.Name, treePath)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator
createFileOptions = getCreateFileOptions()
@@ -277,7 +276,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token4)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
// Test creating a file in an empty repository
doAPICreateRepository(NewAPITestContext(t, "user2", "empty-repo"), true)(t)
@@ -286,7 +285,7 @@ func TestAPICreateFile(t *testing.T) {
treePath = fmt.Sprintf("new/file%d.txt", fileID)
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, "empty-repo", treePath, token2)
req = NewRequestWithJSON(t, "POST", url, &createFileOptions)
- resp = session.MakeRequest(t, req, http.StatusCreated)
+ resp = MakeRequest(t, req, http.StatusCreated)
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo
gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath())
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)