mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
libnetwork: unit tests: drop OptionBoltdbWithRandomDBFile
This option fn was defining a custom directory, file name and bucket name for boltdb. Users can only change data-dir through `OptionDataDir`. Better reuse that function instead, that'll make refactorings easier. It won't set a custom bucket name or file name as `OptionBoltdbWithRandomDBFile` was doing, but that's not needed since every test will use a different temp dir anyway. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
@@ -55,7 +55,7 @@ func TestUserChain(t *testing.T) {
|
||||
defer resetIptables(t)
|
||||
|
||||
c, err := New(
|
||||
OptionBoltdbWithRandomDBFile(t),
|
||||
config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDriverConfig("bridge", map[string]any{
|
||||
netlabel.GenericData: options.Generic{
|
||||
"EnableIPTables": tc.iptables,
|
||||
|
||||
@@ -320,7 +320,7 @@ func compareNwLists(a, b []*net.IPNet) bool {
|
||||
func TestAuxAddresses(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t))
|
||||
c, err := New(config.OptionDataDir(t.TempDir()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -403,7 +403,7 @@ func TestUpdateSvcRecord(t *testing.T) {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
ctrlr, err := New(OptionBoltdbWithRandomDBFile(t))
|
||||
ctrlr, err := New(config.OptionDataDir(t.TempDir()))
|
||||
assert.NilError(t, err)
|
||||
defer ctrlr.Stop()
|
||||
|
||||
@@ -449,7 +449,7 @@ func TestSRVServiceQuery(t *testing.T) {
|
||||
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t),
|
||||
c, err := New(config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDefaultAddressPoolConfig(ipamutils.GetLocalScopeDefaultNetworks()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -550,7 +550,7 @@ func TestServiceVIPReuse(t *testing.T) {
|
||||
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t),
|
||||
c, err := New(config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDefaultAddressPoolConfig(ipamutils.GetLocalScopeDefaultNetworks()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -671,7 +671,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
|
||||
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t))
|
||||
c, err := New(config.OptionDataDir(t.TempDir()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestMain(m *testing.M) {
|
||||
func newController(t *testing.T) *libnetwork.Controller {
|
||||
t.Helper()
|
||||
c, err := libnetwork.New(
|
||||
libnetwork.OptionBoltdbWithRandomDBFile(t),
|
||||
config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDriverConfig(bridgeNetType, map[string]interface{}{
|
||||
netlabel.GenericData: options.Generic{
|
||||
"EnableIPForwarding": true,
|
||||
@@ -1225,7 +1225,7 @@ func TestInvalidRemoteDriver(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctrlr, err := libnetwork.New(libnetwork.OptionBoltdbWithRandomDBFile(t))
|
||||
ctrlr, err := libnetwork.New(config.OptionDataDir(t.TempDir()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// test only works on linux
|
||||
func TestDNSIPQuery(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t),
|
||||
c, err := New(config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDefaultAddressPoolConfig(ipamutils.GetLocalScopeDefaultNetworks()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -114,7 +114,7 @@ func TestDNSProxyServFail(t *testing.T) {
|
||||
osctx := netnsutils.SetupTestOSContextEx(t)
|
||||
defer osctx.Cleanup(t)
|
||||
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t),
|
||||
c, err := New(config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDefaultAddressPoolConfig(ipamutils.GetLocalScopeDefaultNetworks()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -6,13 +6,14 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/libnetwork/config"
|
||||
"github.com/docker/docker/libnetwork/resolvconf"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
|
||||
func TestDNSOptions(t *testing.T) {
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t))
|
||||
c, err := New(config.OptionDataDir(t.TempDir()))
|
||||
assert.NilError(t, err)
|
||||
|
||||
sb, err := c.NewSandbox(context.Background(), "cnt1", nil)
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []*Network) {
|
||||
const netType = "bridge"
|
||||
c, err := New(
|
||||
OptionBoltdbWithRandomDBFile(t),
|
||||
config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDriverConfig(netType, map[string]any{
|
||||
netlabel.GenericData: options.Generic{"EnableIPForwarding": true},
|
||||
}),
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
func TestCleanupServiceDiscovery(t *testing.T) {
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
c, err := New(OptionBoltdbWithRandomDBFile(t),
|
||||
c, err := New(config.OptionDataDir(t.TempDir()),
|
||||
config.OptionDefaultAddressPoolConfig(ipamutils.GetLocalScopeDefaultNetworks()))
|
||||
assert.NilError(t, err)
|
||||
defer c.Stop()
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/libnetwork/config"
|
||||
store "github.com/docker/docker/libnetwork/internal/kvstore"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ func TestBoltdbBackend(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNoPersist(t *testing.T) {
|
||||
configOption := OptionBoltdbWithRandomDBFile(t)
|
||||
configOption := config.OptionDataDir(t.TempDir())
|
||||
testController, err := New(configOption)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating new controller: %v", err)
|
||||
|
||||
@@ -2,8 +2,6 @@ package libnetwork
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/libnetwork/config"
|
||||
@@ -66,18 +64,3 @@ func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Con
|
||||
t.Errorf("Error getting network %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// OptionBoltdbWithRandomDBFile function returns a random dir for local store backend
|
||||
func OptionBoltdbWithRandomDBFile(t *testing.T) config.Option {
|
||||
t.Helper()
|
||||
tmp := filepath.Join(t.TempDir(), "bolt.db")
|
||||
if err := os.WriteFile(tmp, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return func(c *config.Config) {
|
||||
c.Scope.Client.Provider = "boltdb"
|
||||
c.Scope.Client.Address = tmp
|
||||
c.Scope.Client.Config = &store.Config{Bucket: "testBackend"}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user