forked from shawnfeng/dbrouter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress_test.go
87 lines (52 loc) · 1.68 KB
/
express_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2014 The dbrouter Author. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package dbrouter
import (
"log"
"testing"
)
func TestExpress(t *testing.T) {
clustertest(t)
}
func check_ins(t *testing.T, dbs *dbCluster, cluster, table, ins_res string) {
ins := dbs.getInstance(cluster, table)
log.Println("ins", cluster, table, ins, ins_res)
if ins != ins_res {
t.Errorf("err c:%s t:%s ins:%s res:%s", cluster, table, ins, ins_res)
}
}
func clustertest(t *testing.T) {
dbs := &dbCluster {
clusters: make(map[string]*clsEntry),
}
cluster := "account"
err := dbs.addInstance(cluster, &dbLookupCfg{"user", "regex", "user[0-5]"})
if err != nil {
t.Errorf("err add:%s", err)
}
err = dbs.addInstance(cluster, &dbLookupCfg{"auth", "regex", "auth[0-9]+"})
if err != nil {
t.Errorf("err add:%s", err)
}
err = dbs.addInstance(cluster, &dbLookupCfg{"aaafull", "full", "aaa"})
if err != nil {
t.Errorf("err add:%s", err)
}
err = dbs.addInstance(cluster, &dbLookupCfg{"aaareg", "regex", "aaa[0-9]*"})
if err != nil {
t.Errorf("err add:%s", err)
}
check_ins(t, dbs, cluster, "auser0", "")
check_ins(t, dbs, cluster, "user0", "user")
check_ins(t, dbs, cluster, "user1", "user")
check_ins(t, dbs, cluster, "user2", "user")
check_ins(t, dbs, cluster, "user_not", "")
check_ins(t, dbs, cluster, "auth", "")
check_ins(t, dbs, cluster, "auth0", "auth")
check_ins(t, dbs, cluster, "auth1", "auth")
check_ins(t, dbs, cluster, "auth99", "auth")
check_ins(t, dbs, cluster, "auth01", "auth")
check_ins(t, dbs, cluster, "aaa", "aaafull")
check_ins(t, dbs, cluster, "aaa0", "aaareg")
}