github.com/anchore/syft@v1.38.2/syft/source/directorysource/directory_source_win_test.go (about) 1 //go:build windows 2 3 // why the build tags? there is behavior from filepath.ToSlash() that must be tested, but can't be tested on non-windows 4 // since the stdlib keeps this functionality behind a build tag (specifically filepath.Separator): 5 // - https://github.com/golang/go/blob/3aea422e2cb8b1ec2e0c2774be97fe96c7299838/src/path/filepath/path.go#L224-L227 6 // - https://github.com/golang/go/blob/3aea422e2cb8b1ec2e0c2774be97fe96c7299838/src/path/filepath/path.go#L63 7 // - https://github.com/golang/go/blob/master/src/os/path_windows.go#L8 8 // 9 // It would be nice to extract this to simplify testing, however, we also need filepath.Abs(), which in windows 10 // requires a specific syscall: 11 // - https://github.com/golang/go/blob/3aea422e2cb8b1ec2e0c2774be97fe96c7299838/src/path/filepath/path_windows.go#L216 12 // ... which means we can't extract this functionality without build tags. 13 14 package directorysource 15 16 import ( 17 "testing" 18 19 "github.com/stretchr/testify/require" 20 ) 21 22 func Test_DirectorySource_crossPlatformExclusions(t *testing.T) { 23 testCases := []struct { 24 desc string 25 root string 26 path string 27 exclude string 28 match bool 29 }{ 30 { 31 desc: "windows doublestar", 32 root: "C:\\User\\stuff", 33 path: "C:\\User\\stuff\\thing.txt", 34 exclude: "**/*.txt", 35 match: true, 36 }, 37 { 38 desc: "windows relative", 39 root: "C:\\User\\stuff", 40 path: "C:\\User\\stuff\\thing.txt", 41 exclude: "./*.txt", 42 match: true, 43 }, 44 { 45 desc: "windows one level", 46 root: "C:\\User\\stuff", 47 path: "C:\\User\\stuff\\thing.txt", 48 exclude: "*/*.txt", 49 match: false, 50 }, 51 } 52 53 for _, test := range testCases { 54 t.Run(test.desc, func(t *testing.T) { 55 fns, err := GetDirectoryExclusionFunctions(test.root, []string{test.exclude}) 56 require.NoError(t, err) 57 58 for _, f := range fns { 59 result := f(test.path, nil, nil) 60 require.Equal(t, test.match, result) 61 } 62 }) 63 } 64 }