You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect both test cases to work, but they do not. I assume somewhere there is a copy of the record in the primary key index that isn't getting rolled back?
package transactions
import (
"context""database/sql""fmt""log""testing""github.com/jmoiron/sqlx"
_ "github.com/proullon/ramsql/driver"
)
funcTestTx(t*testing.T) {
tests:=map[string]struct {
driverNamestringdataSourceNamestringwithPrimaryKeybool
}{
"ramsql with pk": {driverName: "ramsql", dataSourceName: "testdbwithpk", withPrimaryKey: true},
"ramsql without pk": {driverName: "ramsql", dataSourceName: "testdbwithoutpk", withPrimaryKey: false},
}
forname, test:=rangetests {
t.Run(name, func(t*testing.T) {
ctx:=context.Background()
db, err:=sqlx.Open(test.driverName, test.dataSourceName)
iferr!=nil {
log.Fatal(err)
}
deferdb.Close()
pkStr:=""iftest.withPrimaryKey {
pkStr="PRIMARY KEY"
}
db.MustExec(fmt.Sprintf("CREATE TABLE foos (id BIGINT %s, value TEXT)", pkStr))
typeFoostruct {
IDint64`db:"id"`Valuestring`db:"value"`
}
varfooFooiferr=db.Get(&foo, "SELECT id, value FROM foos WHERE id = $1", 1); err!=sql.ErrNoRows {
t.Fatal("expected no rows")
}
tx, err:=db.BeginTxx(ctx, &sql.TxOptions{})
iferr!=nil {
t.Fatal("unexpected tx error")
}
_, err=tx.NamedExecContext(ctx, "INSERT INTO foos (id, value) VALUES (:id, :value)", Foo{ID: 1, Value: "test"})
iferr!=nil {
t.Fatal("unexpected insert error")
}
iferr=tx.Rollback(); err!=nil {
t.Fatal("unexpected rollback error")
}
iferr=db.Get(&foo, "SELECT id, value FROM foos WHERE id = $1", 1); err!=sql.ErrNoRows {
t.Fail()
}
})
}
}
The text was updated successfully, but these errors were encountered:
I would expect both test cases to work, but they do not. I assume somewhere there is a copy of the record in the primary key index that isn't getting rolled back?
The text was updated successfully, but these errors were encountered: