
Currently the driver configuration is pushed through a separate api. This makes driver configuration possible at any arbitrary time. This unncessarily complicates the driver implementation. More importantly the driver does not get access to it's configuration before it can do the handshake with libnetwork. This make the internal drivers a little bit different to external plugins which can get their configuration before the handshake with libnetwork. This PR attempts to fix that mismatch between internal drivers and external plugins. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
119 lines
2.3 KiB
Go
119 lines
2.3 KiB
Go
package overlay
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/docker/libnetwork/driverapi"
|
|
"github.com/docker/libnetwork/netlabel"
|
|
_ "github.com/docker/libnetwork/testutils"
|
|
)
|
|
|
|
type driverTester struct {
|
|
t *testing.T
|
|
d *driver
|
|
}
|
|
|
|
const testNetworkType = "overlay"
|
|
|
|
func setupDriver(t *testing.T) *driverTester {
|
|
opt := make(map[string]interface{})
|
|
opt[netlabel.OverlayBindInterface] = "eth0"
|
|
dt := &driverTester{t: t}
|
|
if err := Init(dt, opt); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
return dt
|
|
}
|
|
|
|
func cleanupDriver(t *testing.T, dt *driverTester) {
|
|
ch := make(chan struct{})
|
|
go func() {
|
|
Fini(dt.d)
|
|
close(ch)
|
|
}()
|
|
|
|
select {
|
|
case <-ch:
|
|
case <-time.After(10 * time.Second):
|
|
t.Fatal("test timed out because Fini() did not return on time")
|
|
}
|
|
}
|
|
|
|
func (dt *driverTester) RegisterDriver(name string, drv driverapi.Driver,
|
|
cap driverapi.Capability) error {
|
|
if name != testNetworkType {
|
|
dt.t.Fatalf("Expected driver register name to be %q. Instead got %q",
|
|
testNetworkType, name)
|
|
}
|
|
|
|
if _, ok := drv.(*driver); !ok {
|
|
dt.t.Fatalf("Expected driver type to be %T. Instead got %T",
|
|
&driver{}, drv)
|
|
}
|
|
|
|
dt.d = drv.(*driver)
|
|
return nil
|
|
}
|
|
|
|
func TestOverlayInit(t *testing.T) {
|
|
if err := Init(&driverTester{t: t}, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestOverlayFiniWithoutConfig(t *testing.T) {
|
|
dt := &driverTester{t: t}
|
|
if err := Init(dt, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cleanupDriver(t, dt)
|
|
}
|
|
|
|
func TestOverlayNilConfig(t *testing.T) {
|
|
dt := &driverTester{t: t}
|
|
if err := Init(dt, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := dt.d.configure(nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cleanupDriver(t, dt)
|
|
}
|
|
|
|
func TestOverlayConfig(t *testing.T) {
|
|
dt := setupDriver(t)
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
d := dt.d
|
|
if d.notifyCh == nil {
|
|
t.Fatal("Driver notify channel wasn't initialzed after Config method")
|
|
}
|
|
|
|
if d.exitCh == nil {
|
|
t.Fatal("Driver serfloop exit channel wasn't initialzed after Config method")
|
|
}
|
|
|
|
if d.serfInstance == nil {
|
|
t.Fatal("Driver serfinstance hasn't been initialized after Config method")
|
|
}
|
|
|
|
cleanupDriver(t, dt)
|
|
}
|
|
|
|
func TestOverlayType(t *testing.T) {
|
|
dt := &driverTester{t: t}
|
|
if err := Init(dt, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if dt.d.Type() != testNetworkType {
|
|
t.Fatalf("Expected Type() to return %q. Instead got %q", testNetworkType,
|
|
dt.d.Type())
|
|
}
|
|
}
|