forked from StephanU/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.go
58 lines (46 loc) · 1.07 KB
/
testing.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 elasticsearch
import (
"os"
"time"
"github.com/elastic/beats/libbeat/outputs/outil"
)
const ElasticsearchDefaultHost = "localhost"
const ElasticsearchDefaultPort = "9200"
func GetEsPort() string {
port := os.Getenv("ES_PORT")
if len(port) == 0 {
port = ElasticsearchDefaultPort
}
return port
}
// Returns
func GetEsHost() string {
host := os.Getenv("ES_HOST")
if len(host) == 0 {
host = ElasticsearchDefaultHost
}
return host
}
func GetTestingElasticsearch() *Client {
var address = "http://" + GetEsHost() + ":" + GetEsPort()
username := os.Getenv("ES_USER")
pass := os.Getenv("ES_PASS")
client := newTestClientAuth(address, username, pass)
// Load version number
client.Connect(3 * time.Second)
return client
}
func newTestClientAuth(url, user, pass string) *Client {
client, err := NewClient(ClientSettings{
URL: url,
Index: outil.MakeSelector(),
Username: user,
Password: pass,
Timeout: 60 * time.Second,
CompressionLevel: 3,
}, nil)
if err != nil {
panic(err)
}
return client
}