@@ -36,6 +36,7 @@ func TestAPI(t *testing.T) {
36
36
Request any
37
37
Response any
38
38
Status int
39
+ Method string
39
40
}{
40
41
{
41
42
Name : "Root" ,
@@ -216,6 +217,7 @@ func TestAPI(t *testing.T) {
216
217
Status : http .StatusMovedPermanently ,
217
218
Response : "/files/publisher/extension/version@darwin-x64/foo" ,
218
219
},
220
+ // Old vspackage path, for backwards compatibility.
219
221
{
220
222
Name : "DownloadNotExist" ,
221
223
Path : "/publishers/notexist/vsextensions/extension/version/vspackage" ,
@@ -231,6 +233,24 @@ func TestAPI(t *testing.T) {
231
233
Status : http .StatusMovedPermanently ,
232
234
Response : "/files/publisher/extension/version/extension.vsix" ,
233
235
},
236
+ // The vspackage path currently generated by VS Code.
237
+ {
238
+ Name : "APIDownloadNotExist" ,
239
+ Path : "/api/publishers/notexist/vsextensions/extension/version/vspackage" ,
240
+ Status : http .StatusNotFound ,
241
+ Response : & httpapi.ErrorResponse {
242
+ Message : "Extension asset does not exist" ,
243
+ Detail : "Please check the asset path" ,
244
+ },
245
+ Method : http .MethodGet ,
246
+ },
247
+ {
248
+ Name : "APIDownloadOK" ,
249
+ Path : "/api/publishers/publisher/vsextensions/extension/version/vspackage" ,
250
+ Status : http .StatusMovedPermanently ,
251
+ Response : "/files/publisher/extension/version/extension.vsix" ,
252
+ Method : http .MethodGet ,
253
+ },
234
254
{
235
255
Name : "Item" ,
236
256
Path : "/item" ,
@@ -273,9 +293,19 @@ func TestAPI(t *testing.T) {
273
293
},
274
294
}
275
295
296
+ // Most /api calls are POSTs, the rest are GETs.
297
+ var method = c .Method
298
+ if method == "" {
299
+ if strings .HasPrefix (c .Path , "/api" ) {
300
+ method = http .MethodPost
301
+ } else {
302
+ method = http .MethodGet
303
+ }
304
+ }
305
+
276
306
var resp * http.Response
277
307
var err error
278
- if strings . HasPrefix ( c . Path , "/api" ) {
308
+ if method == http . MethodPost {
279
309
var body []byte
280
310
if str , ok := c .Request .(string ); ok {
281
311
body = []byte (str )
@@ -284,8 +314,10 @@ func TestAPI(t *testing.T) {
284
314
require .NoError (t , err )
285
315
}
286
316
resp , err = client .Post (url , "application/json" , bytes .NewReader (body ))
287
- } else {
317
+ } else if method == http . MethodGet {
288
318
resp , err = client .Get (url )
319
+ } else {
320
+ t .Fatal (method + " is not handled in the test yet, please add it now" )
289
321
}
290
322
require .NoError (t , err )
291
323
require .Equal (t , c .Status , resp .StatusCode )
0 commit comments