Browse Source

Add test code for windows.

lucus 8 years ago
parent
commit
dd56f4a2c6
4 changed files with 36 additions and 8 deletions
  1. 7 0
      ipv4_linux_test.go
  2. 1 1
      ipv4_other_test.go
  3. 0 7
      ipv4_test.go
  4. 28 0
      ipv4_windows_test.go

+ 7 - 0
ipv4_linux_test.go

@@ -1,3 +1,4 @@
+// +build linux,darwin
 package water
 
 import (
@@ -6,6 +7,12 @@ import (
 	"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) {
 	if err := exec.Command("ip", "link", "set", dev, "up").Run(); err != nil {
 		t.Fatal(err)

+ 1 - 1
ipv4_other_test.go

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

+ 0 - 7
ipv4_test.go

@@ -2,7 +2,6 @@ package water
 
 import (
 	"net"
-	"os/exec"
 	"testing"
 	"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) {
 	var (
 		self = net.IPv4(10, 0, 42, 1)

+ 28 - 0
ipv4_windows_test.go

@@ -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)
+	}
+}