store_linux_test.go 1.4 KB

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