forked from tetratelabs/wazero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequire_errno_test.go
67 lines (62 loc) · 1.54 KB
/
require_errno_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package require
import (
"io"
"runtime"
"testing"
"github.com/tetratelabs/wazero/experimental/sys"
)
func TestEqualErrno(t *testing.T) {
// This specifically chooses ENOENT and EIO as outside windows, they tend
// to have the same errno literal and text message.
if runtime.GOOS == "windows" {
t.Skipf("error literals are different on windows")
}
tests := []struct {
name string
require func(TestingT)
expectedLog string
}{
{
name: "EqualErrno passes on equal",
require: func(t TestingT) {
EqualErrno(t, sys.ENOENT, sys.ENOENT)
},
},
{
name: "EqualErrno fails on nil",
require: func(t TestingT) {
EqualErrno(t, sys.ENOENT, nil)
},
expectedLog: "expected a sys.Errno, but was nil",
},
{
name: "EqualErrno fails on not Errno",
require: func(t TestingT) {
EqualErrno(t, sys.ENOENT, io.EOF)
},
expectedLog: `expected EOF to be a sys.Errno`,
},
{
name: "EqualErrno fails on not equal",
require: func(t TestingT) {
EqualErrno(t, sys.ENOENT, sys.EIO)
},
expectedLog: `expected Errno 0xc(no such file or directory), but was 0x8(input/output error)`,
},
{
name: "EqualErrno fails on not equal with format",
require: func(t TestingT) {
EqualErrno(t, sys.ENOENT, sys.EIO, "pay me %d", 5)
},
expectedLog: `expected Errno 0xc(no such file or directory), but was 0x8(input/output error): pay me 5`,
},
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := &mockT{t: t}
tc.require(m)
m.require(tc.expectedLog)
})
}
}