@@ -9,12 +9,10 @@ import (
9
9
"fmt"
10
10
"io/ioutil"
11
11
"net/http"
12
- "net/url"
13
12
"testing"
14
13
"time"
15
14
16
15
"code.gitea.io/gitea/models"
17
- "code.gitea.io/gitea/modules/json"
18
16
"code.gitea.io/gitea/modules/queue"
19
17
api "code.gitea.io/gitea/modules/structs"
20
18
"code.gitea.io/gitea/services/forms"
@@ -44,34 +42,6 @@ func (ctx TestContext) CreateAPITestContext(t *testing.T) APITestContext {
44
42
return NewAPITestContext (t , ctx .Username , ctx .Reponame )
45
43
}
46
44
47
- func doCreateRepository (ctx TestContext , empty bool , callback ... func (* testing.T , api.Repository )) func (* testing.T ) {
48
- return func (t * testing.T ) {
49
- createRepoOption := & api.CreateRepoOption {
50
- AutoInit : ! empty ,
51
- Description : "Temporary repo" ,
52
- Name : ctx .Reponame ,
53
- Private : true ,
54
- Template : true ,
55
- Gitignores : "" ,
56
- License : "WTFPL" ,
57
- Readme : "Default" ,
58
- }
59
- req := NewRequestWithJSON (t , "POST" , "/api/v1/user/repos" , createRepoOption )
60
- apiCtx := ctx .CreateAPITestContext (t )
61
- if ctx .ExpectedCode != 0 {
62
- apiCtx .MakeRequest (t , req , ctx .ExpectedCode )
63
- return
64
- }
65
- resp := apiCtx .MakeRequest (t , req , http .StatusCreated )
66
-
67
- var repository api.Repository
68
- DecodeJSON (t , resp , & repository )
69
- if len (callback ) > 0 {
70
- callback [0 ](t , repository )
71
- }
72
- }
73
- }
74
-
75
45
func doDeleteRepository (ctx TestContext ) func (* testing.T ) {
76
46
return func (t * testing.T ) {
77
47
urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s" , ctx .Username , ctx .Reponame )
@@ -85,86 +55,6 @@ func doDeleteRepository(ctx TestContext) func(*testing.T) {
85
55
}
86
56
}
87
57
88
- func doAddCollaborator (ctx TestContext , username string , mode models.AccessMode ) func (* testing.T ) {
89
- return func (t * testing.T ) {
90
- permission := "read"
91
-
92
- if mode == models .AccessModeAdmin {
93
- permission = "admin"
94
- } else if mode > models .AccessModeRead {
95
- permission = "write"
96
- }
97
- addCollaboratorOption := & api.AddCollaboratorOption {
98
- Permission : & permission ,
99
- }
100
- apiCtx := ctx .CreateAPITestContext (t )
101
- req := NewRequestWithJSON (t , "PUT" , fmt .Sprintf ("/api/v1/repos/%s/%s/collaborators/%s" , ctx .Username , ctx .Reponame , username ), addCollaboratorOption )
102
- if ctx .ExpectedCode != 0 {
103
- apiCtx .MakeRequest (t , req , ctx .ExpectedCode )
104
- return
105
- }
106
- apiCtx .MakeRequest (t , req , http .StatusNoContent )
107
- }
108
- }
109
-
110
- func doForkRepository (ctx TestContext , username string , callback ... func (* testing.T , api.Repository )) func (* testing.T ) {
111
- return func (t * testing.T ) {
112
- createForkOption := & api.CreateForkOption {}
113
- apiCtx := ctx .CreateAPITestContext (t )
114
- req := NewRequestWithJSON (t , "POST" , fmt .Sprintf ("/api/v1/repos/%s/%s/forks" , username , ctx .Reponame ), createForkOption )
115
- if ctx .ExpectedCode != 0 {
116
- apiCtx .MakeRequest (t , req , ctx .ExpectedCode )
117
- return
118
- }
119
- resp := apiCtx .MakeRequest (t , req , http .StatusAccepted )
120
- var repository api.Repository
121
- DecodeJSON (t , resp , & repository )
122
- if len (callback ) > 0 {
123
- callback [0 ](t , repository )
124
- }
125
- }
126
- }
127
-
128
- func doEditRepository (ctx TestContext , editRepoOption * api.EditRepoOption , callback ... func (* testing.T , api.Repository )) func (* testing.T ) {
129
- return func (t * testing.T ) {
130
- apiCtx := ctx .CreateAPITestContext (t )
131
- req := NewRequestWithJSON (t , "PATCH" , fmt .Sprintf ("/api/v1/repos/%s/%s" , url .PathEscape (ctx .Username ), url .PathEscape (ctx .Reponame )), editRepoOption )
132
- if ctx .ExpectedCode != 0 {
133
- apiCtx .MakeRequest (t , req , ctx .ExpectedCode )
134
- return
135
- }
136
- resp := apiCtx .MakeRequest (t , req , http .StatusOK )
137
-
138
- var repository api.Repository
139
- DecodeJSON (t , resp , & repository )
140
- if len (callback ) > 0 {
141
- callback [0 ](t , repository )
142
- }
143
- }
144
- }
145
-
146
- func doCreatePullRequest (ctx APITestContext , owner , repo , baseBranch , headBranch string ) func (* testing.T ) (api.PullRequest , error ) {
147
- return func (t * testing.T ) (api.PullRequest , error ) {
148
- urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/pulls" , owner , repo )
149
- req := NewRequestWithJSON (t , http .MethodPost , urlStr , & api.CreatePullRequestOption {
150
- Head : headBranch ,
151
- Base : baseBranch ,
152
- Title : fmt .Sprintf ("create a pr from %s to %s" , headBranch , baseBranch ),
153
- })
154
-
155
- expected := 201
156
- if ctx .ExpectedCode != 0 {
157
- expected = ctx .ExpectedCode
158
- }
159
-
160
- resp := ctx .MakeRequest (t , req , expected )
161
- decoder := json .NewDecoder (resp .Body )
162
- pr := api.PullRequest {}
163
- err := decoder .Decode (& pr )
164
- return pr , err
165
- }
166
- }
167
-
168
58
func doCreateUserKey (ctx TestContext , keyname , keyFile string , callback ... func (* testing.T , api.PublicKey )) func (* testing.T ) {
169
59
return func (t * testing.T ) {
170
60
urlStr := "/api/v1/user/keys"
@@ -189,25 +79,6 @@ func doCreateUserKey(ctx TestContext, keyname, keyFile string, callback ...func(
189
79
}
190
80
}
191
81
192
- func doGetPullRequest (ctx TestContext , owner , repo string , index int64 ) func (* testing.T ) (api.PullRequest , error ) {
193
- return func (t * testing.T ) (api.PullRequest , error ) {
194
- urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/pulls/%d" , owner , repo , index )
195
- req := NewRequest (t , http .MethodGet , urlStr )
196
-
197
- expected := 200
198
- if ctx .ExpectedCode != 0 {
199
- expected = ctx .ExpectedCode
200
- }
201
- apiCtx := ctx .CreateAPITestContext (t )
202
- resp := apiCtx .MakeRequest (t , req , expected )
203
-
204
- decoder := json .NewDecoder (resp .Body )
205
- pr := api.PullRequest {}
206
- err := decoder .Decode (& pr )
207
- return pr , err
208
- }
209
- }
210
-
211
82
func doMergePullRequest (ctx TestContext , owner , repo string , index int64 ) func (* testing.T ) {
212
83
return func (t * testing.T ) {
213
84
urlStr := fmt .Sprintf ("/api/ui/repos/%s/%s/pulls/%d/merge" ,
@@ -217,7 +88,7 @@ func doMergePullRequest(ctx TestContext, owner, repo string, index int64) func(*
217
88
Do : string (models .MergeStyleMerge ),
218
89
})
219
90
220
- resp := MakeRequest (t , req , NoExpectedStatus )
91
+ resp := ctx . Session . MakeRequest (t , req , NoExpectedStatus )
221
92
222
93
if resp .Code == http .StatusMethodNotAllowed {
223
94
err := api.APIError {}
@@ -228,7 +99,7 @@ func doMergePullRequest(ctx TestContext, owner, repo string, index int64) func(*
228
99
MergeMessageField : "doMergePullRequest Merge" ,
229
100
Do : string (models .MergeStyleMerge ),
230
101
})
231
- resp = MakeRequest (t , req , NoExpectedStatus )
102
+ resp = ctx . Session . MakeRequest (t , req , NoExpectedStatus )
232
103
}
233
104
234
105
expected := ctx .ExpectedCode
@@ -242,22 +113,3 @@ func doMergePullRequest(ctx TestContext, owner, repo string, index int64) func(*
242
113
}
243
114
}
244
115
}
245
-
246
- func doManuallyMergePullRequest (ctx TestContext , owner , repo , commitID string , index int64 ) func (* testing.T ) {
247
- return func (t * testing.T ) {
248
- urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/pulls/%d/merge" ,
249
- owner , repo , index )
250
- req := NewRequestWithJSON (t , http .MethodPost , urlStr , & forms.MergePullRequestForm {
251
- Do : string (models .MergeStyleManuallyMerged ),
252
- MergeCommitID : commitID ,
253
- })
254
-
255
- apiCtx := ctx .CreateAPITestContext (t )
256
-
257
- if ctx .ExpectedCode != 0 {
258
- apiCtx .MakeRequest (t , req , ctx .ExpectedCode )
259
- return
260
- }
261
- apiCtx .MakeRequest (t , req , 200 )
262
- }
263
- }
0 commit comments