@@ -3,6 +3,8 @@ package cli_test
33import (
44 "bytes"
55 "fmt"
6+ "net/http"
7+ "net/http/httptest"
68 "os"
79 "path/filepath"
810 "testing"
@@ -97,42 +99,60 @@ func TestAdd(t *testing.T) {
9799 }
98100
99101 // With multiple extensions use bulk add by pointing to the directory
100- // otherwise point to the vsix file.
101- source := extdir
102+ // otherwise point to the vsix file. When not using bulk add also test
103+ // from HTTP.
104+ sources := []string {extdir }
102105 if count == 1 {
103- source = filepath .Join (extdir , "0.vsix" )
106+ sources = []string {filepath .Join (extdir , "0.vsix" )}
107+
108+ handler := func (rw http.ResponseWriter , r * http.Request ) {
109+ var vsix []byte
110+ if test .vsixes == nil {
111+ vsix = testutil .CreateVSIXFromExtension (t , test .extensions [0 ])
112+ } else {
113+ vsix = test .vsixes [0 ]
114+ }
115+ _ , err := rw .Write (vsix )
116+ require .NoError (t , err )
117+ }
118+ server := httptest .NewServer (http .HandlerFunc (handler ))
119+ defer server .Close ()
120+
121+ sources = append (sources , server .URL )
104122 }
105123
106- cmd := cli .Root ()
107- args := []string {"add" , source , "--extensions-dir" , extdir }
108- cmd .SetArgs (args )
109- buf := new (bytes.Buffer )
110- cmd .SetOutput (buf )
124+ for _ , source := range sources {
125+ cmd := cli .Root ()
126+ args := []string {"add" , source , "--extensions-dir" , extdir }
127+ cmd .SetArgs (args )
128+ buf := new (bytes.Buffer )
129+ cmd .SetOutput (buf )
111130
112- err := cmd .Execute ()
113- output := buf .String ()
131+ err := cmd .Execute ()
132+ output := buf .String ()
114133
115- if test .error != "" {
116- require .Error (t , err )
117- require .Regexp (t , test .error , err .Error ())
118- } else {
119- require .NoError (t , err )
120- }
121- // Should list all the extensions that worked.
122- for _ , ext := range test .extensions {
123- // Should exist on disk.
124- dest := filepath .Join (extdir , ext .Publisher , ext .Name , ext .LatestVersion )
125- _ , err := os .Stat (dest )
126- require .NoError (t , err )
127- // Should tell you where it went.
128- id := storage .ExtensionID (ext .Publisher , ext .Name , ext .LatestVersion )
129- require .Contains (t , output , fmt .Sprintf ("Unpacked %s to %s" , id , dest ))
130- // Should mention the dependencies and pack.
131- require .Contains (t , output , fmt .Sprintf ("%s has %d dep" , id , len (ext .Dependencies )))
132- if len (ext .Pack ) > 0 {
133- require .Contains (t , output , fmt .Sprintf ("%s is in a pack with %d other" , id , len (ext .Pack )))
134+ if test .error != "" {
135+ require .Error (t , err )
136+ require .Regexp (t , test .error , err .Error ())
134137 } else {
135- require .Contains (t , output , fmt .Sprintf ("%s is not in a pack" , id ))
138+ require .NoError (t , err )
139+ }
140+ // Should list all the extensions that worked.
141+ for _ , ext := range test .extensions {
142+ // Should exist on disk.
143+ dest := filepath .Join (extdir , ext .Publisher , ext .Name , ext .LatestVersion )
144+ _ , err := os .Stat (dest )
145+ require .NoError (t , err )
146+ // Should tell you where it went.
147+ id := storage .ExtensionID (ext .Publisher , ext .Name , ext .LatestVersion )
148+ require .Contains (t , output , fmt .Sprintf ("Unpacked %s to %s" , id , dest ))
149+ // Should mention the dependencies and pack.
150+ require .Contains (t , output , fmt .Sprintf ("%s has %d dep" , id , len (ext .Dependencies )))
151+ if len (ext .Pack ) > 0 {
152+ require .Contains (t , output , fmt .Sprintf ("%s is in a pack with %d other" , id , len (ext .Pack )))
153+ } else {
154+ require .Contains (t , output , fmt .Sprintf ("%s is not in a pack" , id ))
155+ }
136156 }
137157 }
138158 })
0 commit comments