File: cluster_test.go

package info (click to toggle)
golang-gopkg-dancannon-gorethink.v1 1.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (63 lines) | stat: -rw-r--r-- 1,480 bytes parent folder | download | duplicates (3)
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\")")
}