2
0

Tx.Status handles in transaction error

refs #421
This commit is contained in:
Jack Christensen
2018-05-12 10:23:39 -05:00
parent 26f6ae2c86
commit 6f1c5cc3e6
2 changed files with 51 additions and 2 deletions
+33
View File
@@ -354,6 +354,39 @@ func TestTxStatus(t *testing.T) {
}
}
func TestTxStatusErrorInTransactions(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn)
tx, err := conn.Begin()
if err != nil {
t.Fatal(err)
}
if status := tx.Status(); status != pgx.TxStatusInProgress {
t.Fatalf("Expected status to be %v, but it was %v", pgx.TxStatusInProgress, status)
}
_, err = tx.Exec("syntax error")
if err == nil {
t.Fatal("expected an error but did not get one")
}
if status := tx.Status(); status != pgx.TxStatusInFailure {
t.Fatalf("Expected status to be %v, but it was %v", pgx.TxStatusInFailure, status)
}
if err := tx.Rollback(); err != nil {
t.Fatal(err)
}
if status := tx.Status(); status != pgx.TxStatusRollbackSuccess {
t.Fatalf("Expected status to be %v, but it was %v", pgx.TxStatusRollbackSuccess, status)
}
}
func TestTxErr(t *testing.T) {
t.Parallel()