@@ -65,8 +65,8 @@ func testEditorCreateFile(t *testing.T) {
6565 testEditorActionPostRequestError (t , session , "/user2/repo1/_new/master/" , map [string ]string {
6666 "tree_path" : "test.txt" ,
6767 "commit_choice" : "commit-to-new-branch" ,
68- "new_branch_name" : "branch2 " ,
69- }, `Branch "branch2 " already exists in this repository.` )
68+ "new_branch_name" : "master " ,
69+ }, `Branch "master " already exists in this repository.` )
7070}
7171
7272func testCreateFile (t * testing.T , session * TestSession , user , repo , branch , filePath , content string ) {
@@ -153,24 +153,27 @@ func testEditorDiffPreview(t *testing.T) {
153153
154154func testEditorPatchFile (t * testing.T ) {
155155 session := loginUser (t , "user2" )
156- pathContent := `diff --git a/patch-file-1.txt b/patch-file-1.txt
156+ pathContentCommon := `diff --git a/patch-file-1.txt b/patch-file-1.txt
157157new file mode 100644
158158index 0000000000..aaaaaaaaaa
159159--- /dev/null
160160+++ b/patch-file-1.txt
161161@@ -0,0 +1 @@
162- +patched content
163- `
164- patchForm := map [string ]string {
165- "content" : pathContent ,
162+ +`
163+ testEditorActionPostRequest (t , session , "/user2/repo1/_diffpatch/master/" , map [string ]string {
164+ "content" : pathContentCommon + "patched content\n " ,
166165 "commit_choice" : "commit-to-new-branch" ,
167166 "new_branch_name" : "patched-branch" ,
168- }
169- testEditorActionPostRequest (t , session , "/user2/repo1/_diffpatch/master/" , patchForm )
167+ })
170168 resp := MakeRequest (t , NewRequest (t , "GET" , "/user2/repo1/raw/branch/patched-branch/patch-file-1.txt" ), http .StatusOK )
171169 assert .Equal (t , "patched content\n " , resp .Body .String ())
172170
173- resp = testEditorActionPostRequest (t , session , "/user2/repo1/_diffpatch/master/" , patchForm )
171+ // patch again, it should fail
172+ resp = testEditorActionPostRequest (t , session , "/user2/repo1/_diffpatch/patched-branch/" , map [string ]string {
173+ "content" : pathContentCommon + "another patched content\n " ,
174+ "commit_choice" : "commit-to-new-branch" ,
175+ "new_branch_name" : "patched-branch-1" ,
176+ })
174177 assert .Equal (t , "Unable to apply patch" , test .ParseJSONError (resp .Body .Bytes ()).ErrorMessage )
175178}
176179
0 commit comments