forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rethinkdb_test.go
73 lines (60 loc) · 1.38 KB
/
rethinkdb_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
// +build integration
package rethinkdb
import (
"log"
"math/rand"
"net/url"
"os"
"testing"
"time"
"gopkg.in/gorethink/gorethink.v3"
)
var connect_url, authKey, username, password string
var server *Server
func init() {
connect_url = os.Getenv("RETHINKDB_URL")
if connect_url == "" {
connect_url = "127.0.0.1:28015"
}
authKey = os.Getenv("RETHINKDB_AUTHKEY")
username = os.Getenv("RETHINKDB_USERNAME")
password = os.Getenv("RETHINKDB_PASSWORD")
}
func testSetup(m *testing.M) {
var err error
server = &Server{Url: &url.URL{Host: connect_url}}
if authKey {
server.session, _ = gorethink.Connect(gorethink.ConnectOpts{
Address: server.Url.Host,
AuthKey: authKey,
HandshakeVersion: gorethink.HandshakeV0_4,
DiscoverHosts: false,
})
} else {
server.session, _ = gorethink.Connect(gorethink.ConnectOpts{
Address: server.Url.Host,
Username: username,
Password: password,
HandshakeVersion: gorethink.HandshakeV1_0,
DiscoverHosts: false,
})
}
if err != nil {
log.Fatalln(err.Error())
}
err = server.getServerStatus()
if err != nil {
log.Fatalln(err.Error())
}
}
func testTeardown(m *testing.M) {
server.session.Close()
}
func TestMain(m *testing.M) {
// seed randomness for use with tests
rand.Seed(time.Now().UTC().UnixNano())
testSetup(m)
res := m.Run()
testTeardown(m)
os.Exit(res)
}