File: tx.go

package info (click to toggle)
golang-github-erikstmartin-go-testdb 0.0~git20160219.0.8d10e4a-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 116 kB
  • ctags: 113
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 619 bytes parent folder | download
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
package testdb

type Tx struct {
	commitFunc   func() error
	rollbackFunc func() error
}

func (t *Tx) Commit() error {
	if t.commitFunc != nil {
		return t.commitFunc()
	}
	return nil
}

func (t *Tx) Rollback() error {
	if t.rollbackFunc != nil {
		return t.rollbackFunc()
	}
	return nil
}

func (t *Tx) SetCommitFunc(f func() error) {
	t.commitFunc = f
}

func (t *Tx) StubCommitError(err error) {
	t.SetCommitFunc(func() error {
		return err
	})
}

func (t *Tx) SetRollbackFunc(f func() error) {
	t.rollbackFunc = f
}

func (t *Tx) StubRollbackError(err error) {
	t.SetRollbackFunc(func() error {
		return err
	})
}