diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-02 09:29:41 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-02 09:29:41 -0500 |
| commit | 6760ae82d62449f41c68950264c02c40be81bfb3 (patch) | |
| tree | f071906933642e93e789b5def170985f366171ce /internal/bolttest/mock_sql_db.go | |
| parent | Add proper tests to revert service methods (diff) | |
| download | cli-6760ae82d62449f41c68950264c02c40be81bfb3.zip | |
Improve coverage for separate Tx methods
Diffstat (limited to 'internal/bolttest/mock_sql_db.go')
| -rw-r--r-- | internal/bolttest/mock_sql_db.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/bolttest/mock_sql_db.go b/internal/bolttest/mock_sql_db.go new file mode 100644 index 0000000..0c12592 --- /dev/null +++ b/internal/bolttest/mock_sql_db.go @@ -0,0 +1,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 +} |