@@ -46,220 +46,6 @@ func TestAPISearchRepoNotLogin(t *testing.T) {
46
46
assert .Contains (t , repo .Name , keyword )
47
47
assert .False (t , repo .Private )
48
48
}
49
-
50
- // Should return all (max 50) public repositories
51
- req = NewRequest (t , "GET" , "/api/v1/repos/search?limit=50" )
52
- resp = MakeRequest (t , req , http .StatusOK )
53
-
54
- DecodeJSON (t , resp , & body )
55
- assert .Len (t , body .Data , 12 )
56
- for _ , repo := range body .Data {
57
- assert .NotEmpty (t , repo .Name )
58
- assert .False (t , repo .Private )
59
- }
60
-
61
- // Should return (max 10) public repositories
62
- req = NewRequest (t , "GET" , "/api/v1/repos/search?limit=10" )
63
- resp = MakeRequest (t , req , http .StatusOK )
64
-
65
- DecodeJSON (t , resp , & body )
66
- assert .Len (t , body .Data , 10 )
67
- for _ , repo := range body .Data {
68
- assert .NotEmpty (t , repo .Name )
69
- assert .False (t , repo .Private )
70
- }
71
-
72
- const keyword2 = "big_test_"
73
- // Should return all public repositories which (partial) match keyword
74
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?q=%s" , keyword2 )
75
- resp = MakeRequest (t , req , http .StatusOK )
76
-
77
- DecodeJSON (t , resp , & body )
78
- assert .Len (t , body .Data , 4 )
79
- for _ , repo := range body .Data {
80
- assert .Contains (t , repo .Name , keyword2 )
81
- assert .False (t , repo .Private )
82
- }
83
-
84
- // Should return all public repositories accessible and related to user
85
- const userID = int64 (15 )
86
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , userID )
87
- resp = MakeRequest (t , req , http .StatusOK )
88
-
89
- DecodeJSON (t , resp , & body )
90
- assert .Len (t , body .Data , 4 )
91
- for _ , repo := range body .Data {
92
- assert .NotEmpty (t , repo .Name )
93
- assert .False (t , repo .Private )
94
- }
95
-
96
- // Should return all public repositories accessible and related to user
97
- const user2ID = int64 (16 )
98
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , user2ID )
99
- resp = MakeRequest (t , req , http .StatusOK )
100
-
101
- DecodeJSON (t , resp , & body )
102
- assert .Len (t , body .Data , 1 )
103
- for _ , repo := range body .Data {
104
- assert .NotEmpty (t , repo .Name )
105
- assert .False (t , repo .Private )
106
- }
107
-
108
- // Should return all public repositories owned by organization
109
- const orgID = int64 (17 )
110
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , orgID )
111
- resp = MakeRequest (t , req , http .StatusOK )
112
-
113
- DecodeJSON (t , resp , & body )
114
- assert .Len (t , body .Data , 1 )
115
- for _ , repo := range body .Data {
116
- assert .NotEmpty (t , repo .Name )
117
- assert .Equal (t , repo .Owner .ID , orgID )
118
- assert .False (t , repo .Private )
119
- }
120
- }
121
-
122
- func TestAPISearchRepoLoggedUser (t * testing.T ) {
123
- prepareTestEnv (t )
124
-
125
- user := models .AssertExistsAndLoadBean (t , & models.User {ID : 15 }).(* models.User )
126
- user2 := models .AssertExistsAndLoadBean (t , & models.User {ID : 16 }).(* models.User )
127
- session := loginUser (t , user .Name )
128
- session2 := loginUser (t , user2 .Name )
129
-
130
- var body api.SearchResults
131
-
132
- // Get public repositories accessible and not related to logged in user that match the keyword
133
- // Should return all public repositories which (partial) match keyword
134
- const keyword = "big_test_"
135
- req := NewRequestf (t , "GET" , "/api/v1/repos/search?q=%s" , keyword )
136
- resp := session .MakeRequest (t , req , http .StatusOK )
137
-
138
- DecodeJSON (t , resp , & body )
139
- assert .Len (t , body .Data , 4 )
140
- for _ , repo := range body .Data {
141
- assert .Contains (t , repo .Name , keyword )
142
- assert .False (t , repo .Private )
143
- }
144
- // Test when user2 is logged in
145
- resp = session2 .MakeRequest (t , req , http .StatusOK )
146
-
147
- DecodeJSON (t , resp , & body )
148
- assert .Len (t , body .Data , 4 )
149
- for _ , repo := range body .Data {
150
- assert .Contains (t , repo .Name , keyword )
151
- assert .False (t , repo .Private )
152
- }
153
-
154
- // Get all public repositories accessible and not related to logged in user
155
- // Should return all (max 50) public repositories
156
- req = NewRequest (t , "GET" , "/api/v1/repos/search?limit=50" )
157
- resp = session .MakeRequest (t , req , http .StatusOK )
158
-
159
- DecodeJSON (t , resp , & body )
160
- assert .Len (t , body .Data , 12 )
161
- for _ , repo := range body .Data {
162
- assert .NotEmpty (t , repo .Name )
163
- assert .False (t , repo .Private )
164
- }
165
- // Test when user2 is logged in
166
- resp = session2 .MakeRequest (t , req , http .StatusOK )
167
-
168
- DecodeJSON (t , resp , & body )
169
- assert .Len (t , body .Data , 12 )
170
- for _ , repo := range body .Data {
171
- assert .NotEmpty (t , repo .Name )
172
- assert .False (t , repo .Private )
173
- }
174
-
175
- // Get all public repositories accessible and not related to logged in user
176
- // Should return all (max 10) public repositories
177
- req = NewRequest (t , "GET" , "/api/v1/repos/search?limit=10" )
178
- resp = session .MakeRequest (t , req , http .StatusOK )
179
-
180
- DecodeJSON (t , resp , & body )
181
- assert .Len (t , body .Data , 10 )
182
- for _ , repo := range body .Data {
183
- assert .NotEmpty (t , repo .Name )
184
- assert .False (t , repo .Private )
185
- }
186
- // Test when user2 is logged in
187
- resp = session2 .MakeRequest (t , req , http .StatusOK )
188
-
189
- DecodeJSON (t , resp , & body )
190
- assert .Len (t , body .Data , 10 )
191
- for _ , repo := range body .Data {
192
- assert .NotEmpty (t , repo .Name )
193
- assert .False (t , repo .Private )
194
- }
195
-
196
- // Get repositories of logged in user
197
- // Should return all public and private repositories accessible and related to user
198
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , user .ID )
199
- resp = session .MakeRequest (t , req , http .StatusOK )
200
-
201
- DecodeJSON (t , resp , & body )
202
- assert .Len (t , body .Data , 8 )
203
- for _ , repo := range body .Data {
204
- assert .NotEmpty (t , repo .Name )
205
- }
206
- // Test when user2 is logged in
207
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , user2 .ID )
208
- resp = session2 .MakeRequest (t , req , http .StatusOK )
209
-
210
- DecodeJSON (t , resp , & body )
211
- assert .Len (t , body .Data , 2 )
212
- for _ , repo := range body .Data {
213
- assert .NotEmpty (t , repo .Name )
214
- }
215
-
216
- // Get repositories of another user
217
- // Should return all public repositories accessible and related to user
218
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , user2 .ID )
219
- resp = session .MakeRequest (t , req , http .StatusOK )
220
-
221
- DecodeJSON (t , resp , & body )
222
- assert .Len (t , body .Data , 1 )
223
- for _ , repo := range body .Data {
224
- assert .NotEmpty (t , repo .Name )
225
- assert .False (t , repo .Private )
226
- }
227
- // Test when user2 is logged in
228
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , user .ID )
229
- resp = session2 .MakeRequest (t , req , http .StatusOK )
230
-
231
- DecodeJSON (t , resp , & body )
232
- assert .Len (t , body .Data , 4 )
233
- for _ , repo := range body .Data {
234
- assert .NotEmpty (t , repo .Name )
235
- assert .False (t , repo .Private )
236
- }
237
-
238
- // Get repositories of organization owned by logged in user
239
- // Should return all public and private repositories owned by organization
240
- const orgID = int64 (17 )
241
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , orgID )
242
- resp = session .MakeRequest (t , req , http .StatusOK )
243
-
244
- DecodeJSON (t , resp , & body )
245
- assert .Len (t , body .Data , 2 )
246
- for _ , repo := range body .Data {
247
- assert .NotEmpty (t , repo .Name )
248
- assert .Equal (t , repo .Owner .ID , orgID )
249
- }
250
-
251
- // Get repositories of organization owned by another user
252
- // Should return all public repositories owned by organization
253
- req = NewRequestf (t , "GET" , "/api/v1/repos/search?uid=%d" , orgID )
254
- resp = session2 .MakeRequest (t , req , http .StatusOK )
255
-
256
- DecodeJSON (t , resp , & body )
257
- assert .Len (t , body .Data , 1 )
258
- for _ , repo := range body .Data {
259
- assert .NotEmpty (t , repo .Name )
260
- assert .Equal (t , repo .Owner .ID , orgID )
261
- assert .False (t , repo .Private )
262
- }
263
49
}
264
50
265
51
func TestAPIViewRepo (t * testing.T ) {
0 commit comments