-
Notifications
You must be signed in to change notification settings - Fork 296
/
ipv4_darwin_test.go
52 lines (43 loc) · 1.1 KB
/
ipv4_darwin_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 water
import (
"net"
"os/exec"
"testing"
)
func startPing(t *testing.T, dst net.IP, dashB bool) {
params := []string{"-c", "4", dst.String()}
if dashB {
params = append([]string{"-b"}, params...)
}
if err := exec.Command("ping", params...).Start(); err != nil {
t.Fatal(err)
}
}
func setupIfce(t *testing.T, self net.IP, remote net.IP, dev string) {
if err := exec.Command("ifconfig", dev, "inet", self.String(), remote.String(), "up").Run(); err != nil {
t.Fatal(err)
}
}
func teardownIfce(t *testing.T, ifce *Interface) {
if err := ifce.Close(); err != nil {
t.Fatal(err)
}
if err := exec.Command("ifconfig", ifce.Name(), "down").Run(); err != nil {
t.Fatal(err)
}
}
func TestP2PTUN(t *testing.T) {
var (
self = net.IPv4(10, 0, 42, 1)
remote = net.IPv4(10, 0, 42, 2)
)
ifce, err := New(Config{DeviceType: TUN})
if err != nil {
t.Fatalf("creating TUN error: %v\n", err)
}
defer teardownIfce(t, ifce)
dataCh, errCh := startRead(t, ifce)
setupIfce(t, self, remote, ifce.Name())
startPing(t, remote, false)
waitForPingOrBust(t, false, false, self, remote, dataCh, errCh)
}