-
Notifications
You must be signed in to change notification settings - Fork 9
/
error_test.go
52 lines (47 loc) · 1.12 KB
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package wasi_test
import (
"context"
"fmt"
"io"
"io/fs"
"net"
"os"
"syscall"
"testing"
"github.com/stealthrocket/wasi-go"
)
func TestErrno(t *testing.T) {
for errno := wasi.Errno(0); errno < wasi.ENOTCAPABLE; errno++ {
t.Run(errno.Name(), func(t *testing.T) {
e1 := errno.Syscall()
e2 := wasi.MakeErrno(e1)
if e2 != errno {
t.Errorf("conversion to syscall.Errno did not yield the same error code: want=%d got=%d", errno, e2)
}
})
}
}
func TestMakeErrno(t *testing.T) {
tests := []struct {
error error
errno wasi.Errno
}{
{nil, wasi.ESUCCESS},
{syscall.EAGAIN, wasi.EAGAIN},
{context.Canceled, wasi.ECANCELED},
{context.DeadlineExceeded, wasi.ETIMEDOUT},
{io.ErrUnexpectedEOF, wasi.EIO},
{fs.ErrClosed, wasi.EIO},
{net.ErrClosed, wasi.EIO},
{syscall.EPERM, wasi.EPERM},
{wasi.EAGAIN, wasi.EAGAIN},
{os.ErrDeadlineExceeded, wasi.ETIMEDOUT},
}
for _, test := range tests {
t.Run(fmt.Sprint(test.error), func(t *testing.T) {
if errno := wasi.MakeErrno(test.error); errno != test.errno {
t.Errorf("error mismatch: want=%d got=%d (%s)", test.errno, errno, errno)
}
})
}
}