package etcdv3 import ( "testing" "time" "github.com/docker/libkv" "github.com/docker/libkv/store" "github.com/docker/libkv/testutils" "github.com/stretchr/testify/assert" ) var ( client = "localhost:2379" ) func makeEtcdClient(t *testing.T) store.Store { kv, err := New( []string{client}, &store.Config{ ConnectionTimeout: 3 * time.Second, Username: "test", Password: "very-secure", }, ) if err != nil { t.Fatalf("cannot create store: %v", err) } return kv } func TestRegister(t *testing.T) { Register() kv, err := libkv.NewStore(ETCDV3, []string{client}, nil) assert.NoError(t, err) assert.NotNil(t, kv) if _, ok := kv.(*EtcdV3); !ok { t.Fatal("Error registering and initializing etcd") } } func TestEtcdStore(t *testing.T) { kv := makeEtcdClient(t) lockKV := makeEtcdClient(t) ttlKV := makeEtcdClient(t) defer testutils.RunCleanup(t, kv) testutils.RunTestCommon(t, kv) testutils.RunTestAtomic(t, kv) testutils.RunTestWatch(t, kv) testutils.RunTestLock(t, kv) testutils.RunTestLockTTL(t, kv, lockKV) testutils.RunTestLockWait(t, kv, lockKV) testutils.RunTestTTL(t, kv, ttlKV) }