-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathinternal_mocks.go
107 lines (87 loc) · 2.26 KB
/
internal_mocks.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package ksql
import (
"context"
)
// mockTxBeginner mocks the ksql.TxBeginner interface
type mockTxBeginner struct {
DBAdapter
BeginTxFn func(ctx context.Context) (Tx, error)
}
func (b mockTxBeginner) BeginTx(ctx context.Context) (Tx, error) {
return b.BeginTxFn(ctx)
}
// mockDBAdapter mocks the ksql.DBAdapter interface
type mockDBAdapter struct {
ExecContextFn func(ctx context.Context, query string, args ...interface{}) (Result, error)
QueryContextFn func(ctx context.Context, query string, args ...interface{}) (Rows, error)
}
func (m mockDBAdapter) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) {
return m.ExecContextFn(ctx, query, args...)
}
func (m mockDBAdapter) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error) {
return m.QueryContextFn(ctx, query, args...)
}
type mockRows struct {
ScanFn func(...interface{}) error
CloseFn func() error
NextFn func() bool
ErrFn func() error
ColumnsFn func() ([]string, error)
}
func (m mockRows) Scan(values ...interface{}) error {
return m.ScanFn(values...)
}
func (m mockRows) Close() error {
if m.CloseFn == nil {
return nil
}
return m.CloseFn()
}
func (m mockRows) Next() bool {
return m.NextFn()
}
func (m mockRows) Err() error {
if m.ErrFn == nil {
return nil
}
return m.ErrFn()
}
func (m mockRows) Columns() ([]string, error) {
return m.ColumnsFn()
}
// mockResult mocks the ksql.Result interface
type mockResult struct {
LastInsertIdFn func() (int64, error)
RowsAffectedFn func() (int64, error)
}
func (m mockResult) LastInsertId() (int64, error) {
if m.LastInsertIdFn != nil {
return m.LastInsertIdFn()
}
return 0, nil
}
func (m mockResult) RowsAffected() (int64, error) {
if m.RowsAffectedFn != nil {
return m.RowsAffectedFn()
}
return 0, nil
}
// mockTx mocks the ksql.Tx interface
type mockTx struct {
DBAdapter
RollbackFn func(ctx context.Context) error
CommitFn func(ctx context.Context) error
}
func (m mockTx) Rollback(ctx context.Context) error {
return m.RollbackFn(ctx)
}
func (m mockTx) Commit(ctx context.Context) error {
return m.CommitFn(ctx)
}
// mockCloser mocks the io.Closer interface
type mockCloser struct {
CloseFn func() error
}
func (m mockCloser) Close() error {
return m.CloseFn()
}