MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / TestTx_Begin

Function TestTx_Begin

tx_test.go:68–108  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestTx_Begin(t *testing.T) {
69 t.Run("Begin with default options, with only read", func(t *testing.T) {
70 withDefaultDB(t, func(t *testing.T, db *DB) {
71 tx, err := db.Begin(false)
72 assert.NoError(t, err)
73
74 err = tx.Rollback()
75 assert.NoError(t, err)
76
77 err = db.Close()
78 assert.NoError(t, err)
79 })
80 })
81
82 t.Run("Begin with default options, with writable", func(t *testing.T) {
83 withDefaultDB(t, func(t *testing.T, db *DB) {
84 tx, err := db.Begin(true)
85 assert.NoError(t, err)
86
87 _ = tx.Rollback()
88
89 err = db.Close()
90 assert.NoError(t, err)
91 })
92 })
93
94 t.Run("Begin with error: begin the closed db", func(t *testing.T) {
95 withDefaultDB(t, func(t *testing.T, db *DB) {
96 tx, err := db.Begin(true)
97 assert.NoError(t, err)
98
99 _ = tx.Rollback() // for unlock mutex
100
101 err = db.Close()
102 assert.NoError(t, err)
103
104 _, err = db.Begin(false)
105 assert.Error(t, err)
106 })
107 })
108}
109
110func TestTx_Close(t *testing.T) {
111 withDefaultDB(t, func(t *testing.T, db *DB) {

Callers

nothing calls this directly

Calls 6

withDefaultDBFunction · 0.85
RunMethod · 0.80
BeginMethod · 0.80
RollbackMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected