|
@@ -59,7 +59,6 @@ func setupPlugin(t *testing.T, name string, mux *http.ServeMux) func() {
|
|
|
|
|
|
type testEndpoint struct {
|
|
type testEndpoint struct {
|
|
t *testing.T
|
|
t *testing.T
|
|
- id int
|
|
|
|
src string
|
|
src string
|
|
dst string
|
|
dst string
|
|
address string
|
|
address string
|
|
@@ -74,16 +73,11 @@ type testEndpoint struct {
|
|
routeType int
|
|
routeType int
|
|
}
|
|
}
|
|
|
|
|
|
-func (test *testEndpoint) Interfaces() []driverapi.InterfaceInfo {
|
|
|
|
- // return an empty one so we don't trip the check for existing
|
|
|
|
- // interfaces; we don't care about this after that
|
|
|
|
- return []driverapi.InterfaceInfo{}
|
|
|
|
|
|
+func (test *testEndpoint) Interface() driverapi.InterfaceInfo {
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (test *testEndpoint) AddInterface(ID int, mac net.HardwareAddr, ipv4 net.IPNet, ipv6 net.IPNet) error {
|
|
|
|
- if ID != test.id {
|
|
|
|
- test.t.Fatalf("Wrong ID passed to AddInterface: %d", ID)
|
|
|
|
- }
|
|
|
|
|
|
+func (test *testEndpoint) AddInterface(mac net.HardwareAddr, ipv4 net.IPNet, ipv6 net.IPNet) error {
|
|
ip4, net4, _ := net.ParseCIDR(test.address)
|
|
ip4, net4, _ := net.ParseCIDR(test.address)
|
|
ip6, net6, _ := net.ParseCIDR(test.addressIPv6)
|
|
ip6, net6, _ := net.ParseCIDR(test.addressIPv6)
|
|
if ip4 != nil {
|
|
if ip4 != nil {
|
|
@@ -104,8 +98,8 @@ func (test *testEndpoint) AddInterface(ID int, mac net.HardwareAddr, ipv4 net.IP
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (test *testEndpoint) InterfaceNames() []driverapi.InterfaceNameInfo {
|
|
|
|
- return []driverapi.InterfaceNameInfo{test}
|
|
|
|
|
|
+func (test *testEndpoint) InterfaceName() driverapi.InterfaceNameInfo {
|
|
|
|
+ return test
|
|
}
|
|
}
|
|
|
|
|
|
func compareIPs(t *testing.T, kind string, shouldBe string, supplied net.IP) {
|
|
func compareIPs(t *testing.T, kind string, shouldBe string, supplied net.IP) {
|
|
@@ -148,7 +142,7 @@ func (test *testEndpoint) SetNames(src string, dst string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (test *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP, interfaceID int) error {
|
|
|
|
|
|
+func (test *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
|
|
compareIPNets(test.t, "Destination", test.destination, *destination)
|
|
compareIPNets(test.t, "Destination", test.destination, *destination)
|
|
compareIPs(test.t, "NextHop", test.nextHop, nextHop)
|
|
compareIPs(test.t, "NextHop", test.nextHop, nextHop)
|
|
|
|
|
|
@@ -156,17 +150,9 @@ func (test *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int,
|
|
test.t.Fatalf(`Wrong RouteType; expected "%d", got "%d"`, test.routeType, routeType)
|
|
test.t.Fatalf(`Wrong RouteType; expected "%d", got "%d"`, test.routeType, routeType)
|
|
}
|
|
}
|
|
|
|
|
|
- if test.id != interfaceID {
|
|
|
|
- test.t.Fatalf(`Wrong InterfaceID; expected "%d", got "%d"`, test.id, interfaceID)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (test *testEndpoint) ID() int {
|
|
|
|
- return test.id
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func TestRemoteDriver(t *testing.T) {
|
|
func TestRemoteDriver(t *testing.T) {
|
|
var plugin = "test-net-driver"
|
|
var plugin = "test-net-driver"
|
|
|
|
|
|
@@ -207,13 +193,12 @@ func TestRemoteDriver(t *testing.T) {
|
|
})
|
|
})
|
|
handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} {
|
|
handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} {
|
|
iface := map[string]interface{}{
|
|
iface := map[string]interface{}{
|
|
- "ID": ep.id,
|
|
|
|
"Address": ep.address,
|
|
"Address": ep.address,
|
|
"AddressIPv6": ep.addressIPv6,
|
|
"AddressIPv6": ep.addressIPv6,
|
|
"MacAddress": ep.macAddress,
|
|
"MacAddress": ep.macAddress,
|
|
}
|
|
}
|
|
return map[string]interface{}{
|
|
return map[string]interface{}{
|
|
- "Interfaces": []interface{}{iface},
|
|
|
|
|
|
+ "Interface": iface,
|
|
}
|
|
}
|
|
})
|
|
})
|
|
handle(t, mux, "Join", func(msg map[string]interface{}) interface{} {
|
|
handle(t, mux, "Join", func(msg map[string]interface{}) interface{} {
|
|
@@ -227,17 +212,14 @@ func TestRemoteDriver(t *testing.T) {
|
|
"GatewayIPv6": ep.gatewayIPv6,
|
|
"GatewayIPv6": ep.gatewayIPv6,
|
|
"HostsPath": ep.hostsPath,
|
|
"HostsPath": ep.hostsPath,
|
|
"ResolvConfPath": ep.resolvConfPath,
|
|
"ResolvConfPath": ep.resolvConfPath,
|
|
- "InterfaceNames": []map[string]interface{}{
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "SrcName": ep.src,
|
|
|
|
- "DstPrefix": ep.dst,
|
|
|
|
- },
|
|
|
|
|
|
+ "InterfaceName": map[string]interface{}{
|
|
|
|
+ "SrcName": ep.src,
|
|
|
|
+ "DstPrefix": ep.dst,
|
|
},
|
|
},
|
|
"StaticRoutes": []map[string]interface{}{
|
|
"StaticRoutes": []map[string]interface{}{
|
|
map[string]interface{}{
|
|
map[string]interface{}{
|
|
"Destination": ep.destination,
|
|
"Destination": ep.destination,
|
|
"RouteType": ep.routeType,
|
|
"RouteType": ep.routeType,
|
|
- "InterfaceID": ep.id,
|
|
|
|
"NextHop": ep.nextHop,
|
|
"NextHop": ep.nextHop,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
@@ -343,13 +325,11 @@ func TestMissingValues(t *testing.T) {
|
|
defer setupPlugin(t, plugin, mux)()
|
|
defer setupPlugin(t, plugin, mux)()
|
|
|
|
|
|
ep := &testEndpoint{
|
|
ep := &testEndpoint{
|
|
- t: t,
|
|
|
|
- id: 0,
|
|
|
|
|
|
+ t: t,
|
|
}
|
|
}
|
|
|
|
|
|
handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} {
|
|
handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} {
|
|
iface := map[string]interface{}{
|
|
iface := map[string]interface{}{
|
|
- "ID": ep.id,
|
|
|
|
"Address": ep.address,
|
|
"Address": ep.address,
|
|
"AddressIPv6": ep.addressIPv6,
|
|
"AddressIPv6": ep.addressIPv6,
|
|
"MacAddress": ep.macAddress,
|
|
"MacAddress": ep.macAddress,
|
|
@@ -373,11 +353,11 @@ func TestMissingValues(t *testing.T) {
|
|
type rollbackEndpoint struct {
|
|
type rollbackEndpoint struct {
|
|
}
|
|
}
|
|
|
|
|
|
-func (r *rollbackEndpoint) Interfaces() []driverapi.InterfaceInfo {
|
|
|
|
- return []driverapi.InterfaceInfo{}
|
|
|
|
|
|
+func (r *rollbackEndpoint) Interface() driverapi.InterfaceInfo {
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (r *rollbackEndpoint) AddInterface(_ int, _ net.HardwareAddr, _ net.IPNet, _ net.IPNet) error {
|
|
|
|
|
|
+func (r *rollbackEndpoint) AddInterface(_ net.HardwareAddr, _ net.IPNet, _ net.IPNet) error {
|
|
return fmt.Errorf("fail this to trigger a rollback")
|
|
return fmt.Errorf("fail this to trigger a rollback")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -391,13 +371,12 @@ func TestRollback(t *testing.T) {
|
|
|
|
|
|
handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} {
|
|
handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} {
|
|
iface := map[string]interface{}{
|
|
iface := map[string]interface{}{
|
|
- "ID": 0,
|
|
|
|
"Address": "192.168.4.5/16",
|
|
"Address": "192.168.4.5/16",
|
|
"AddressIPv6": "",
|
|
"AddressIPv6": "",
|
|
"MacAddress": "7a:12:34:56:78:90",
|
|
"MacAddress": "7a:12:34:56:78:90",
|
|
}
|
|
}
|
|
return map[string]interface{}{
|
|
return map[string]interface{}{
|
|
- "Interfaces": []interface{}{iface},
|
|
|
|
|
|
+ "Interface": interface{}(iface),
|
|
}
|
|
}
|
|
})
|
|
})
|
|
handle(t, mux, "DeleteEndpoint", func(msg map[string]interface{}) interface{} {
|
|
handle(t, mux, "DeleteEndpoint", func(msg map[string]interface{}) interface{} {
|