2014-07-24 01:41:10 +08:00
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateBridgeWithMac(t *testing.T) {
|
2014-07-24 04:45:05 +08:00
|
|
|
if testing.Short() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-07-24 01:41:10 +08:00
|
|
|
name := "testbridge"
|
|
|
|
|
|
|
|
if err := CreateBridge(name, true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := net.InterfaceByName(name); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup and tests
|
|
|
|
|
|
|
|
if err := DeleteBridge(name); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := net.InterfaceByName(name); err == nil {
|
2014-08-06 08:29:37 +08:00
|
|
|
t.Fatalf("expected error getting interface because %s bridge was deleted", name)
|
2014-07-24 01:41:10 +08:00
|
|
|
}
|
|
|
|
}
|
2014-07-24 02:34:07 +08:00
|
|
|
|
2014-08-05 01:29:06 +08:00
|
|
|
func TestCreateBridgeLink(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
name := "mybrlink"
|
|
|
|
|
|
|
|
if err := NetworkLinkAdd(name, "bridge"); err != nil {
|
2014-08-06 07:40:26 +08:00
|
|
|
t.Fatal(err)
|
2014-08-05 01:29:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := net.InterfaceByName(name); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := NetworkLinkDel(name); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := net.InterfaceByName(name); err == nil {
|
2014-08-06 08:29:37 +08:00
|
|
|
t.Fatalf("expected error getting interface because %s bridge was deleted", name)
|
2014-08-05 01:29:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-24 02:34:07 +08:00
|
|
|
func TestCreateVethPair(t *testing.T) {
|
2014-07-24 04:45:05 +08:00
|
|
|
if testing.Short() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-07-24 02:34:07 +08:00
|
|
|
var (
|
|
|
|
name1 = "veth1"
|
|
|
|
name2 = "veth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := NetworkCreateVethPair(name1, name2); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := net.InterfaceByName(name1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := net.InterfaceByName(name2); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|