Files
moby/daemon/libnetwork/store_test.go
Albin Kerouanton 2436458227 libnet/d/bridge: Register: pass a Configuration struct
Libnetwork passes a map[string]any to the bridge driver's Register
function. This forces the daemon to convert its configuration into a
map, and the driver to convert that map back into a struct.

This is unnecessary complexity, and makes it harder to track down where
and how bridge driver configuration fields are set.

Refactor libnetwork to let the daemon register the bridge.Configuration
directly through a new option `OptionBridgeConfig`.

The bridge driver now takes a `Configuration` param that needs no
special treatment.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-03 12:10:10 +02:00

59 lines
1.6 KiB
Go

package libnetwork
import (
"context"
"testing"
"github.com/moby/moby/v2/daemon/libnetwork/config"
)
func testLocalBackend(t *testing.T, path, bucket string) {
cfgOptions := []config.Option{
config.OptionDataDir(path),
func(c *config.Config) { c.DatastoreBucket = bucket },
}
testController, err := New(context.Background(), cfgOptions...)
if err != nil {
t.Fatalf("Error new controller: %v", err)
}
defer testController.Stop()
nw, err := testController.NewNetwork(context.Background(), "host", "host", "")
if err != nil {
t.Fatalf(`Error creating default "host" network: %v`, err)
}
ep, err := nw.CreateEndpoint(context.Background(), "newendpoint", []EndpointOption{}...)
if err != nil {
t.Fatalf("Error creating endpoint: %v", err)
}
nwKVObject := &Network{id: nw.ID()}
err = testController.store.GetObject(nwKVObject)
if err != nil {
t.Errorf("Error when retrieving network key from store: %v", err)
}
if !nwKVObject.Exists() {
t.Errorf("Network key should have been created.")
}
epKVObject := &Endpoint{network: nw, id: ep.ID()}
err = testController.store.GetObject(epKVObject)
if err != nil {
t.Errorf("Error when retrieving Endpoint key from store: %v", err)
}
if !epKVObject.Exists() {
t.Errorf("Endpoint key should have been created.")
}
testController.Stop()
// test restore of local store
testController, err = New(context.Background(), cfgOptions...)
if err != nil {
t.Fatalf("Error creating controller: %v", err)
}
defer testController.Stop()
if _, err = testController.NetworkByID(nw.ID()); err != nil {
t.Errorf("Error getting network %v", err)
}
}