gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/tests/cluster_test.go (about) 1 // +build cluster 2 3 package tests 4 5 import ( 6 "fmt" 7 "time" 8 9 test "gopkg.in/check.v1" 10 r "gopkg.in/rethinkdb/rethinkdb-go.v6" 11 ) 12 13 func (s *RethinkSuite) TestClusterConnect(c *test.C) { 14 session, err := r.Connect(r.ConnectOpts{ 15 Addresses: []string{url1, url2, url3}, 16 }) 17 c.Assert(err, test.IsNil) 18 19 row, err := r.Expr("Hello World").Run(session) 20 c.Assert(err, test.IsNil) 21 22 var response string 23 err = row.One(&response) 24 c.Assert(err, test.IsNil) 25 c.Assert(response, test.Equals, "Hello World") 26 } 27 28 func (s *RethinkSuite) TestClusterMultipleQueries(c *test.C) { 29 session, err := r.Connect(r.ConnectOpts{ 30 Addresses: []string{url1, url2, url3}, 31 }) 32 c.Assert(err, test.IsNil) 33 34 for i := 0; i < 1000; i++ { 35 row, err := r.Expr(fmt.Sprintf("Hello World %v", i)).Run(session) 36 c.Assert(err, test.IsNil) 37 38 var response string 39 err = row.One(&response) 40 c.Assert(err, test.IsNil) 41 c.Assert(response, test.Equals, fmt.Sprintf("Hello World %v", i)) 42 } 43 } 44 45 func (s *RethinkSuite) TestClusterConnectError(c *test.C) { 46 var err error 47 _, err = r.Connect(r.ConnectOpts{ 48 Addresses: []string{"nonexistanturl"}, 49 Timeout: time.Second, 50 }) 51 c.Assert(err, test.NotNil) 52 } 53 54 func (s *RethinkSuite) TestClusterConnectDatabase(c *test.C) { 55 session, err := r.Connect(r.ConnectOpts{ 56 Addresses: []string{url1, url2, url3}, 57 Database: "test2", 58 }) 59 c.Assert(err, test.IsNil) 60 61 _, err = r.Table("test2").Run(session) 62 c.Assert(err, test.NotNil) 63 c.Assert(err.Error(), test.Equals, "rethinkdb: Database `test2` does not exist. in:\nr.Table(\"test2\")") 64 }