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:
parent
2ff269bf67
commit
5a07d6696d
@ -46,7 +46,7 @@ func TestDHCPv4(t *testing.T) {
|
|||||||
ready.Close() // dnsmasq will re-create the file anyway
|
ready.Close() // dnsmasq will re-create the file anyway
|
||||||
defer os.Remove(ready.Name()) // dnsmasq does not clean up its pid file
|
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()
|
defer dnsmasq.Kill()
|
||||||
|
|
||||||
// f, err := os.Create("/tmp/pcap")
|
// f, err := os.Create("/tmp/pcap")
|
@ -16,7 +16,7 @@ import (
|
|||||||
var v6AddrRe = regexp.MustCompile(`2001:db8::[^ ]+`)
|
var v6AddrRe = regexp.MustCompile(`2001:db8::[^ ]+`)
|
||||||
|
|
||||||
func TestDHCPv6(t *testing.T) {
|
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 {
|
if err := exec.Command("ip", "netns", "add", ns).Run(); err != nil {
|
||||||
t.Fatalf("ip netns add %s: %v", ns, err)
|
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()
|
defer dnsmasq.Kill()
|
||||||
|
|
||||||
// f, err := os.Create("/tmp/pcap6")
|
// f, err := os.Create("/tmp/pcap6")
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRouterAdvertisement(t *testing.T) {
|
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 {
|
if err := exec.Command("ip", "netns", "add", ns).Run(); err != nil {
|
||||||
t.Fatalf("ip netns add %s: %v", ns, err)
|
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()
|
defer exec.Command("ip", "netns", "delete", ns).Run()
|
||||||
|
|
||||||
nsSetup := []*exec.Cmd{
|
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
|
// Disable Duplicate Address Detection: until DAD completes, the link-local
|
||||||
// address remains in state “tentative”, resulting in any attempts to
|
// address remains in state “tentative”, resulting in any attempts to
|
||||||
// bind(2) to the address to fail with -EADDRNOTAVAIL.
|
// 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("/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/veth0b/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", "link", "set", "veth2a", "up"),
|
||||||
exec.Command("ip", "netns", "exec", ns, "ip", "addr", "add", "192.168.23.1/24", "dev", "veth0b"),
|
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", "veth0b", "up"),
|
exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth2b", "up"),
|
||||||
exec.Command("ip", "netns", "exec", ns, "ip", "link", "set", "veth0b"),
|
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 {
|
for _, cmd := range nsSetup {
|
||||||
@ -59,7 +59,7 @@ func TestRouterAdvertisement(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if err := srv.Serve("veth0a", conn); err != nil {
|
if err := srv.Serve("veth2a", conn); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -68,7 +68,7 @@ func TestRouterAdvertisement(t *testing.T) {
|
|||||||
"--single", // exit after first router advertisement
|
"--single", // exit after first router advertisement
|
||||||
"--retry", "1", // retry only once
|
"--retry", "1", // retry only once
|
||||||
"--wait", "1000", // wait 1s
|
"--wait", "1000", // wait 1s
|
||||||
"veth0b")
|
"veth2b")
|
||||||
rdisc6.Stderr = os.Stderr
|
rdisc6.Stderr = os.Stderr
|
||||||
b, err := rdisc6.Output()
|
b, err := rdisc6.Output()
|
||||||
if err != nil {
|
if err != nil {
|
@ -30,9 +30,7 @@ type Process struct {
|
|||||||
var dhcpActionRe = regexp.MustCompile(` (DHCP[^(]+\(.*)$`)
|
var dhcpActionRe = regexp.MustCompile(` (DHCP[^(]+\(.*)$`)
|
||||||
|
|
||||||
// Run starts a dnsmasq(8) process and returns a handle to it.
|
// Run starts a dnsmasq(8) process and returns a handle to it.
|
||||||
func Run(t *testing.T, iface string) *Process {
|
func Run(t *testing.T, iface, ns string) *Process {
|
||||||
const ns = "ns0" // TODO: configurable?
|
|
||||||
|
|
||||||
ready, err := ioutil.TempFile("", "router7")
|
ready, err := ioutil.TempFile("", "router7")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Example(t *testing.T) {
|
func Example(t *testing.T) {
|
||||||
dnsmasq := dnsmasq.Run(t, "veth0b")
|
dnsmasq := dnsmasq.Run(t, "veth0b", "ns0")
|
||||||
defer dnsmasq.Kill()
|
defer dnsmasq.Kill()
|
||||||
// test code here
|
// test code here
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user