mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com> Signed-off-by: Keith Zantow <kzantow@gmail.com> Co-authored-by: Keith Zantow <kzantow@gmail.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package unknown
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
)
|
|
|
|
func Test_ProcessPathErrors(t *testing.T) {
|
|
tests := []struct {
|
|
errorText string
|
|
expected error
|
|
}{
|
|
{
|
|
errorText: `prefix path="/var/lib/thing" suffix`,
|
|
expected: &CoordinateError{
|
|
Coordinates: file.Coordinates{
|
|
RealPath: "/var/lib/thing",
|
|
},
|
|
Reason: fmt.Errorf(`prefix path="/var/lib/thing" suffix`),
|
|
},
|
|
},
|
|
{
|
|
errorText: `prefix path="/var/lib/thing"`,
|
|
expected: &CoordinateError{
|
|
Coordinates: file.Coordinates{
|
|
RealPath: "/var/lib/thing",
|
|
},
|
|
Reason: fmt.Errorf(`prefix path="/var/lib/thing"`),
|
|
},
|
|
},
|
|
{
|
|
errorText: `path="/var/lib/thing" suffix`,
|
|
expected: &CoordinateError{
|
|
Coordinates: file.Coordinates{
|
|
RealPath: "/var/lib/thing",
|
|
},
|
|
Reason: fmt.Errorf(`path="/var/lib/thing" suffix`),
|
|
},
|
|
},
|
|
{
|
|
errorText: "all your base are belong to us",
|
|
expected: nil,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.errorText, func(t *testing.T) {
|
|
got := ProcessPathErrors(fmt.Errorf("%s", test.errorText))
|
|
require.Equal(t, test.expected, got)
|
|
})
|
|
}
|
|
}
|