2016-05-20 16:23:53 -04:00
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
2021-05-27 20:15:56 -04:00
|
|
|
"github.com/docker/libkv/store"
|
2016-05-20 16:23:53 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
|
|
|
cfgOptions, err := OptionBoltdbWithRandomDBFile()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating random boltdb file : %v", err)
|
|
|
|
}
|
|
|
|
ctrl, err := New(cfgOptions...)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error new controller: %v", err)
|
|
|
|
}
|
|
|
|
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()
|
2021-05-27 20:15:56 -04:00
|
|
|
if exists, _ := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); exists {
|
2016-05-20 16:23:53 -04:00
|
|
|
t.Fatalf("Network with persist=false should not be stored in KV Store")
|
|
|
|
}
|
2021-05-27 20:15:56 -04:00
|
|
|
if exists, _ := store.Exists(datastore.Key([]string{datastore.EndpointKeyPrefix, nw.ID(), ep.ID()}...)); exists {
|
2016-05-20 16:23:53 -04:00
|
|
|
t.Fatalf("Endpoint in Network with persist=false should not be stored in KV Store")
|
|
|
|
}
|
|
|
|
store.Close()
|
|
|
|
}
|