| 1 | package pathidentity |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | "os" |
| 7 | "syscall" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestClassifyPreservesWrappedFilesystemErrors(t *testing.T) { |
| 12 | for _, tc := range []struct { |
| 13 | name string |
| 14 | err error |
| 15 | kind ErrorKind |
| 16 | }{ |
| 17 | {"missing", os.ErrNotExist, ErrorUnavailable}, |
| 18 | {"missing-syscall", syscall.ENOENT, ErrorUnavailable}, |
| 19 | {"denied", os.ErrPermission, ErrorPermission}, |
| 20 | {"loop", syscall.ELOOP, ErrorLinkLoop}, |
| 21 | } { |
| 22 | t.Run(tc.name, func(t *testing.T) { |
| 23 | err := classify("physical", "fixture", fmt.Errorf("open physical path: %w", tc.err)) |
| 24 | var failure *Error |
| 25 | if !errors.As(err, &failure) || failure.Kind != tc.kind || !errors.Is(err, tc.err) { |
| 26 | t.Fatalf("lost error kind or cause: %v", err) |
| 27 | } |
| 28 | }) |
| 29 | } |
| 30 | } |
| 31 |