diff --git a/integrationdhcpv4_test.go b/integration/dhcpv4/dhcpv4_test.go similarity index 99% rename from integrationdhcpv4_test.go rename to integration/dhcpv4/dhcpv4_test.go index a9f22cc..caaa60b 100644 --- a/integrationdhcpv4_test.go +++ b/integration/dhcpv4/dhcpv4_test.go @@ -46,7 +46,7 @@ func TestDHCPv4(t *testing.T) { ready.Close() // dnsmasq will re-create the file anyway defer os.Remove(ready.Name()) // dnsmasq does not clean up its pid file - dnsmasq := dnsmasq.Run(t, "veth0b") + dnsmasq := dnsmasq.Run(t, "veth0b", ns) defer dnsmasq.Kill() // f, err := os.Create("/tmp/pcap") diff --git a/integrationdhcpv6_test.go b/integration/dhcpv6/dhcpv6_test.go similarity index 97% rename from integrationdhcpv6_test.go rename to integration/dhcpv6/dhcpv6_test.go index b811003..3872c2f 100644 --- a/integrationdhcpv6_test.go +++ b/integration/dhcpv6/dhcpv6_test.go @@ -16,7 +16,7 @@ import ( var v6AddrRe = regexp.MustCompile(`2001:db8::[^ ]+`) func TestDHCPv6(t *testing.T) { - const ns = "ns0" // name of the network namespace to use for this test + const ns = "ns1" // name of the network namespace to use for this test if err := exec.Command("ip", "netns", "add", ns).Run(); err != nil { t.Fatalf("ip netns add %s: %v", ns, err) @@ -45,7 +45,7 @@ func TestDHCPv6(t *testing.T) { } } - dnsmasq := dnsmasq.Run(t, "veth1b") + dnsmasq := dnsmasq.Run(t, "veth1b", ns) defer dnsmasq.Kill() // f, err := os.Create("/tmp/pcap6") diff --git a/integrationdns_test.go b/integration/dns/dns_test.go similarity index 100% rename from integrationdns_test.go rename to integration/dns/dns_test.go diff --git a/integrationnetconfig_test.go b/integration/netconfig/netconfig_test.go similarity index 100% rename from integrationnetconfig_test.go rename to integration/netconfig/netconfig_test.go diff --git a/integrationradvd_test.go b/integration/radvd/radvd_test.go similarity index 82% rename from integrationradvd_test.go rename to integration/radvd/radvd_test.go index f93ec48..ab98b53 100644 --- a/integrationradvd_test.go +++ b/integration/radvd/radvd_test.go @@ -10,7 +10,7 @@ import ( ) func TestRouterAdvertisement(t *testing.T) { - const ns = "ns0" // name of the network namespace to use for this test + const ns = "ns2" // name of the network namespace to use for this test if err := exec.Command("ip", "netns", "add", ns).Run(); err != nil { t.Fatalf("ip netns add %s: %v", ns, err) @@ -18,20 +18,20 @@ func TestRouterAdvertisement(t *testing.T) { defer exec.Command("ip", "netns", "delete", ns).Run() nsSetup := []*exec.Cmd{ - exec.Command("ip", "link", "add", "veth0a", "type", "veth", "peer", "name", "veth0b", "netns", ns), + exec.Command("ip", "link", "add", "veth2a", "type", "veth", "peer", "name", "veth2b", "netns", ns), // Disable Duplicate Address Detection: until DAD completes, the link-local // address remains in state “tentative”, resulting in any attempts to // bind(2) to the address to fail with -EADDRNOTAVAIL. - exec.Command("/bin/sh", "-c", "echo 0 > /proc/sys/net/ipv6/conf/veth0a/accept_dad"), - exec.Command("ip", "netns", "exec", ns, "/bin/sh", "-c", "echo 0 > /proc/sys/net/ipv6/conf/veth0b/accept_dad"), + exec.Command("/bin/sh", "-c", "echo 0 > /proc/sys/net/ipv6/conf/veth2a/accept_dad"), + exec.Command("ip", "netns", "exec", ns, "/bin/sh", "-c", "echo 0 > /proc/sys/net/ipv6/conf/veth2b/accept_dad"), - exec.Command("ip", "link", "set", "veth0a", "up"), - exec.Command("ip", "netns", "exec", ns, "ip", "addr", "add", "192.168.23.1/24", "dev", "veth0b"), - exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth0b", "up"), - exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth0b"), + exec.Command("ip", "link", "set", "veth2a", "up"), + exec.Command("ip", "netns", "exec", ns, "ip", "addr", "add", "192.168.23.1/24", "dev", "veth2b"), + exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth2b", "up"), + exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth2b"), - exec.Command("/bin/sh", "-c", "echo 1 > /proc/sys/net/ipv6/conf/veth0a/forwarding"), + exec.Command("/bin/sh", "-c", "echo 1 > /proc/sys/net/ipv6/conf/veth2a/forwarding"), } for _, cmd := range nsSetup { @@ -59,7 +59,7 @@ func TestRouterAdvertisement(t *testing.T) { t.Fatal(err) } go func() { - if err := srv.Serve("veth0a", conn); err != nil { + if err := srv.Serve("veth2a", conn); err != nil { t.Fatal(err) } }() @@ -68,7 +68,7 @@ func TestRouterAdvertisement(t *testing.T) { "--single", // exit after first router advertisement "--retry", "1", // retry only once "--wait", "1000", // wait 1s - "veth0b") + "veth2b") rdisc6.Stderr = os.Stderr b, err := rdisc6.Output() if err != nil { diff --git a/internal/testing/dnsmasq/dnsmasq.go b/internal/testing/dnsmasq/dnsmasq.go index 7c92957..d4888b6 100644 --- a/internal/testing/dnsmasq/dnsmasq.go +++ b/internal/testing/dnsmasq/dnsmasq.go @@ -30,9 +30,7 @@ type Process struct { var dhcpActionRe = regexp.MustCompile(` (DHCP[^(]+\(.*)$`) // Run starts a dnsmasq(8) process and returns a handle to it. -func Run(t *testing.T, iface string) *Process { - const ns = "ns0" // TODO: configurable? - +func Run(t *testing.T, iface, ns string) *Process { ready, err := ioutil.TempFile("", "router7") if err != nil { t.Fatal(err) diff --git a/internal/testing/dnsmasq/example_test.go b/internal/testing/dnsmasq/example_test.go index 50407b3..300b1e9 100644 --- a/internal/testing/dnsmasq/example_test.go +++ b/internal/testing/dnsmasq/example_test.go @@ -9,7 +9,7 @@ import ( ) func Example(t *testing.T) { - dnsmasq := dnsmasq.Run(t, "veth0b") + dnsmasq := dnsmasq.Run(t, "veth0b", "ns0") defer dnsmasq.Kill() // test code here