github.com/anchore/syft@v1.38.2/syft/internal/fileresolver/metadata_test.go (about) 1 package fileresolver 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 "github.com/anchore/stereoscope/pkg/file" 11 ) 12 13 func TestFileMetadataFromPath(t *testing.T) { 14 15 tests := []struct { 16 path string 17 expectedType file.Type 18 expectedMIMEType string 19 }{ 20 { 21 path: "test-fixtures/symlinks-simple/readme", 22 expectedType: file.TypeRegular, 23 expectedMIMEType: "text/plain", 24 }, 25 { 26 path: "test-fixtures/symlinks-simple/link_to_new_readme", 27 expectedType: file.TypeSymLink, 28 expectedMIMEType: "", 29 }, 30 { 31 path: "test-fixtures/symlinks-simple/link_to_link_to_new_readme", 32 expectedType: file.TypeSymLink, 33 expectedMIMEType: "", 34 }, 35 { 36 path: "test-fixtures/symlinks-simple", 37 expectedType: file.TypeDirectory, 38 expectedMIMEType: "", 39 }, 40 } 41 for _, test := range tests { 42 t.Run(test.path, func(t *testing.T) { 43 info, err := os.Lstat(test.path) 44 require.NoError(t, err) 45 46 actual := NewMetadataFromPath(test.path, info) 47 assert.Equal(t, test.expectedMIMEType, actual.MIMEType, "unexpected MIME type for %s", test.path) 48 assert.Equal(t, test.expectedType, actual.Type, "unexpected type for %s", test.path) 49 }) 50 } 51 }