Skip to content

Commit 164c18f

Browse files
committed
fix tests
1 parent c5a7beb commit 164c18f

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

routers/api/v1/repo/file.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,13 @@ func changeFilesCommitMessage(ctx *context.APIContext, files []*files_service.Ch
737737
}
738738
message := ""
739739
if len(createFiles) != 0 {
740-
message += ctx.Tr("repo.editor.add") + strings.Join(createFiles, ", ") + "\n"
740+
message += ctx.Tr("repo.editor.add", strings.Join(createFiles, ", ")+"\n")
741741
}
742742
if len(updateFiles) != 0 {
743-
message += ctx.Tr("repo.editor.update") + strings.Join(updateFiles, ", ") + "\n"
743+
message += ctx.Tr("repo.editor.update", strings.Join(updateFiles, ", ")+"\n")
744744
}
745745
if len(deleteFiles) != 0 {
746-
message += ctx.Tr("repo.editor.delete") + strings.Join(deleteFiles, ", ") + "\n"
746+
message += ctx.Tr("repo.editor.delete", strings.Join(deleteFiles, ", ")+"\n")
747747
}
748748
return message
749749
}

tests/integration/api_repo_files_change_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ func getChangeFilesOptions() *api.ChangeFilesOptions {
3434
NewBranchName: "master",
3535
Message: "My update of new/file.txt",
3636
Author: api.Identity{
37-
Name: "John Doe",
38-
39-
},
40-
Committer: api.Identity{
4137
Name: "Anne Doe",
4238
4339
},
40+
Committer: api.Identity{
41+
Name: "John Doe",
42+
43+
},
4444
},
4545
Files: []*api.ChangeFileOperation{
4646
{
@@ -60,7 +60,7 @@ func getChangeFilesOptions() *api.ChangeFilesOptions {
6060
}
6161
}
6262

63-
func TestAPIUChangeFiles(t *testing.T) {
63+
func TestAPIChangeFiles(t *testing.T) {
6464
onGiteaRun(t, func(t *testing.T, u *url.URL) {
6565
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) // owner of the repo1 & repo16
6666
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}) // owner of the repo3, is an org
@@ -95,7 +95,7 @@ func TestAPIUChangeFiles(t *testing.T) {
9595
changeFilesOptions.Files[2].Path = deleteTreePath
9696
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents?token=%s", user2.Name, repo1.Name, token2)
9797
req := NewRequestWithJSON(t, "POST", url, &changeFilesOptions)
98-
resp := MakeRequest(t, req, http.StatusOK)
98+
resp := MakeRequest(t, req, http.StatusCreated)
9999
gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
100100
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
101101
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
@@ -111,17 +111,14 @@ func TestAPIUChangeFiles(t *testing.T) {
111111
assert.EqualValues(t, expectedCreateFileResponse.Commit.HTMLURL, fileResponse[0].Commit.HTMLURL)
112112
assert.EqualValues(t, expectedCreateFileResponse.Commit.Author.Email, fileResponse[0].Commit.Author.Email)
113113
assert.EqualValues(t, expectedCreateFileResponse.Commit.Author.Name, fileResponse[0].Commit.Author.Name)
114-
assert.EqualValues(t, expectedCreateFileResponse.Commit.Author.Date, fileResponse[0].Commit.Author.Date)
115114
assert.EqualValues(t, expectedCreateFileResponse.Commit.Committer.Email, fileResponse[0].Commit.Committer.Email)
116115
assert.EqualValues(t, expectedCreateFileResponse.Commit.Committer.Name, fileResponse[0].Commit.Committer.Name)
117-
assert.EqualValues(t, expectedCreateFileResponse.Commit.Committer.Date, fileResponse[0].Commit.Committer.Date)
118-
119116
// test update file
120117
assert.EqualValues(t, expectedUpdateFileResponse.Content, fileResponse[1].Content)
121118
assert.EqualValues(t, expectedUpdateFileResponse.Commit.SHA, fileResponse[1].Commit.SHA)
122119
assert.EqualValues(t, expectedUpdateFileResponse.Commit.HTMLURL, fileResponse[1].Commit.HTMLURL)
123-
assert.EqualValues(t, expectedUpdateFileResponse.Commit.Author.Email, fileResponse[1].Commit.Author.Email)
124-
assert.EqualValues(t, expectedUpdateFileResponse.Commit.Author.Name, fileResponse[1].Commit.Author.Name)
120+
assert.EqualValues(t, expectedUpdateFileResponse.Commit.Committer.Email, fileResponse[1].Commit.Author.Email)
121+
assert.EqualValues(t, expectedUpdateFileResponse.Commit.Committer.Name, fileResponse[1].Commit.Author.Name)
125122

126123
// test delete file
127124
assert.NotNil(t, fileResponse[2])
@@ -145,7 +142,7 @@ func TestAPIUChangeFiles(t *testing.T) {
145142
createFile(user2, repo1, deleteTreePath)
146143
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents?token=%s", user2.Name, repo1.Name, token2)
147144
req := NewRequestWithJSON(t, "POST", url, &changeFilesOptions)
148-
resp := MakeRequest(t, req, http.StatusOK)
145+
resp := MakeRequest(t, req, http.StatusCreated)
149146
var fileResponse []api.FileResponse
150147
DecodeJSON(t, resp, &fileResponse)
151148
expectedCreateSHA := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
@@ -176,7 +173,7 @@ func TestAPIUChangeFiles(t *testing.T) {
176173
changeFilesOptions.Files[0].FromPath = updateTreePath
177174
changeFilesOptions.Files[0].Path = "rename/" + updateTreePath
178175
req = NewRequestWithJSON(t, "POST", url, &changeFilesOptions)
179-
resp = MakeRequest(t, req, http.StatusOK)
176+
resp = MakeRequest(t, req, http.StatusCreated)
180177
DecodeJSON(t, resp, &fileResponse)
181178
expectedUpdateSHA = "08bd14b2e2852529157324de9c226b3364e76136"
182179
expectedUpdateHTMLURL = fmt.Sprintf(setting.AppURL+"user2/repo1/src/branch/master/rename/update/file%d.txt", fileID)
@@ -193,12 +190,15 @@ func TestAPIUChangeFiles(t *testing.T) {
193190
createTreePath = fmt.Sprintf("new/file%d.txt", fileID)
194191
updateTreePath = fmt.Sprintf("update/file%d.txt", fileID)
195192
deleteTreePath = fmt.Sprintf("delete/file%d.txt", fileID)
193+
changeFilesOptions.Files[0].Path = createTreePath
194+
changeFilesOptions.Files[1].Path = updateTreePath
195+
changeFilesOptions.Files[2].Path = deleteTreePath
196196
createFile(user2, repo1, updateTreePath)
197197
createFile(user2, repo1, deleteTreePath)
198198
req = NewRequestWithJSON(t, "POST", url, &changeFilesOptions)
199-
resp = MakeRequest(t, req, http.StatusOK)
199+
resp = MakeRequest(t, req, http.StatusCreated)
200200
DecodeJSON(t, resp, &fileResponse)
201-
expectedMessage := fmt.Sprintf("Create: %v\nUpdate: %v\nDelete: %v\n", createTreePath, updateTreePath, deleteTreePath)
201+
expectedMessage := fmt.Sprintf("Add %v\nUpdate %v\nDelete %v\n", createTreePath, updateTreePath, deleteTreePath)
202202
for _, response := range fileResponse {
203203
assert.EqualValues(t, expectedMessage, response.Commit.Message)
204204
}
@@ -209,6 +209,7 @@ func TestAPIUChangeFiles(t *testing.T) {
209209
createFile(user2, repo1, updateTreePath)
210210
changeFilesOptions = getChangeFilesOptions()
211211
changeFilesOptions.Files = []*api.ChangeFileOperation{changeFilesOptions.Files[1]}
212+
changeFilesOptions.Files[0].Path = updateTreePath
212213
correctSHA := changeFilesOptions.Files[0].SHA
213214
changeFilesOptions.Files[0].SHA = "badsha"
214215
req = NewRequestWithJSON(t, "POST", url, &changeFilesOptions)
@@ -264,7 +265,7 @@ func TestAPIUChangeFiles(t *testing.T) {
264265
changeFilesOptions.Files[2].Path = deleteTreePath
265266
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents?token=%s", user2.Name, repo16.Name, token2)
266267
req = NewRequestWithJSON(t, "POST", url, &changeFilesOptions)
267-
MakeRequest(t, req, http.StatusOK)
268+
MakeRequest(t, req, http.StatusCreated)
268269

269270
// Test using org repo "user3/repo3" where user2 is a collaborator
270271
fileID++
@@ -279,7 +280,7 @@ func TestAPIUChangeFiles(t *testing.T) {
279280
changeFilesOptions.Files[2].Path = deleteTreePath
280281
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents?token=%s", user3.Name, repo3.Name, token2)
281282
req = NewRequestWithJSON(t, "POST", url, &changeFilesOptions)
282-
MakeRequest(t, req, http.StatusOK)
283+
MakeRequest(t, req, http.StatusCreated)
283284

284285
// Test using org repo "user3/repo3" with no user token
285286
fileID++

0 commit comments

Comments
 (0)