-
Notifications
You must be signed in to change notification settings - Fork 19
/
batch_test.go
75 lines (60 loc) · 1.59 KB
/
batch_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
package gockle
import (
"fmt"
"reflect"
"testing"
)
func TestBatch(t *testing.T) {
var execs = newSession(t)
var exec = func(q string) {
if err := execs.Exec(q); err != nil {
t.Fatalf("Actual error %v, expected no error", err)
}
}
exec(ksDropIf)
exec(ksCreate)
exec(tabCreate)
exec(rowInsert)
defer execs.Close()
defer exec(ksDrop)
defer exec(tabDrop)
// Exec
var s = newSession(t)
var b = s.Batch(BatchKind(0))
if b == nil {
t.Error("Actual batch nil, expected not nil")
}
b.Add("update gockle_test.test set n = 3 where id = 1 if n = 2")
if err := b.Exec(); err != nil {
t.Errorf("Actual error %v, expected no error", err)
}
// ExecTx
b = s.Batch(BatchKind(0))
b.Add("update gockle_test.test set n = 4 where id = 1 if n = 3")
if a, err := b.ExecTx(); err == nil {
if e := ([]map[string]interface{}{{"[applied]": true}}); !reflect.DeepEqual(a, e) {
t.Errorf("Actual tx %v, expected %v", a, e)
}
} else {
t.Errorf("Actual error %v, expected no error", err)
}
s.Close()
if _, err := b.ExecTx(); err == nil {
t.Error("Actual no error, expected error")
}
}
func TestBatchMock(t *testing.T) {
var m, e = &BatchMock{}, fmt.Errorf("e")
testMock(t, m, &m.Mock, []struct {
method string
arguments []interface{}
results []interface{}
}{
{"Add", []interface{}{"", []interface{}(nil)}, nil},
{"Add", []interface{}{"a", []interface{}{1}}, nil},
{"Exec", nil, []interface{}{nil}},
{"Exec", nil, []interface{}{e}},
{"ExecTx", nil, []interface{}{([]map[string]interface{})(nil), nil}},
{"ExecTx", nil, []interface{}{[]map[string]interface{}{}, e}},
})
}