forked from docker/libkv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibkv_test.go
81 lines (68 loc) · 1.57 KB
/
libkv_test.go
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
package libkv
import (
"testing"
"time"
"github.com/gonkulator/libkv/store"
"github.com/gonkulator/libkv/store/consul"
"github.com/gonkulator/libkv/store/etcd"
"github.com/gonkulator/libkv/store/zookeeper"
"github.com/stretchr/testify/assert"
)
func TestNewStoreConsul(t *testing.T) {
client := "localhost:8500"
kv, err := NewStore(
store.CONSUL,
[]string{client},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
assert.NoError(t, err)
assert.NotNil(t, kv)
if _, ok := kv.(*consul.Consul); !ok {
t.Fatal("Error while initializing store consul")
}
}
func TestNewStoreEtcd(t *testing.T) {
client := "localhost:4001"
kv, err := NewStore(
store.ETCD,
[]string{client},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
assert.NoError(t, err)
assert.NotNil(t, kv)
if _, ok := kv.(*etcd.Etcd); !ok {
t.Fatal("Error while initializing store etcd")
}
}
func TestNewStoreZookeeper(t *testing.T) {
client := "localhost:2181"
kv, err := NewStore(
store.ZK,
[]string{client},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
assert.NoError(t, err)
assert.NotNil(t, kv)
if _, ok := kv.(*zookeeper.Zookeeper); !ok {
t.Fatal("Error while initializing store zookeeper")
}
}
func TestNewStoreUnsupported(t *testing.T) {
client := "localhost:9999"
kv, err := NewStore(
"unsupported",
[]string{client},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
assert.Error(t, err)
assert.Nil(t, kv)
assert.Equal(t, "Backend storage not supported yet, please choose one of consul, etcd, zk", err.Error())
}