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
|
// +build cluster
package tests
import (
"fmt"
"time"
test "gopkg.in/check.v1"
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
)
func (s *RethinkSuite) TestClusterConnect(c *test.C) {
session, err := r.Connect(r.ConnectOpts{
Addresses: []string{url1, url2, url3},
})
c.Assert(err, test.IsNil)
row, err := r.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 := r.Connect(r.ConnectOpts{
Addresses: []string{url1, url2, url3},
})
c.Assert(err, test.IsNil)
for i := 0; i < 1000; i++ {
row, err := r.Expr(fmt.Sprintf("Hello World %v", 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 %v", i))
}
}
func (s *RethinkSuite) TestClusterConnectError(c *test.C) {
var err error
_, err = r.Connect(r.ConnectOpts{
Addresses: []string{"nonexistanturl"},
Timeout: time.Second,
})
c.Assert(err, test.NotNil)
}
func (s *RethinkSuite) TestClusterConnectDatabase(c *test.C) {
session, err := r.Connect(r.ConnectOpts{
Addresses: []string{url1, url2, url3},
Database: "test2",
})
c.Assert(err, test.IsNil)
_, err = r.Table("test2").Run(session)
c.Assert(err, test.NotNil)
c.Assert(err.Error(), test.Equals, "rethinkdb: Database `test2` does not exist. in:\nr.Table(\"test2\")")
}
|