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