-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind_test.go
87 lines (85 loc) · 1.77 KB
/
bind_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
package querybuilder
import "testing"
func Test_rebind(t *testing.T) {
type args struct {
bindType int
query string
}
tests := []struct {
name string
args args
want string
}{
{
name: "test1",
args: args{
bindType: DOLLAR,
query: "SELECT * FROM table1 WHERE id=?",
},
want: "SELECT * FROM table1 WHERE id=$1",
},
{
name: "test2",
args: args{
bindType: DOLLAR,
query: "SELECT * FROM table1 WHERE id=? and name=?",
},
want: "SELECT * FROM table1 WHERE id=$1 and name=$2",
},
{
name: "test3",
args: args{
bindType: QUESTION,
query: "SELECT * FROM table1 WHERE id=?",
},
want: "SELECT * FROM table1 WHERE id=?",
},
{
name: "test4",
args: args{
bindType: QUESTION,
query: "SELECT * FROM table1 WHERE id=? and name=?",
},
want: "SELECT * FROM table1 WHERE id=? and name=?",
},
{
name: "test5",
args: args{
bindType: NAMED,
query: "SELECT * FROM table1 WHERE id=?",
},
want: "SELECT * FROM table1 WHERE id=:arg1",
},
{
name: "test6",
args: args{
bindType: NAMED,
query: "SELECT * FROM table1 WHERE id=? and name=?",
},
want: "SELECT * FROM table1 WHERE id=:arg1 and name=:arg2",
},
{
name: "test7",
args: args{
bindType: AT,
query: "SELECT * FROM table1 WHERE id=?",
},
want: "SELECT * FROM table1 WHERE id=@p1",
},
{
name: "test8",
args: args{
bindType: AT,
query: "SELECT * FROM table1 WHERE id=? and name=?",
},
want: "SELECT * FROM table1 WHERE id=@p1 and name=@p2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := rebind(tt.args.bindType, tt.args.query); got != tt.want {
t.Errorf("rebind() = %v, want %v", got, tt.want)
}
})
}
}