mirror of
https://github.com/moby/moby.git
synced 2026-07-11 18:13:57 +00:00
Now that this function is only ever called from contexts where a *testing.T value is available, several improvements can be made to it. Refactor it to be a test helper function so that callers do not need to check and fail the test themselves. Leverage t.TempDir() so that the temporary file is cleaned up automatically. Change it to return a single config.Option to get better ergonomics at call sites. Signed-off-by: Cory Snider <csnider@mirantis.com>
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package libnetwork
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
|
"github.com/docker/libkv/store"
|
|
)
|
|
|
|
func TestBoltdbBackend(t *testing.T) {
|
|
defer os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address)
|
|
testLocalBackend(t, "", "", nil)
|
|
defer os.Remove("/tmp/boltdb.db")
|
|
config := &store.Config{Bucket: "testBackend"}
|
|
testLocalBackend(t, "boltdb", "/tmp/boltdb.db", config)
|
|
}
|
|
|
|
func TestNoPersist(t *testing.T) {
|
|
ctrl, err := New(OptionBoltdbWithRandomDBFile(t))
|
|
if err != nil {
|
|
t.Fatalf("Error new controller: %v", err)
|
|
}
|
|
defer ctrl.Stop()
|
|
nw, err := ctrl.NewNetwork("host", "host", "", NetworkOptionPersist(false))
|
|
if err != nil {
|
|
t.Fatalf("Error creating default \"host\" network: %v", err)
|
|
}
|
|
ep, err := nw.CreateEndpoint("newendpoint", []EndpointOption{}...)
|
|
if err != nil {
|
|
t.Fatalf("Error creating endpoint: %v", err)
|
|
}
|
|
store := ctrl.(*controller).getStore(datastore.LocalScope).KVStore()
|
|
if exists, _ := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); exists {
|
|
t.Fatalf("Network with persist=false should not be stored in KV Store")
|
|
}
|
|
if exists, _ := store.Exists(datastore.Key([]string{datastore.EndpointKeyPrefix, nw.ID(), ep.ID()}...)); exists {
|
|
t.Fatalf("Endpoint in Network with persist=false should not be stored in KV Store")
|
|
}
|
|
store.Close()
|
|
}
|