mirror of
https://github.com/moby/moby.git
synced 2026-08-08 00:52:17 +00:00
Before that change, we were passing the datastore to network drivers
through a `map[string]interface{}`. Then, each driver that needed the
store would cast the datastore to the correct type.
This was not a good design, as it was not clear which drivers were using
the store and which were not. Not all unit tests were passing the store,
leading to logs about uninitialized store being written.
This change makes the store a parameter of the `RegisterX` functions.
All unit tests are now passing a valid datastore to the drivers. A new
testutil func is added for that purpose.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
//go:build linux
|
|
|
|
package macvlan
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/docker/docker/internal/testutils/storeutils"
|
|
"github.com/docker/docker/libnetwork/driverapi"
|
|
)
|
|
|
|
const testNetworkType = "macvlan"
|
|
|
|
type driverTester struct {
|
|
t *testing.T
|
|
d *driver
|
|
}
|
|
|
|
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 TestMacvlanRegister(t *testing.T) {
|
|
if err := Register(&driverTester{t: t}, storeutils.NewTempStore(t), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMacvlanNilConfig(t *testing.T) {
|
|
dt := &driverTester{t: t}
|
|
if err := Register(dt, storeutils.NewTempStore(t), nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := dt.d.initStore(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMacvlanType(t *testing.T) {
|
|
dt := &driverTester{t: t}
|
|
if err := Register(dt, storeutils.NewTempStore(t), 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())
|
|
}
|
|
}
|