-
Notifications
You must be signed in to change notification settings - Fork 627
/
Copy pathestransport_integration_multinode_test.go
72 lines (57 loc) · 1.51 KB
/
estransport_integration_multinode_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
// Licensed to Elasticsearch B.V. under one or more agreements.
// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
// +build integration,multinode
package estransport_test
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"testing"
"github.com/elastic/go-elasticsearch/v6/estransport"
)
var (
_ = fmt.Print
)
func TestTransportSelector(t *testing.T) {
NodeName := func(t *testing.T, transport estransport.Interface) string {
req, err := http.NewRequest("GET", "/", nil)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
res, err := transport.Perform(req)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
fmt.Printf("> GET %s\n", req.URL)
r := struct {
Name string
}{}
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
t.Fatalf("Error parsing the response body: %s", err)
}
return r.Name
}
t.Run("RoundRobin", func(t *testing.T) {
var (
node string
)
transport, _ := estransport.New(estransport.Config{URLs: []*url.URL{
{Scheme: "http", Host: "localhost:9200"},
{Scheme: "http", Host: "localhost:9201"},
}})
node = NodeName(t, transport)
if node != "es1" {
t.Errorf("Unexpected node, want=e1, got=%s", node)
}
node = NodeName(t, transport)
if node != "es2" {
t.Errorf("Unexpected node, want=e1, got=%s", node)
}
node = NodeName(t, transport)
if node != "es1" {
t.Errorf("Unexpected node, want=e1, got=%s", node)
}
})
}