-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn_test.go
57 lines (49 loc) · 950 Bytes
/
conn_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
package pio_test
import (
"testing"
// "github.com/kmcsr/go-pio/encoding"
. "github.com/kmcsr/go-pio"
)
func TestConnPing(t *testing.T){
c, d := Pipe()
go d.Serve()
go c.Serve()
defer c.Close()
<-c.ServeDone()
ping, err := c.Ping()
if err != nil {
t.Fatalf("Ping: %v", err)
}
t.Logf("ping: %v", ping)
}
func TestConnAsStream(t *testing.T){
c, d := Pipe()
go d.Serve()
go c.Serve()
defer c.Close()
defer d.Close()
<-c.ServeDone()
if _, err := c.Ping(); err != nil {
t.Fatalf("Ping: %v", err)
}
crw, err := c.AsStream()
if err != nil {
t.Fatalf("c.AsStream: %v", err)
}
go func(){
t.Logf("Writing")
crw.Write(([]byte)("hello pio"))
}()
<-d.StreamedDone()
drw, err := d.AsStream()
if err != nil {
t.Fatalf("d.AsStream: %v", err)
}
t.Logf("Reading")
var buf = make([]byte, 8)
n, err := drw.Read(buf)
if err != nil {
t.Fatalf("d.stream.Read: %v", err)
}
t.Logf("Readed: '%v'", (string)(buf[:n]))
}