sysfs: consolidates errno coersion and maps EAGAIN and EINTR (#1113)
Signed-off-by: Adrian Cole <adrian@tetrate.io> Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
package gojs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
@@ -17,6 +13,11 @@ func TestToErrno(t *testing.T) {
|
||||
input error
|
||||
expected *Errno
|
||||
}{
|
||||
{
|
||||
name: "syscall.EAGAIN",
|
||||
input: syscall.EAGAIN,
|
||||
expected: ErrnoAgain,
|
||||
},
|
||||
{
|
||||
name: "syscall.EBADF",
|
||||
input: syscall.EBADF,
|
||||
@@ -27,6 +28,11 @@ func TestToErrno(t *testing.T) {
|
||||
input: syscall.EEXIST,
|
||||
expected: ErrnoExist,
|
||||
},
|
||||
{
|
||||
name: "syscall.EINTR",
|
||||
input: syscall.EINTR,
|
||||
expected: ErrnoIntr,
|
||||
},
|
||||
{
|
||||
name: "syscall.EINVAL",
|
||||
input: syscall.EINVAL,
|
||||
@@ -87,46 +93,6 @@ func TestToErrno(t *testing.T) {
|
||||
input: syscall.Errno(0xfe),
|
||||
expected: ErrnoIo,
|
||||
},
|
||||
{
|
||||
name: "PathError ErrInvalid",
|
||||
input: &os.PathError{Err: fs.ErrInvalid},
|
||||
expected: ErrnoInval,
|
||||
},
|
||||
{
|
||||
name: "PathError ErrPermission",
|
||||
input: &os.PathError{Err: fs.ErrPermission},
|
||||
expected: ErrnoPerm,
|
||||
},
|
||||
{
|
||||
name: "PathError ErrExist",
|
||||
input: &os.PathError{Err: fs.ErrExist},
|
||||
expected: ErrnoExist,
|
||||
},
|
||||
{
|
||||
name: "PathError ErrNotExist",
|
||||
input: &os.PathError{Err: fs.ErrNotExist},
|
||||
expected: ErrnoNoent,
|
||||
},
|
||||
{
|
||||
name: "PathError ErrClosed",
|
||||
input: &os.PathError{Err: fs.ErrClosed},
|
||||
expected: ErrnoBadf,
|
||||
},
|
||||
{
|
||||
name: "PathError unknown == ErrnoIo",
|
||||
input: &os.PathError{Err: errors.New("ice cream")},
|
||||
expected: ErrnoIo,
|
||||
},
|
||||
{
|
||||
name: "unknown == ErrnoIo",
|
||||
input: errors.New("ice cream"),
|
||||
expected: ErrnoIo,
|
||||
},
|
||||
{
|
||||
name: "very wrapped unknown == ErrnoIo",
|
||||
input: fmt.Errorf("%w", fmt.Errorf("%w", fmt.Errorf("%w", errors.New("ice cream")))),
|
||||
expected: ErrnoIo,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user