Commit fd9049f4 authored by Mikio Hara's avatar Mikio Hara

net: skip interface tests when required external command not found

Fixes #4952.

R=alex.brainman
CC=golang-dev
https://golang.org/cl/7445046
parent 83c8cc54
...@@ -11,11 +11,11 @@ import ( ...@@ -11,11 +11,11 @@ import (
"os/exec" "os/exec"
) )
func (ti *testInterface) setBroadcast(suffix int) { func (ti *testInterface) setBroadcast(suffix int) error {
ti.name = fmt.Sprintf("vlan%d", suffix) ti.name = fmt.Sprintf("vlan%d", suffix)
xname, err := exec.LookPath("ifconfig") xname, err := exec.LookPath("ifconfig")
if err != nil { if err != nil {
xname = "ifconfig" return err
} }
ti.setupCmds = append(ti.setupCmds, &exec.Cmd{ ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
Path: xname, Path: xname,
...@@ -25,15 +25,16 @@ func (ti *testInterface) setBroadcast(suffix int) { ...@@ -25,15 +25,16 @@ func (ti *testInterface) setBroadcast(suffix int) {
Path: xname, Path: xname,
Args: []string{"ifconfig", ti.name, "destroy"}, Args: []string{"ifconfig", ti.name, "destroy"},
}) })
return nil
} }
func (ti *testInterface) setPointToPoint(suffix int, local, remote string) { func (ti *testInterface) setPointToPoint(suffix int, local, remote string) error {
ti.name = fmt.Sprintf("gif%d", suffix) ti.name = fmt.Sprintf("gif%d", suffix)
ti.local = local ti.local = local
ti.remote = remote ti.remote = remote
xname, err := exec.LookPath("ifconfig") xname, err := exec.LookPath("ifconfig")
if err != nil { if err != nil {
xname = "ifconfig" return err
} }
ti.setupCmds = append(ti.setupCmds, &exec.Cmd{ ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
Path: xname, Path: xname,
...@@ -47,4 +48,5 @@ func (ti *testInterface) setPointToPoint(suffix int, local, remote string) { ...@@ -47,4 +48,5 @@ func (ti *testInterface) setPointToPoint(suffix int, local, remote string) {
Path: xname, Path: xname,
Args: []string{"ifconfig", ti.name, "destroy"}, Args: []string{"ifconfig", ti.name, "destroy"},
}) })
return nil
} }
...@@ -10,11 +10,11 @@ import ( ...@@ -10,11 +10,11 @@ import (
"testing" "testing"
) )
func (ti *testInterface) setBroadcast(suffix int) { func (ti *testInterface) setBroadcast(suffix int) error {
ti.name = fmt.Sprintf("gotest%d", suffix) ti.name = fmt.Sprintf("gotest%d", suffix)
xname, err := exec.LookPath("ip") xname, err := exec.LookPath("ip")
if err != nil { if err != nil {
xname = "ip" return err
} }
ti.setupCmds = append(ti.setupCmds, &exec.Cmd{ ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
Path: xname, Path: xname,
...@@ -24,15 +24,16 @@ func (ti *testInterface) setBroadcast(suffix int) { ...@@ -24,15 +24,16 @@ func (ti *testInterface) setBroadcast(suffix int) {
Path: xname, Path: xname,
Args: []string{"ip", "link", "delete", ti.name, "type", "dummy"}, Args: []string{"ip", "link", "delete", ti.name, "type", "dummy"},
}) })
return nil
} }
func (ti *testInterface) setPointToPoint(suffix int, local, remote string) { func (ti *testInterface) setPointToPoint(suffix int, local, remote string) error {
ti.name = fmt.Sprintf("gotest%d", suffix) ti.name = fmt.Sprintf("gotest%d", suffix)
ti.local = local ti.local = local
ti.remote = remote ti.remote = remote
xname, err := exec.LookPath("ip") xname, err := exec.LookPath("ip")
if err != nil { if err != nil {
xname = "ip" return err
} }
ti.setupCmds = append(ti.setupCmds, &exec.Cmd{ ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
Path: xname, Path: xname,
...@@ -44,12 +45,13 @@ func (ti *testInterface) setPointToPoint(suffix int, local, remote string) { ...@@ -44,12 +45,13 @@ func (ti *testInterface) setPointToPoint(suffix int, local, remote string) {
}) })
xname, err = exec.LookPath("ifconfig") xname, err = exec.LookPath("ifconfig")
if err != nil { if err != nil {
xname = "ifconfig" return err
} }
ti.setupCmds = append(ti.setupCmds, &exec.Cmd{ ti.setupCmds = append(ti.setupCmds, &exec.Cmd{
Path: xname, Path: xname,
Args: []string{"ifconfig", ti.name, "inet", local, "dstaddr", remote}, Args: []string{"ifconfig", ti.name, "inet", local, "dstaddr", remote},
}) })
return nil
} }
const ( const (
......
...@@ -53,7 +53,9 @@ func TestPointToPointInterface(t *testing.T) { ...@@ -53,7 +53,9 @@ func TestPointToPointInterface(t *testing.T) {
ip := ParseIP(remote) ip := ParseIP(remote)
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
ti := &testInterface{} ti := &testInterface{}
ti.setPointToPoint(5963+i, local, remote) if err := ti.setPointToPoint(5963+i, local, remote); err != nil {
t.Skipf("test requries external command: %v", err)
}
if err := ti.setup(); err != nil { if err := ti.setup(); err != nil {
t.Fatalf("testInterface.setup failed: %v", err) t.Fatalf("testInterface.setup failed: %v", err)
} else { } else {
...@@ -98,7 +100,9 @@ func TestInterfaceArrivalAndDeparture(t *testing.T) { ...@@ -98,7 +100,9 @@ func TestInterfaceArrivalAndDeparture(t *testing.T) {
t.Fatalf("Interfaces failed: %v", err) t.Fatalf("Interfaces failed: %v", err)
} }
ti := &testInterface{} ti := &testInterface{}
ti.setBroadcast(5682 + i) if err := ti.setBroadcast(5682 + i); err != nil {
t.Skipf("test requires external command: %v", err)
}
if err := ti.setup(); err != nil { if err := ti.setup(); err != nil {
t.Fatalf("testInterface.setup failed: %v", err) t.Fatalf("testInterface.setup failed: %v", err)
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment