github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/libnetwork/store_linux_test.go (about) 1 package libnetwork 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/docker/docker/libnetwork/datastore" 8 "github.com/docker/libkv/store" 9 ) 10 11 func TestBoltdbBackend(t *testing.T) { 12 defer os.Remove(datastore.DefaultScopes("")[datastore.LocalScope].Client.Address) 13 testLocalBackend(t, "", "", nil) 14 defer os.Remove("/tmp/boltdb.db") 15 config := &store.Config{Bucket: "testBackend"} 16 testLocalBackend(t, "boltdb", "/tmp/boltdb.db", config) 17 } 18 19 func TestNoPersist(t *testing.T) { 20 cfgOptions, err := OptionBoltdbWithRandomDBFile() 21 if err != nil { 22 t.Fatalf("Error creating random boltdb file : %v", err) 23 } 24 ctrl, err := New(cfgOptions...) 25 if err != nil { 26 t.Fatalf("Error new controller: %v", err) 27 } 28 nw, err := ctrl.NewNetwork("host", "host", "", NetworkOptionPersist(false)) 29 if err != nil { 30 t.Fatalf("Error creating default \"host\" network: %v", err) 31 } 32 ep, err := nw.CreateEndpoint("newendpoint", []EndpointOption{}...) 33 if err != nil { 34 t.Fatalf("Error creating endpoint: %v", err) 35 } 36 store := ctrl.(*controller).getStore(datastore.LocalScope).KVStore() 37 if exists, _ := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); exists { 38 t.Fatalf("Network with persist=false should not be stored in KV Store") 39 } 40 if exists, _ := store.Exists(datastore.Key([]string{datastore.EndpointKeyPrefix, nw.ID(), ep.ID()}...)); exists { 41 t.Fatalf("Endpoint in Network with persist=false should not be stored in KV Store") 42 } 43 store.Close() 44 }