File tree 2 files changed +9
-9
lines changed
2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ import (
12
12
type SqlAdapter interface {
13
13
txn.Adapter
14
14
15
- // IsTx returns true if the current transaction is active .
16
- IsTx () bool
15
+ // Returns current transaction if it exists .
16
+ Tx () * sql. Tx
17
17
}
18
18
19
19
// New creates a new SqlAdapter instance using the provided *sql.DB.
@@ -59,6 +59,6 @@ func (a *sqlAdapter) End(_ context.Context) {
59
59
}
60
60
}
61
61
62
- func (a * sqlAdapter ) IsTx () bool {
63
- return a .tx != nil
62
+ func (a * sqlAdapter ) Tx () * sql. Tx {
63
+ return a .tx
64
64
}
Original file line number Diff line number Diff line change @@ -141,23 +141,23 @@ func TestSqlAdapter_End(t *testing.T) {
141
141
})
142
142
}
143
143
144
- func TestSqlAdapter_IsTx (t * testing.T ) {
144
+ func TestSqlAdapter_Tx (t * testing.T ) {
145
145
db , mock , err := sqlmock .New ()
146
146
if err != nil {
147
147
t .Fatalf ("an error '%s' was not expected when opening a stub database connection" , err )
148
148
}
149
149
defer db .Close ()
150
150
151
- t .Run ("IsTx true " , func (t * testing.T ) {
151
+ t .Run ("Tx is not nil " , func (t * testing.T ) {
152
152
adapter := & sqlAdapter {db : db }
153
153
mock .ExpectBegin ()
154
154
155
155
adapter .Begin (context .Background ())
156
- assert .True (t , adapter .IsTx () )
156
+ assert .True (t , adapter .Tx () != nil )
157
157
})
158
158
159
- t .Run ("IsTx false " , func (t * testing.T ) {
159
+ t .Run ("Tx is nil " , func (t * testing.T ) {
160
160
adapter := & sqlAdapter {db : db }
161
- assert .False (t , adapter .IsTx () )
161
+ assert .True (t , adapter .Tx () == nil )
162
162
})
163
163
}
You can’t perform that action at this time.
0 commit comments