-
Notifications
You must be signed in to change notification settings - Fork 19
/
examples_test.go
50 lines (35 loc) · 931 Bytes
/
examples_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
package gockle
import (
"fmt"
"github.com/maraino/go-mock"
)
var mySession = &SessionMock{}
func Example_dump() {
var rows, _ = mySession.QuerySliceMap("select * from users")
for _, row := range rows {
fmt.Println(row)
}
}
func Example_insert() {
mySession.QueryExec("insert into users (id, name) values (123, 'me')")
}
func Example_print() {
var i = mySession.QueryIterator("select * from users")
for done := false; !done; {
var m = map[string]interface{}{}
done = i.ScanMap(m)
fmt.Println(m)
}
}
func init() {
var i = &IteratorMock{}
i.When("ScanMap", mock.Any).Call(func(m map[string]interface{}) bool {
m["id"] = 123
m["name"] = "me"
return false
})
i.When("Close").Return(nil)
mySession.When("QueryExec", mock.Any).Return(nil)
mySession.When("QueryIterator", mock.Any).Return(i)
mySession.When("QueryScanMap", mock.Any).Return(map[string]interface{}{"id": 1, "name": "me"}, nil)
}