@@ -36,6 +36,7 @@ func TestAPI(t *testing.T) {
3636 Request any
3737 Response any
3838 Status int
39+ Method string
3940 }{
4041 {
4142 Name : "Root" ,
@@ -216,6 +217,7 @@ func TestAPI(t *testing.T) {
216217 Status : http .StatusMovedPermanently ,
217218 Response : "/files/publisher/extension/version@darwin-x64/foo" ,
218219 },
220+ // Old vspackage path, for backwards compatibility.
219221 {
220222 Name : "DownloadNotExist" ,
221223 Path : "/publishers/notexist/vsextensions/extension/version/vspackage" ,
@@ -231,6 +233,24 @@ func TestAPI(t *testing.T) {
231233 Status : http .StatusMovedPermanently ,
232234 Response : "/files/publisher/extension/version/extension.vsix" ,
233235 },
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+ },
234254 {
235255 Name : "Item" ,
236256 Path : "/item" ,
@@ -273,9 +293,19 @@ func TestAPI(t *testing.T) {
273293 },
274294 }
275295
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+
276306 var resp * http.Response
277307 var err error
278- if strings . HasPrefix ( c . Path , "/api" ) {
308+ if method == http . MethodPost {
279309 var body []byte
280310 if str , ok := c .Request .(string ); ok {
281311 body = []byte (str )
@@ -284,8 +314,10 @@ func TestAPI(t *testing.T) {
284314 require .NoError (t , err )
285315 }
286316 resp , err = client .Post (url , "application/json" , bytes .NewReader (body ))
287- } else {
317+ } else if method == http . MethodGet {
288318 resp , err = client .Get (url )
319+ } else {
320+ t .Fatal (method + " is not handled in the test yet, please add it now" )
289321 }
290322 require .NoError (t , err )
291323 require .Equal (t , c .Status , resp .StatusCode )
0 commit comments