diff --git a/ipv4_darwin_test.go b/ipv4_darwin_test.go index 74044c7..c419069 100644 --- a/ipv4_darwin_test.go +++ b/ipv4_darwin_test.go @@ -21,6 +21,15 @@ func setupIfce(t *testing.T, self net.IP, remote net.IP, dev string) { } } +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) @@ -31,6 +40,7 @@ func TestP2PTUN(t *testing.T) { if err != nil { t.Fatalf("creating TUN error: %v\n", err) } + defer teardownIfce(t, ifce) dataCh := make(chan []byte) errCh := make(chan error) diff --git a/ipv4_linux_test.go b/ipv4_linux_test.go index f488ffc..0c81f9c 100644 --- a/ipv4_linux_test.go +++ b/ipv4_linux_test.go @@ -24,6 +24,15 @@ func setupIfce(t *testing.T, ipNet net.IPNet, dev string) { } } +func teardownIfce(t *testing.T, ifce *Interface) { + if err := ifce.Close(); err != nil { + t.Fatal(err) + } + if err := exec.Command("ip", "link", "set", ifce.Name(), "down").Run(); err != nil { + t.Fatal(err) + } +} + func TestBroadcastTAP(t *testing.T) { var ( self = net.IPv4(10, 0, 42, 1) @@ -35,6 +44,7 @@ func TestBroadcastTAP(t *testing.T) { if err != nil { t.Fatalf("creating TAP error: %v\n", err) } + defer teardownIfce(t, ifce) setupIfce(t, net.IPNet{IP: self, Mask: mask}, ifce.Name()) startBroadcast(t, brd)