github.com/anchore/syft@v1.38.2/internal/unknown/path_error_test.go (about) 1 package unknown 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/anchore/syft/syft/file" 10 ) 11 12 func Test_ProcessPathErrors(t *testing.T) { 13 tests := []struct { 14 errorText string 15 expected error 16 }{ 17 { 18 errorText: `prefix path="/var/lib/thing" suffix`, 19 expected: &CoordinateError{ 20 Coordinates: file.Coordinates{ 21 RealPath: "/var/lib/thing", 22 }, 23 Reason: fmt.Errorf(`prefix path="/var/lib/thing" suffix`), 24 }, 25 }, 26 { 27 errorText: `prefix path="/var/lib/thing"`, 28 expected: &CoordinateError{ 29 Coordinates: file.Coordinates{ 30 RealPath: "/var/lib/thing", 31 }, 32 Reason: fmt.Errorf(`prefix path="/var/lib/thing"`), 33 }, 34 }, 35 { 36 errorText: `path="/var/lib/thing" suffix`, 37 expected: &CoordinateError{ 38 Coordinates: file.Coordinates{ 39 RealPath: "/var/lib/thing", 40 }, 41 Reason: fmt.Errorf(`path="/var/lib/thing" suffix`), 42 }, 43 }, 44 { 45 errorText: "all your base are belong to us", 46 expected: nil, 47 }, 48 } 49 50 for _, test := range tests { 51 t.Run(test.errorText, func(t *testing.T) { 52 got := ProcessPathErrors(fmt.Errorf("%s", test.errorText)) 53 require.Equal(t, test.expected, got) 54 }) 55 } 56 }