-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunix_test.go
More file actions
47 lines (42 loc) · 997 Bytes
/
unix_test.go
File metadata and controls
47 lines (42 loc) · 997 Bytes
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
package node
import (
"bytes"
"encoding/json"
"net"
"testing"
"github.com/AutoRoute/node/internal"
"github.com/AutoRoute/node/types"
)
func TestUnixSocket(t *testing.T) {
_, err := NewUnixSocket("/impossible/NON EXISTANT PATH", nil)
if err == nil {
t.Fatal("Expected failure of opening NON EXISTANT PATH")
}
data := internal.TestDataConnection{make(chan types.Packet), make(chan types.Packet)}
c, err := NewUnixSocket("/tmp/test", data)
if err != nil {
t.Fatal("Error opening test pipe", err)
}
defer c.Close()
p := types.Packet{"dest", 10, []byte("data")}
c2, err := net.Dial("unix", "/tmp/test")
if err != nil {
t.Fatal(err)
}
w := json.NewEncoder(c2)
d := json.NewDecoder(c2)
err = w.Encode(p)
if err != nil {
t.Fatal(err)
}
p2 := <-data.Out
data.In <- p2
var p3 types.Packet
err = d.Decode(&p3)
if err != nil {
t.Fatal(err)
}
if p3.Dest != p.Dest || p3.Amt != p.Amt || bytes.Compare(p3.Data, p.Data) != 0 {
t.Fatalf("Error %q != %q", p3, p)
}
}