@@ -12,6 +12,7 @@ import (
1212 "net/http/httptest"
1313 "os"
1414 "path/filepath"
15+ "runtime"
1516 "sort"
1617 "strconv"
1718 "testing"
@@ -261,6 +262,7 @@ func TestAddExtension(t *testing.T) {
261262 handler http.HandlerFunc
262263 name string
263264 setup func (extdir string ) (string , error )
265+ skip bool
264266 }{
265267 {
266268 name : "OK" ,
@@ -297,8 +299,11 @@ func TestAddExtension(t *testing.T) {
297299 },
298300 },
299301 {
300- name : "ExtensionDirPerms" ,
301- error : "permission denied" ,
302+ name : "ExtensionDirPerms" ,
303+ error : "permission denied" ,
304+ // It does not appear possible to create a directory that is not
305+ // writable on Windows?
306+ skip : runtime .GOOS == "windows" ,
302307 expected : testutil .Extensions [0 ],
303308 setup : func (extdir string ) (string , error ) {
304309 // Disallow writing to the extension directory.
@@ -324,6 +329,9 @@ func TestAddExtension(t *testing.T) {
324329 test := test
325330 t .Run (test .name , func (t * testing.T ) {
326331 t .Parallel ()
332+ if test .skip {
333+ t .Skip ()
334+ }
327335
328336 handler := test .handler
329337 if handler == nil {
@@ -362,10 +370,12 @@ func TestAddExtension(t *testing.T) {
362370 t .Parallel ()
363371
364372 tests := []struct {
365- error string
366- expected testutil.Extension
367- name string
368- source func (extdir string ) (string , error )
373+ error string
374+ errorType error
375+ expected testutil.Extension
376+ name string
377+ skip bool
378+ source func (extdir string ) (string , error )
369379 }{
370380 {
371381 name : "OK" ,
@@ -379,8 +389,8 @@ func TestAddExtension(t *testing.T) {
379389 },
380390 },
381391 {
382- name : "NotFound" ,
383- error : "foo \\ .vsix.+no such file" ,
392+ name : "NotFound" ,
393+ errorType : os . ErrNotExist ,
384394 source : func (extdir string ) (string , error ) {
385395 return filepath .Join (extdir , "foo.vsix" ), nil
386396 },
@@ -396,6 +406,9 @@ func TestAddExtension(t *testing.T) {
396406 {
397407 name : "Unreadable" ,
398408 error : "permission denied" ,
409+ // It does not appear possible to create a file that is not readable on
410+ // Windows?
411+ skip : runtime .GOOS == "windows" ,
399412 source : func (extdir string ) (string , error ) {
400413 vsixPath := filepath .Join (extdir , "extension.vsix" )
401414 return vsixPath , os .WriteFile (vsixPath , []byte {}, 0o222 )
@@ -407,6 +420,9 @@ func TestAddExtension(t *testing.T) {
407420 test := test
408421 t .Run (test .name , func (t * testing.T ) {
409422 t .Parallel ()
423+ if test .skip {
424+ t .Skip ()
425+ }
410426
411427 extdir := t .TempDir ()
412428 s := & storage.Local {ExtDir : extdir }
@@ -415,7 +431,10 @@ func TestAddExtension(t *testing.T) {
415431 require .NoError (t , err )
416432
417433 got , err := s .AddExtension (context .Background (), source )
418- if test .error != "" {
434+ if test .errorType != nil {
435+ require .Error (t , err )
436+ require .True (t , errors .Is (err , test .errorType ))
437+ } else if test .error != "" {
419438 require .Error (t , err )
420439 require .Regexp (t , test .error , err .Error ())
421440 } else {
0 commit comments