Open smoynes opened 1 year ago
It would be really handy if sqlmock.ExpectBegin() allowed the user to verify the options passed to BeginTx().
sqlmock.ExpectBegin()
BeginTx()
txOptions *TxOptions
ExpectedBegin
ExpectedBegin.txOptions
(*ExpectedBegin).WithTxOptions(sql.TxOptions)
Verifying transaction isolation level:
db, mock, err := sqlmock.New() defer mock.ExpectationsWereMet() txOpts := sql.TxOptions{Isolation: sql.LevelReadUncommitted} mock.ExpectBegin().WithTxOptions(txOpts) tx, err := db.BeginTx(context.TODO(), &txOpts)
Verifying read-only transactions:
db, mock, err := sqlmock.New() defer mock.ExpectationsWereMet() txOpts := sql.TxOptions{ReadOnly: true} mock.ExpectBegin().WithTxOptions(txOpts) tx, err := db.BeginTx(context.TODO(), &txOpts)
It would be really handy if
sqlmock.ExpectBegin()
allowed the user to verify the options passed toBeginTx()
.Proposal
txOptions *TxOptions
field toExpectedBegin
: https://github.com/DATA-DOG/go-sqlmock/blob/3476f31d8fc4d652040f8d534380f5b54a8d3a42/expectations.go#L54ExpectedBegin.txOptions
in new method(*ExpectedBegin).WithTxOptions(sql.TxOptions)
BeginTx()
: https://github.com/DATA-DOG/go-sqlmock/blob/3476f31d8fc4d652040f8d534380f5b54a8d3a42/sqlmock_go18.go#L68Use-cases
Verifying transaction isolation level:
Verifying read-only transactions: