github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/file/location_test.go (about) 1 package file 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/anchore/stereoscope/pkg/file" 9 ) 10 11 func TestLocation_ID(t *testing.T) { 12 tests := []struct { 13 name string 14 coordinates Coordinates 15 virtualPath string 16 ref file.Reference 17 }{ 18 { 19 name: "coordinates should match location hash", 20 coordinates: Coordinates{ 21 RealPath: "path!", 22 FileSystemID: "filesystem!", 23 }, 24 }, 25 { 26 name: "coordinates should match location hash (with extra fields)", 27 coordinates: Coordinates{ 28 RealPath: "path!", 29 FileSystemID: "filesystem!", 30 }, 31 virtualPath: "virtualPath!", 32 ref: file.Reference{ 33 RealPath: "other-real-path!", 34 }, 35 }, 36 } 37 for _, test := range tests { 38 t.Run(test.name, func(t *testing.T) { 39 l := Location{ 40 LocationData: LocationData{ 41 Coordinates: test.coordinates, 42 VirtualPath: test.virtualPath, 43 ref: test.ref, 44 }, 45 } 46 assert.Equal(t, l.ID(), test.coordinates.ID()) 47 }) 48 } 49 50 }