mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6fb69f0816
With the introduction of a driver generic gossip in libnetwork it is not necessary for drivers to run their own gossip protocol (like what overlay driver is doing currently) but instead rely on the gossip instance run centrally in libnetwork. In order to achieve this, certain enhancements to driver api are needed. This api aims to provide these enhancements. The new api provides a way for drivers to register interest on table names of their choice by returning a list of table names of interest as a response to CreateNetwork. By doing that they will get notified if a CRUD operation happened on the tables of their interest, via the newly added EventNotify call. Drivers themselves can add entries to any table during a Join call by invoking AddTableEntry method any number of times during the Join call. These entries lifetime is the same as the endpoint itself. As soon as the container leaves the endpoint, those entries added by driver during that endpoint's Join call will be automatically removed by libnetwork. This action may trigger notification of such deletion to all driver instances in the cluster who have registered interest in that table's notification. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package null
|
|
|
|
import (
|
|
"testing"
|
|
|
|
_ "github.com/docker/libnetwork/testutils"
|
|
"github.com/docker/libnetwork/types"
|
|
)
|
|
|
|
func TestDriver(t *testing.T) {
|
|
d := &driver{}
|
|
|
|
if d.Type() != networkType {
|
|
t.Fatalf("Unexpected network type returned by driver")
|
|
}
|
|
|
|
err := d.CreateNetwork("first", nil, nil, nil, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if d.network != "first" {
|
|
t.Fatalf("Unexpected network id stored")
|
|
}
|
|
|
|
err = d.CreateNetwork("second", nil, nil, nil, nil)
|
|
if err == nil {
|
|
t.Fatalf("Second network creation should fail on this driver")
|
|
}
|
|
if _, ok := err.(types.ForbiddenError); !ok {
|
|
t.Fatalf("Second network creation failed with unexpected error type")
|
|
}
|
|
|
|
err = d.DeleteNetwork("first")
|
|
if err == nil {
|
|
t.Fatalf("network deletion should fail on this driver")
|
|
}
|
|
if _, ok := err.(types.ForbiddenError); !ok {
|
|
t.Fatalf("network deletion failed with unexpected error type")
|
|
}
|
|
|
|
// we don't really check if it is there or not, delete is not allowed for this driver, period.
|
|
err = d.DeleteNetwork("unknown")
|
|
if err == nil {
|
|
t.Fatalf("any network deletion should fail on this driver")
|
|
}
|
|
if _, ok := err.(types.ForbiddenError); !ok {
|
|
t.Fatalf("any network deletion failed with unexpected error type")
|
|
}
|
|
}
|