etcdv3_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package etcdv3
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/docker/libkv"
  6. "github.com/docker/libkv/store"
  7. "github.com/docker/libkv/testutils"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. var (
  11. client = "localhost:2379"
  12. )
  13. func makeEtcdClient(t *testing.T) store.Store {
  14. kv, err := New(
  15. []string{client},
  16. &store.Config{
  17. ConnectionTimeout: 3 * time.Second,
  18. Username: "test",
  19. Password: "very-secure",
  20. },
  21. )
  22. if err != nil {
  23. t.Fatalf("cannot create store: %v", err)
  24. }
  25. return kv
  26. }
  27. func TestRegister(t *testing.T) {
  28. Register()
  29. kv, err := libkv.NewStore(ETCDV3, []string{client}, nil)
  30. assert.NoError(t, err)
  31. assert.NotNil(t, kv)
  32. if _, ok := kv.(*EtcdV3); !ok {
  33. t.Fatal("Error registering and initializing etcd")
  34. }
  35. }
  36. func TestEtcdStore(t *testing.T) {
  37. kv := makeEtcdClient(t)
  38. lockKV := makeEtcdClient(t)
  39. ttlKV := makeEtcdClient(t)
  40. defer testutils.RunCleanup(t, kv)
  41. testutils.RunTestCommon(t, kv)
  42. testutils.RunTestAtomic(t, kv)
  43. testutils.RunTestWatch(t, kv)
  44. testutils.RunTestLock(t, kv)
  45. testutils.RunTestLockTTL(t, kv, lockKV)
  46. testutils.RunTestLockWait(t, kv, lockKV)
  47. testutils.RunTestTTL(t, kv, ttlKV)
  48. }