@@ -357,22 +357,22 @@ func TestReadVSIXManifest(t *testing.T) {
357357 {
358358 name : "MissingManifest" ,
359359 error : "not found" ,
360- vsix : testutil .CreateVSIX (t , nil ),
360+ vsix : testutil .CreateVSIX (t , nil , nil ),
361361 },
362362 {
363363 name : "EmptyManifest" ,
364364 error : "EOF" ,
365- vsix : testutil .CreateVSIX (t , []byte ("" )),
365+ vsix : testutil .CreateVSIX (t , []byte ("" ), nil ),
366366 },
367367 {
368368 name : "TextFileManifest" ,
369369 error : "EOF" ,
370- vsix : testutil .CreateVSIX (t , []byte ("just some random text" )),
370+ vsix : testutil .CreateVSIX (t , []byte ("just some random text" ), nil ),
371371 },
372372 {
373373 name : "ManifestSyntaxError" ,
374374 error : "XML syntax error" ,
375- vsix : testutil .CreateVSIX (t , []byte ("<PackageManifest/PackageManifest>" )),
375+ vsix : testutil .CreateVSIX (t , []byte ("<PackageManifest/PackageManifest>" ), nil ),
376376 },
377377 {
378378 name : "ManifestMissingPublisher" ,
@@ -424,6 +424,74 @@ func TestReadVSIXManifest(t *testing.T) {
424424 }
425425}
426426
427+ func TestReadVSIXPackageJson (t * testing.T ) {
428+ t .Parallel ()
429+
430+ tests := []struct {
431+ // error is the expected error, if any.
432+ error string
433+ // json is the package.json from which to create the VSIX. Use `vsix` to
434+ // specify raw bytes instead.
435+ json * storage.VSIXPackageJSON
436+ // name is the name of the test.
437+ name string
438+ // vsix contains the raw bytes for the VSIX from which to read the manifest.
439+ // If omitted it will be created from `manifest`. For non-error cases
440+ // always use `manifest` instead so the result can be checked.
441+ vsix []byte
442+ }{
443+ {
444+ name : "OK" ,
445+ json : & storage.VSIXPackageJSON {},
446+ },
447+ {
448+ name : "WithBrowser" ,
449+ json : & storage.VSIXPackageJSON {
450+ Browser : "foo" ,
451+ },
452+ },
453+ {
454+ name : "MissingPackageJson" ,
455+ error : "not found" ,
456+ vsix : testutil .CreateVSIX (t , nil , nil ),
457+ },
458+ {
459+ name : "EmptyPackageJson" ,
460+ error : "EOF" ,
461+ vsix : testutil .CreateVSIX (t , nil , []byte ("" )),
462+ },
463+ {
464+ name : "TextFilePackageJson" ,
465+ error : "invalid character" ,
466+ vsix : testutil .CreateVSIX (t , nil , []byte ("just some random text" )),
467+ },
468+ {
469+ name : "PackageJsonSyntaxError" ,
470+ error : "invalid character" ,
471+ vsix : testutil .CreateVSIX (t , nil , []byte ("{\" foo\" : bar}" )),
472+ },
473+ }
474+
475+ for _ , test := range tests {
476+ test := test
477+ t .Run (test .name , func (t * testing.T ) {
478+ t .Parallel ()
479+ vsix := test .vsix
480+ if vsix == nil {
481+ vsix = testutil .CreateVSIXFromPackageJSON (t , test .json )
482+ }
483+ json , err := storage .ReadVSIXPackageJSON (vsix , "extension/package.json" )
484+ if test .error != "" {
485+ require .Error (t , err )
486+ require .Regexp (t , test .error , err .Error ())
487+ } else {
488+ require .NoError (t , err )
489+ require .Equal (t , test .json , json )
490+ }
491+ })
492+ }
493+ }
494+
427495func TestAddExtension (t * testing.T ) {
428496 t .Parallel ()
429497
0 commit comments