store_linux_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.DefaultScope("").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. ctrl, err := New(OptionBoltdbWithRandomDBFile(t))
  17. if err != nil {
  18. t.Fatalf("Error new controller: %v", err)
  19. }
  20. defer ctrl.Stop()
  21. nw, err := ctrl.NewNetwork("host", "host", "", NetworkOptionPersist(false))
  22. if err != nil {
  23. t.Fatalf("Error creating default \"host\" network: %v", err)
  24. }
  25. ep, err := nw.CreateEndpoint("newendpoint", []EndpointOption{}...)
  26. if err != nil {
  27. t.Fatalf("Error creating endpoint: %v", err)
  28. }
  29. store := ctrl.getStore().KVStore()
  30. if exists, _ := store.Exists(datastore.Key(datastore.NetworkKeyPrefix, nw.ID())); exists {
  31. t.Fatalf("Network with persist=false should not be stored in KV Store")
  32. }
  33. if exists, _ := store.Exists(datastore.Key([]string{datastore.EndpointKeyPrefix, nw.ID(), ep.ID()}...)); exists {
  34. t.Fatalf("Endpoint in Network with persist=false should not be stored in KV Store")
  35. }
  36. store.Close()
  37. }