-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
adapter_test.go
86 lines (69 loc) · 2.07 KB
/
adapter_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
package grimoire
import (
"github.com/stretchr/testify/mock"
)
type TestAdapter struct {
mock.Mock
result interface{}
}
var _ Adapter = (*TestAdapter)(nil)
func (adapter TestAdapter) Open(dsn string) error {
args := adapter.Called(dsn)
return args.Error(0)
}
func (adapter TestAdapter) Close() error {
args := adapter.Called()
return args.Error(0)
}
func (adapter TestAdapter) Aggregate(query Query, out interface{}, logger ...Logger) error {
args := adapter.Called(query, out)
return args.Error(0)
}
func (adapter TestAdapter) All(query Query, doc interface{}, logger ...Logger) (int, error) {
args := adapter.Called(query, doc)
if adapter.result != nil {
switch doc.(type) {
case *[]Address:
*doc.(*[]Address) = adapter.result.([]Address)
case *[]Transaction:
*doc.(*[]Transaction) = adapter.result.([]Transaction)
case *[]User:
*doc.(*[]User) = adapter.result.([]User)
default:
panic("not implemented")
}
}
return args.Int(0), args.Error(1)
}
func (adapter TestAdapter) Insert(query Query, ch map[string]interface{}, logger ...Logger) (interface{}, error) {
args := adapter.Called(query, ch)
return args.Get(0), args.Error(1)
}
func (adapter TestAdapter) InsertAll(query Query, fields []string, chs []map[string]interface{}, logger ...Logger) ([]interface{}, error) {
args := adapter.Called(query, chs)
return args.Get(0).([]interface{}), args.Error(1)
}
func (adapter TestAdapter) Update(query Query, ch map[string]interface{}, logger ...Logger) error {
args := adapter.Called(query, ch)
return args.Error(0)
}
func (adapter TestAdapter) Delete(query Query, logger ...Logger) error {
args := adapter.Called(query)
return args.Error(0)
}
func (adapter TestAdapter) Begin() (Adapter, error) {
args := adapter.Called()
return adapter, args.Error(0)
}
func (adapter TestAdapter) Commit() error {
args := adapter.Called()
return args.Error(0)
}
func (adapter TestAdapter) Rollback() error {
args := adapter.Called()
return args.Error(0)
}
func (adapter *TestAdapter) Result(result interface{}) *TestAdapter {
adapter.result = result
return adapter
}