Finishes testing all error cases in the .Transaction() method

pull/26/head
Vinícius Garcia 2022-08-03 21:05:20 -03:00
parent 25e77f3f36
commit 45d8ef4491
1 changed files with 31 additions and 0 deletions

View File

@ -2350,6 +2350,37 @@ func TransactionTest(
tt.AssertErrContains(t, err, "fakePanicPayload", "fakeRollbackErrMsg")
})
t.Run("should handle rollback errors when fn returns an error", func(t *testing.T) {
err := createTables(driver, connStr)
if err != nil {
t.Fatal("could not create test table!, reason:", err.Error())
}
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
c := newTestDB(db, driver)
cMock := mockTxBeginner{
DBAdapter: c.db,
BeginTxFn: func(ctx context.Context) (Tx, error) {
return mockTx{
DBAdapter: c.db,
RollbackFn: func(ctx context.Context) error {
return fmt.Errorf("fakeRollbackErrMsg")
},
}, nil
},
}
c.db = cMock
err = c.Transaction(ctx, func(db Provider) error {
return fmt.Errorf("fakeTransactionErrMsg")
})
tt.AssertErrContains(t, err, "fakeTransactionErrMsg", "fakeRollbackErrMsg")
})
t.Run("should report error when BeginTx() fails", func(t *testing.T) {
db, closer := newDBAdapter(t)
defer closer.Close()