forked from olivere/elastic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_test.go
More file actions
75 lines (70 loc) · 2.11 KB
/
client_test.go
File metadata and controls
75 lines (70 loc) · 2.11 KB
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
package elastic
import (
"net/http"
"testing"
)
func TestSingleUrl(t *testing.T) {
client, err := NewClient(http.DefaultClient)
if err != nil {
t.Fatal(err)
}
if len(client.urls) != 1 {
t.Fatalf("expected 1 default client url, got: %v", client.urls)
}
if client.urls[0] != defaultUrl {
t.Errorf("expected default client url of %s, got: %s", defaultUrl, client.urls[0])
}
}
func TestMultipleUrls(t *testing.T) {
client, err := NewClient(http.DefaultClient, "http://localhost:9200", "http://localhost:9201")
if err != nil {
t.Fatal(err)
}
if len(client.urls) != 2 {
t.Fatalf("expected 2 default client urls, got: %v", client.urls)
}
if client.urls[0] != "http://localhost:9200" {
t.Errorf("expected 1st client url of %s, got: %s", "http://localhost:9200", client.urls[0])
}
if client.urls[1] != "http://localhost:9201" {
t.Errorf("expected 2nd client url of %s, got: %s", "http://localhost:9201", client.urls[0])
}
}
func TestFindingActiveClient(t *testing.T) {
client, err := NewClient(http.DefaultClient, "http://localhost:19200", "http://localhost:9200")
if err != nil {
t.Fatal(err)
}
if len(client.urls) != 2 {
t.Fatalf("expected 2 default client urls, got: %v", client.urls)
}
if !client.hasActive {
t.Errorf("expected to have active connection, got: %v", client.hasActive)
}
expected := "http://localhost:9200"
if client.activeUrl != expected {
t.Errorf("expected active url to be %s, got: %v", expected, client.activeUrl)
}
}
func TestFindingNoActiveClient(t *testing.T) {
client, err := NewClient(http.DefaultClient, "http://localhost:19200", "http://localhost:19201")
if err != nil {
t.Fatal(err)
}
if len(client.urls) != 2 {
t.Fatalf("expected 2 default client urls, got: %v", client.urls)
}
if client.hasActive {
t.Errorf("expected to not have an active connection, got: %v", client.hasActive)
}
if client.activeUrl != "" {
t.Errorf("expected no active url, got: %v", client.activeUrl)
}
req, err := client.NewRequest("HEAD", "/")
if err != ErrNoClient {
t.Errorf("expected ErrNoClient, got: %v", err)
}
if req != nil {
t.Errorf("expected no request, got: %v", req)
}
}