-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx_test.go
41 lines (37 loc) · 855 Bytes
/
tx_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
package dali
import "testing"
var transactionTests = []struct {
sql string
args []interface{}
wantSQL string
prepared bool
}{
{"SELECT name WHERE id = ?", Args{13}, "SELECT name WHERE id = 13", false},
{"SELECT ?ident WHERE [id] = ?", Args{"name"}, "SELECT {name} WHERE {id} = &1", true},
}
func TestTransactions(t *testing.T) {
tx, _ := db.Begin()
for _, tt := range transactionTests {
var q *Query
var gotErr error
if tt.prepared {
stmt, err := tx.Prepare(tt.sql, tt.args...)
if err != nil {
gotErr = err
} else {
q = stmt.Bind()
}
} else {
q = tx.Query(tt.sql, tt.args...)
if q.err != nil {
gotErr = q.err
}
}
if gotErr != nil {
t.Fatalf("%s:\nunexpected err: %v\n", tt.sql, gotErr)
}
if q.query != tt.wantSQL {
t.Errorf("\n got: %v\nwant: %v", q.query, tt.wantSQL)
}
}
}