aboutsummaryrefslogtreecommitdiffstats
path: root/internal/bolttest/mock_sql_db.go
blob: 0c125928164ee3ca1f641fb70add4f44259c93c4 (plain) (blame)
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
package bolttest

import "database/sql"

type MockSqlDb struct {
	ExecReturnValue     ExecReturnValue
	ExecCallCount       int
	QueryReturnValue    QueryReturnValue
	QueryCallCount      int
	QueryRowReturnValue QueryRowReturnValue
	QueryRowCallCount   int
	BeginReturnValue    BeginReturnValue
	BeginCallCount      int
}

type ExecReturnValue struct {
	Result sql.Result
	Err    error
}

type QueryReturnValue struct {
	Rows *sql.Rows
	Err  error
}

type QueryRowReturnValue struct {
	Row *sql.Row
}

type BeginReturnValue struct {
	Tx  *sql.Tx
	Err error
}

func (db *MockSqlDb) Exec(query string, args ...any) (sql.Result, error) {
	db.ExecCallCount += 1
	return db.ExecReturnValue.Result, db.ExecReturnValue.Err
}

func (db *MockSqlDb) Query(query string, args ...any) (*sql.Rows, error) {
	db.QueryCallCount += 1
	return db.QueryReturnValue.Rows, db.QueryReturnValue.Err
}

func (db *MockSqlDb) QueryRow(query string, args ...any) *sql.Row {
	db.QueryRowCallCount += 1
	return db.QueryRowReturnValue.Row
}

func (db *MockSqlDb) Begin() (*sql.Tx, error) {
	db.BeginCallCount += 1
	return db.BeginReturnValue.Tx, db.BeginReturnValue.Err
}