Files
moby/libnetwork/drivers/macvlan/macvlan_test.go
Albin Kerouanton e5bf6d8ba0 libnet: pass store as an arg to netdrivers
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>
2024-12-20 17:51:53 +01:00

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())
}
}