libnetwork: replace consul with boltdb in test

Based on randomLocalStore() in libnetwork/ipam/allocator_test.go

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-06-28 12:20:31 +02:00
parent a7d0f3060a
commit 25594c33b9
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 22 additions and 6 deletions

View File

@ -8,23 +8,24 @@ import (
"fmt"
"net"
"os"
"path/filepath"
"syscall"
"testing"
"time"
"golang.org/x/sys/unix"
"github.com/docker/docker/libnetwork/datastore"
"github.com/docker/docker/libnetwork/discoverapi"
"github.com/docker/docker/libnetwork/driverapi"
"github.com/docker/docker/libnetwork/netlabel"
"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/libkv/store/consul"
"github.com/docker/libkv/store"
"github.com/docker/libkv/store/boltdb"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
func init() {
consul.Register()
boltdb.Register()
}
type driverTester struct {
@ -37,10 +38,25 @@ const testNetworkType = "overlay"
func setupDriver(t *testing.T) *driverTester {
dt := &driverTester{t: t}
config := make(map[string]interface{})
tmp, err := os.CreateTemp(t.TempDir(), "libnetwork-")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
}
err = tmp.Close()
if err != nil {
t.Fatalf("Error closing temp file: %v", err)
}
defaultPrefix := filepath.Join(os.TempDir(), "libnetwork", "test", "overlay")
config[netlabel.GlobalKVClient] = discoverapi.DatastoreConfigData{
Scope: datastore.GlobalScope,
Provider: "consul",
Address: "127.0.0.01:8500",
Provider: "boltdb",
Address: filepath.Join(defaultPrefix, filepath.Base(tmp.Name())),
Config: &store.Config{
Bucket: "libnetwork",
ConnectionTimeout: 3 * time.Second,
},
}
if err := Init(dt, config); err != nil {