split integration tests into multiple packages

This makes them complete more quickly (because they are run in parallel) and
invalidates only the cache for the integration test I’m working on, not for all
of them.
This commit is contained in:
Michael Stapelberg 2018-06-24 11:45:18 +02:00
parent 2ff269bf67
commit 5a07d6696d
7 changed files with 16 additions and 18 deletions

View File

@ -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")

View File

@ -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")

View File

@ -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 {

View File

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

View File

@ -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