forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_test.go
63 lines (51 loc) · 1.44 KB
/
cluster_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
// +build cluster
package gorethink
import (
"fmt"
"time"
test "gopkg.in/check.v1"
)
func (s *RethinkSuite) TestClusterConnect(c *test.C) {
session, err := Connect(ConnectOpts{
Addresses: []string{url1, url2, url3},
})
c.Assert(err, test.IsNil)
row, err := Expr("Hello World").Run(session)
c.Assert(err, test.IsNil)
var response string
err = row.One(&response)
c.Assert(err, test.IsNil)
c.Assert(response, test.Equals, "Hello World")
}
func (s *RethinkSuite) TestClusterMultipleQueries(c *test.C) {
session, err := Connect(ConnectOpts{
Addresses: []string{url1, url2, url3},
})
c.Assert(err, test.IsNil)
for i := 0; i < 1000; i++ {
row, err := Expr(fmt.Sprintf("Hello World", i)).Run(session)
c.Assert(err, test.IsNil)
var response string
err = row.One(&response)
c.Assert(err, test.IsNil)
c.Assert(response, test.Equals, fmt.Sprintf("Hello World", i))
}
}
func (s *RethinkSuite) TestClusterConnectError(c *test.C) {
var err error
_, err = Connect(ConnectOpts{
Addresses: []string{"nonexistanturl"},
Timeout: time.Second,
})
c.Assert(err, test.NotNil)
}
func (s *RethinkSuite) TestClusterConnectDatabase(c *test.C) {
session, err := Connect(ConnectOpts{
Addresses: []string{url1, url2, url3},
Database: "test2",
})
c.Assert(err, test.IsNil)
_, err = Table("test2").Run(session)
c.Assert(err, test.NotNil)
c.Assert(err.Error(), test.Equals, "gorethink: Database `test2` does not exist. in:\nr.Table(\"test2\")")
}