-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctxio_bsd_wrap_test.go
More file actions
109 lines (79 loc) · 1.91 KB
/
ctxio_bsd_wrap_test.go
File metadata and controls
109 lines (79 loc) · 1.91 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//go:build darwin || freebsd || netbsd || openbsd
package ctxio
import (
"os"
"testing"
)
func TestWrapFilePipe(t *testing.T) {
t.Parallel()
r, w, err := os.Pipe()
if err != nil {
t.Fatalf("os.Pipe: %v", err)
}
defer r.Close()
defer w.Close()
cio, err := WrapFile(r)
if err != nil {
t.Fatalf("WrapFile(pipe): %v", err)
}
defer cio.Close()
if _, ok := cio.(*kqueueIO); !ok {
t.Errorf("WrapFile(pipe) = %T, want *kqueueIO", cio)
}
}
func TestWrapFileRegular(t *testing.T) {
t.Parallel()
f, err := os.CreateTemp(t.TempDir(), "ctxio-wrap-test-*")
if err != nil {
t.Fatalf("CreateTemp: %v", err)
}
defer f.Close()
cio, err := WrapFile(f)
if err != nil {
t.Fatalf("WrapFile(regular file): %v", err)
}
defer cio.Close()
if _, ok := cio.(*kqueueIO); !ok {
t.Errorf("WrapFile(regular file) = %T, want *kqueueIO", cio)
}
}
func TestWrapConnTCP(t *testing.T) {
t.Parallel()
conn, _ := activeConns(t, "tcp4", "127.0.0.1:0")
cio, err := WrapConn(conn)
if err != nil {
t.Fatalf("WrapConn(tcp): %v", err)
}
defer cio.Close()
if _, ok := cio.(*kqueueIO); !ok {
t.Errorf("WrapConn(tcp) = %T, want *kqueueIO", cio)
}
}
func TestWrapFileTTY(t *testing.T) {
t.Parallel()
tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
if err != nil {
t.Skipf("skipping: cannot open /dev/tty: %v", err)
}
defer tty.Close()
cio, err := WrapFile(tty)
if err != nil {
t.Fatalf("WrapFile(/dev/tty): %v", err)
}
defer cio.Close()
if _, ok := cio.(*selectIO); !ok {
t.Errorf("WrapFile(/dev/tty) = %T, want *selectIO", cio)
}
}
func TestWrapConnDeadlineFallback(t *testing.T) {
t.Parallel()
conn, _ := activeConns(t, "tcp4", "127.0.0.1:0")
cio, err := WrapConn(deadlinerOnlyConn{Conn: conn})
if err != nil {
t.Fatalf("WrapConn(deadlinerOnlyConn): %v", err)
}
defer cio.Close()
if _, ok := cio.(*deadlineIO); !ok {
t.Errorf("WrapConn(deadlinerOnlyConn) = %T, want *deadlineIO", cio)
}
}