File: topology_test.go

package info (click to toggle)
golang-github-gocql-gocql 0.0~git20171009.0.2416cf3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 872 kB
  • sloc: sh: 68; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 999 bytes parent folder | download
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
// +build all unit

package gocql

import (
	"testing"
)

// fakeNode is used as a simple structure to test the RoundRobin API
type fakeNode struct {
	conn   *Conn
	closed bool
}

// Pick is needed to satisfy the Node interface
func (n *fakeNode) Pick(qry *Query) *Conn {
	if n.conn == nil {
		n.conn = &Conn{}
	}
	return n.conn
}

//Close is needed to satisfy the Node interface
func (n *fakeNode) Close() {
	n.closed = true
}

//TestRoundRobinAPI tests the exported methods of the RoundRobin struct
//to make sure the API behaves accordingly.
func TestRoundRobinAPI(t *testing.T) {
	node := &fakeNode{}
	rr := NewRoundRobin()
	rr.AddNode(node)

	if rr.Size() != 1 {
		t.Fatalf("expected size to be 1, got %v", rr.Size())
	}

	if c := rr.Pick(nil); c != node.conn {
		t.Fatalf("expected conn %v, got %v", node.conn, c)
	}

	rr.Close()
	if rr.pool != nil {
		t.Fatalf("expected rr.pool to be nil, got %v", rr.pool)
	}

	if !node.closed {
		t.Fatal("expected node.closed to be true, got false")
	}
}