forked from go-zookeeper/zk
-
Notifications
You must be signed in to change notification settings - Fork 6
/
refreshdnshostprovider_test.go
58 lines (44 loc) · 1.15 KB
/
refreshdnshostprovider_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
package zk
import (
"testing"
)
func TestRefreshDNSHostProviderReconnection(t *testing.T) {
hp := refreshDNSHostProvider(t)
hp.Connected()
hp.DNSHostProvider.lookupHost = func(host string) ([]string, error) {
return []string{"10.0.0.1"}, nil
}
ip, _ := hp.Next()
if ip != "10.0.0.1:2181" {
t.Fatalf("expected ip to be 10.0.0.1, got %v", ip)
}
}
func TestRefreshDNSHostProviderRetryStart(t *testing.T) {
hp := refreshDNSHostProvider(t)
hp.DNSHostProvider.lookupHost = func(host string) ([]string, error) {
return []string{"10.0.0.1"}, nil
}
for {
if _, retryStart := hp.Next(); retryStart {
break
}
}
ip, _ := hp.Next()
if ip != "10.0.0.1:2181" {
t.Fatalf("expected ip to be 10.0.0.1, got %v", ip)
}
}
func refreshDNSHostProvider(t *testing.T) *RefreshDNSHostProvider {
t.Helper()
hp := &RefreshDNSHostProvider{}
hp.DNSHostProvider.lookupHost = func(host string) ([]string, error) {
return []string{"192.0.2.1", "192.0.2.2", "192.0.2.3"}, nil
}
if err := hp.Init([]string{"foo.local:2181"}); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if hp.Len() != 3 {
t.Fatalf("unexpected length: %d", hp.Len())
}
return hp
}