2014-10-03 05:54:48 +08:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/libcontainer/netlink"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateVethNames(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix := "veth"
|
|
|
|
|
2014-09-17 17:02:27 +08:00
|
|
|
name1, name2, err := createVethPair(prefix, 0)
|
2014-10-03 05:54:48 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if name1 == "" {
|
|
|
|
t.Fatal("name1 should not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if name2 == "" {
|
|
|
|
t.Fatal("name2 should not be empty")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateDuplicateVethPair(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix := "veth"
|
|
|
|
|
2014-09-17 17:02:27 +08:00
|
|
|
name1, name2, err := createVethPair(prefix, 0)
|
2014-10-03 05:54:48 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// retry to create the name interfaces and make sure that we get the correct error
|
2014-09-17 17:02:27 +08:00
|
|
|
err = CreateVethPair(name1, name2, 0)
|
2014-10-03 05:54:48 +08:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error to not be nil with duplicate interface")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != netlink.ErrInterfaceExists {
|
|
|
|
t.Fatalf("expected error to be ErrInterfaceExists but received %q", err)
|
|
|
|
}
|
|
|
|
}
|