Add test code for windows.

This commit is contained in:
lucus 2016-12-26 04:59:00 +09:00
parent b090a0ff67
commit dd56f4a2c6
4 changed files with 36 additions and 8 deletions

View file

@ -1,3 +1,4 @@
// +build linux,darwin
package water package water
import ( import (
@ -6,6 +7,12 @@ import (
"testing" "testing"
) )
func startBroadcast(t *testing.T, dst net.IP) {
if err := exec.Command("ping", "-b", "-c", "2", dst.String()).Start(); err != nil {
t.Fatal(err)
}
}
func setupIfce(t *testing.T, ipNet net.IPNet, dev string) { func setupIfce(t *testing.T, ipNet net.IPNet, dev string) {
if err := exec.Command("ip", "link", "set", dev, "up").Run(); err != nil { if err := exec.Command("ip", "link", "set", dev, "up").Run(); err != nil {
t.Fatal(err) t.Fatal(err)

View file

@ -1,4 +1,4 @@
// +build !linux // +build !linux,!windows
package water package water

View file

@ -2,7 +2,6 @@ package water
import ( import (
"net" "net"
"os/exec"
"testing" "testing"
"time" "time"
@ -24,12 +23,6 @@ func startRead(ch chan<- []byte, ifce *Interface) {
}() }()
} }
func startBroadcast(t *testing.T, dst net.IP) {
if err := exec.Command("ping", "-b", "-c", "2", dst.String()).Start(); err != nil {
t.Fatal(err)
}
}
func TestBroadcast(t *testing.T) { func TestBroadcast(t *testing.T) {
var ( var (
self = net.IPv4(10, 0, 42, 1) self = net.IPv4(10, 0, 42, 1)

28
ipv4_windows_test.go Normal file
View file

@ -0,0 +1,28 @@
// +build windows
package water
import (
"fmt"
"net"
"os/exec"
"strings"
"testing"
)
func startBroadcast(t *testing.T, dst net.IP) {
if err := exec.Command("ping", "-n", "2", dst.String()).Start(); err != nil {
t.Fatal(err)
}
}
func setupIfce(t *testing.T, ipNet net.IPNet, dev string) {
sargs := fmt.Sprintf("interface ip set address name=REPLACE_ME source=static addr=REPLACE_ME mask=REPLACE_ME gateway=none")
args := strings.Split(sargs, " ")
args[4] = fmt.Sprintf("name=%s", dev)
args[6] = fmt.Sprintf("addr=%s", ipNet.IP)
args[7] = fmt.Sprintf("mask=%d.%d.%d.%d", ipNet.Mask[0], ipNet.Mask[1], ipNet.Mask[2], ipNet.Mask[3])
cmd := exec.Command("netsh", args...)
if err := cmd.Run(); err != nil {
t.Fatal(err)
}
}