github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/gojs/errno_test.go (about)

     1  package gojs
     2  
     3  import (
     4  	"io"
     5  	"testing"
     6  
     7  	"github.com/bananabytelabs/wazero/experimental/sys"
     8  )
     9  
    10  func TestToErrno(t *testing.T) {
    11  	tests := []struct {
    12  		name     string
    13  		input    error
    14  		expected *Errno
    15  	}{
    16  		{
    17  			name: "nil is not an error",
    18  		},
    19  		{
    20  			name:  "io.EOF is not an error",
    21  			input: io.EOF,
    22  		},
    23  		{
    24  			name:     "sys.EACCES",
    25  			input:    sys.EACCES,
    26  			expected: ErrnoAcces,
    27  		},
    28  		{
    29  			name:     "sys.EAGAIN",
    30  			input:    sys.EAGAIN,
    31  			expected: ErrnoAgain,
    32  		},
    33  		{
    34  			name:     "sys.EBADF",
    35  			input:    sys.EBADF,
    36  			expected: ErrnoBadf,
    37  		},
    38  		{
    39  			name:     "sys.EEXIST",
    40  			input:    sys.EEXIST,
    41  			expected: ErrnoExist,
    42  		},
    43  		{
    44  			name:     "sys.EFAULT",
    45  			input:    sys.EFAULT,
    46  			expected: ErrnoFault,
    47  		},
    48  		{
    49  			name:     "sys.EINTR",
    50  			input:    sys.EINTR,
    51  			expected: ErrnoIntr,
    52  		},
    53  		{
    54  			name:     "sys.EINVAL",
    55  			input:    sys.EINVAL,
    56  			expected: ErrnoInval,
    57  		},
    58  		{
    59  			name:     "sys.EIO",
    60  			input:    sys.EIO,
    61  			expected: ErrnoIo,
    62  		},
    63  		{
    64  			name:     "sys.EISDIR",
    65  			input:    sys.EISDIR,
    66  			expected: ErrnoIsdir,
    67  		},
    68  		{
    69  			name:     "sys.ELOOP",
    70  			input:    sys.ELOOP,
    71  			expected: ErrnoLoop,
    72  		},
    73  		{
    74  			name:     "sys.ENAMETOOLONG",
    75  			input:    sys.ENAMETOOLONG,
    76  			expected: ErrnoNametoolong,
    77  		},
    78  		{
    79  			name:     "sys.ENOENT",
    80  			input:    sys.ENOENT,
    81  			expected: ErrnoNoent,
    82  		},
    83  		{
    84  			name:     "sys.ENOSYS",
    85  			input:    sys.ENOSYS,
    86  			expected: ErrnoNosys,
    87  		},
    88  		{
    89  			name:     "sys.ENOTDIR",
    90  			input:    sys.ENOTDIR,
    91  			expected: ErrnoNotdir,
    92  		},
    93  		{
    94  			name:     "sys.ENOTEMPTY",
    95  			input:    sys.ENOTEMPTY,
    96  			expected: ErrnoNotempty,
    97  		},
    98  		{
    99  			name:     "sys.ENOTSUP",
   100  			input:    sys.ENOTSUP,
   101  			expected: ErrnoNotsup,
   102  		},
   103  		{
   104  			name:     "sys.EPERM",
   105  			input:    sys.EPERM,
   106  			expected: ErrnoPerm,
   107  		},
   108  		{
   109  			name:     "sys.EROFS",
   110  			input:    sys.EROFS,
   111  			expected: ErrnoRofs,
   112  		},
   113  		{
   114  			name:     "sys.Errno unexpected == ErrnoIo",
   115  			input:    sys.Errno(0xfe),
   116  			expected: ErrnoIo,
   117  		},
   118  	}
   119  
   120  	for _, tt := range tests {
   121  		tc := tt
   122  		t.Run(tc.name, func(t *testing.T) {
   123  			if errno := ToErrno(tc.input); errno != tc.expected {
   124  				t.Fatalf("expected %#v but was %#v", tc.expected, errno)
   125  			}
   126  		})
   127  	}
   128  }