-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
options_test.go
52 lines (42 loc) · 1.16 KB
/
options_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
package dbresolver_test
import (
"database/sql"
"testing"
"github.com/bxcodec/dbresolver/v2"
)
func TestOptionWithPrimaryDBs(t *testing.T) {
dbPrimary := &sql.DB{}
optFunc := dbresolver.WithPrimaryDBs(dbPrimary)
opt := &dbresolver.Option{}
optFunc(opt)
if len(opt.PrimaryDBs) != 1 {
t.Errorf("want %v, got %v", 1, len(opt.PrimaryDBs))
}
}
func TestOptionWithReplicaDBs(t *testing.T) {
dbReplica := &sql.DB{}
optFunc := dbresolver.WithReplicaDBs(dbReplica)
opt := &dbresolver.Option{}
optFunc(opt)
if len(opt.ReplicaDBs) != 1 {
t.Errorf("want %v, got %v", 1, len(opt.PrimaryDBs))
}
}
func TestOptionWithLoadBalancer(t *testing.T) {
optFunc := dbresolver.WithLoadBalancer(dbresolver.RoundRobinLB)
opt := &dbresolver.Option{}
optFunc(opt)
if opt.DBLB.Name() != dbresolver.RoundRobinLB {
t.Errorf("want %v, got %v", dbresolver.RoundRobinLB, opt.DBLB.Name())
}
}
func TestOptionWithLoadBalancerNonExist(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("Should throw panic, but it does not")
}
}()
optFunc := dbresolver.WithLoadBalancer(dbresolver.LoadBalancerPolicy("NON_EXIST"))
opt := &dbresolver.Option{}
optFunc(opt)
}