-
Notifications
You must be signed in to change notification settings - Fork 18k
testing/fstest: TestFS should return an unwrappable error #63675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm working on a patch. |
Change https://go.dev/cl/537015 mentions this issue: |
Add testdata/perms.sqlar to check the permissions system. This allowed to discover two issues in testing/fstest.TestFS: - golang/go#63675 errors must be unwrappable - golang/go#63707 relax check on ReadDir if mode & 0444 != 0444
Add testdata/perms.sqlar to check the permissions system. This allowed to discover two issues in testing/fstest.TestFS: - golang/go#63675 errors must be unwrappable - golang/go#63707 relax check on ReadDir if mode & 0444 != 0444
Reviews of CL #537015 would be welcome. |
Here is the workaround I had to implement in my sqlarfs testsuite when testing for var errs interface{ Unwrap() []error }
switch {
case err == nil: // ignore
case errors.As(err, &errs):
for _, err := range errs.Unwrap() {
if errors.Is(err, fs.ErrPermission) {
t.Logf("%T: %[1]q", err)
} else {
t.Fatal(err)
}
}
case errors.Is(err, fs.ErrPermission):
t.Logf("%T: %[1]q", err)
default:
t.Logf("%T: %[1]q", err)
if strings.Contains(err.Error(), fs.ErrPermission.Error()) {
t.Logf("%T: %[1]q", err)
t.Log("Fallback to error message check")
t.Skip("Skip. See https://github.com/golang/go/issues/63675")
}
t.Fatalf("%T: %[1]q", err)
} My CL 537015 is still waiting. |
testing/fstest.TestFS
reports a single error which is the concatenation of all errors. This doesn't allow to analyze the errors by unwraping usingerrors.Is
orerrors.As
or callingUnwrap() []error
.See
TestFS
code: https://github.com/golang/go/blob/master/src/testing/fstest/testfs.go#L107Instead
TestFS
should useerrors.Join
or a custom error that implements theUnwrap() []error
method likeerrors.Join
.What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, on
master
branch.Check code of the
fsTester.errorf
method:https://github.com/golang/go/blob/master/src/testing/fstest/testfs.go#L107
What did you do?
I'm testing a filesystem that enforces permissions: https://github.com/dolmen-go/sqlar
I applied TestFS to a filesystem that returns
fs.ErrPermission
for ReadDir on multiple directories.What did you expect to see?
I would like to analyze the errors using
errors.Is
to ignore expectedfs.ErrPermission
errors.What did you see instead?
I got a big string containing the error messages concatenated.
The text was updated successfully, but these errors were encountered: