-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocks_test.go
75 lines (64 loc) · 1.27 KB
/
mocks_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 dbal
import (
"database/sql"
"errors"
)
// mockDb mocks out sqlx.m for the purpose of testing.
type mockDb struct {
PingOk bool
ExecOk bool
PrepareOk bool
QueryOk bool
QueryRowOk bool
}
// Prepare ...
func (m *mockDb) Prepare(query string) (*sql.Stmt, error) {
if m.PrepareOk {
return &sql.Stmt{}, nil
}
return nil, errors.New("mock error")
}
// Exec ...
func (m *mockDb) Exec(query string, args ...interface{}) (sql.Result, error) {
if m.ExecOk {
return &Result{}, nil
}
return nil, errors.New("mock error")
}
// Query ...
func (m *mockDb) Query(query string, args ...interface{}) (*sql.Rows, error) {
if m.QueryOk {
return nil, nil
}
return nil, errors.New("mock error")
}
// QueryRow ...
func (m *mockDb) QueryRow(query string, args ...interface{}) *sql.Row {
if m.QueryRowOk {
return &sql.Row{}
}
return nil
}
// Ping ...
func (m *mockDb) Ping() error {
if m.PingOk {
return nil
}
return errors.New("mock Ping error")
}
// Close ...
func (m *mockDb) Close() error {
return nil
}
// Result is a mock of sql.Result
type Result struct {
LastInsertIDOk bool
}
// LastInsertId ...
func (r *Result) LastInsertId() (int64, error) {
return 1, nil
}
// RowsAffected ...
func (r *Result) RowsAffected() (int64, error) {
return 1, nil
}