/usr/share/gocode/src/github.com/docker/libkv/store/consul/consul_test.go is in golang-github-docker-libkv-dev 0.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | package consul
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:8500"
)
func makeConsulClient(t *testing.T) store.Store {
kv, err := New(
[]string{client},
&store.Config{
ConnectionTimeout: 3 * time.Second,
},
)
if err != nil {
t.Fatalf("cannot create store: %v", err)
}
return kv
}
func TestRegister(t *testing.T) {
Register()
kv, err := libkv.NewStore(store.CONSUL, []string{client}, nil)
assert.NoError(t, err)
assert.NotNil(t, kv)
if _, ok := kv.(*Consul); !ok {
t.Fatal("Error registering and initializing consul")
}
}
func TestConsulStore(t *testing.T) {
kv := makeConsulClient(t)
lockKV := makeConsulClient(t)
ttlKV := makeConsulClient(t)
testutils.RunTestCommon(t, kv)
testutils.RunTestAtomic(t, kv)
testutils.RunTestWatch(t, kv)
testutils.RunTestLock(t, kv)
testutils.RunTestLockTTL(t, kv, lockKV)
testutils.RunTestTTL(t, kv, ttlKV)
testutils.RunCleanup(t, kv)
}
func TestGetActiveSession(t *testing.T) {
kv := makeConsulClient(t)
consul := kv.(*Consul)
key := "foo"
value := []byte("bar")
// Put the first key with the Ephemeral flag
err := kv.Put(key, value, &store.WriteOptions{TTL: 2 * time.Second})
assert.NoError(t, err)
// Session should not be empty
session, err := consul.getActiveSession(key)
assert.NoError(t, err)
assert.NotEqual(t, session, "")
// Delete the key
err = kv.Delete(key)
assert.NoError(t, err)
// Check the session again, it should return nothing
session, err = consul.getActiveSession(key)
assert.NoError(t, err)
assert.Equal(t, session, "")
}
|