-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclientv3_test.go
86 lines (75 loc) · 1.9 KB
/
clientv3_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
82
83
84
85
86
package etcd
import (
"context"
"testing"
"time"
)
func TestNewClient_withDefaultsV3(t *testing.T) {
client, err := NewClientV3(
context.Background(),
[]string{"http://irrelevant:12345"},
ClientOptions{},
)
if err == nil {
t.Fatalf("unexpected error creating client: %v", err)
}
if client != nil {
t.Fatal("expected new Client, got nil")
}
}
// NewClient should fail when providing invalid or missing endpoints.
func TestOptionsV3(t *testing.T) {
a, err := NewClientV3(
context.Background(),
[]string{},
ClientOptions{
Cert: "",
Key: "",
CACert: "",
DialTimeout: 2 * time.Second,
DialKeepAlive: 2 * time.Second,
HeaderTimeoutPerRequest: 2 * time.Second,
},
)
if err == nil {
t.Errorf("expected error: %v", err)
}
if a != nil {
t.Fatalf("expected client to be nil on failure")
}
_, err = NewClientV3(
context.Background(),
[]string{"http://irrelevant:12345"},
ClientOptions{
Cert: "blank.crt",
Key: "blank.key",
CACert: "blank.CACert",
DialTimeout: 2 * time.Second,
DialKeepAlive: 2 * time.Second,
HeaderTimeoutPerRequest: 2 * time.Second,
},
)
if err == nil {
t.Errorf("expected error: %v", err)
}
}
// ---------------------------------------------------------------------------------------------------------------------
func newFakeClientV3(ctx context.Context) Client {
return &clientv3{
client: nil,
ctx: ctx,
timeout: 3 * time.Second,
}
}
func TestWatchPrefixV3(t *testing.T) {
cv3 := newFakeClientV3(context.Background())
ch := make(chan struct{})
cv3.WatchPrefix("prefix", ch)
}
func TestGetEntriesV3(t *testing.T) {
cv3 := newFakeClientV3(context.Background())
res, err := cv3.GetEntries("prefix")
if res != nil || err == nil {
t.Errorf("expected client error")
}
}